Use the signTypedData method exported from the useSignTypedData hook to sign a message with an Ethereum embedded wallet.

signTypedData(input: SignTypedDataParams, options?: SignTypedDataOptions): Promise<{signature: string}>

Usage

import {useSignTypedData} from '@privy-io/react-auth';

const {signTypedData} = useSignTypedData();
const {signature} = await signTypedData({...});

Parameters

input
Object
required

The typed data object to sign with the wallet, with the properties defined in EIP-712.

options
Object
uiOptions
SignMessageModalUIOptions

UI options to customize the signature prompt modal. Learn more

address
string

Address for the embedded wallet signing the message. Only set this parameter if using imported embedded wallets or multiple HD embedded wallets for the same user. Defaults to the user’s embedded wallet at HD index 0.

Response

signature
string

The signature produced by the wallet.

Callbacks

Configure callbacks for signTypedData with the useSignTypedData hook.

import {useSignTypedData} from '@privy-io/react-auth';

const {signTypedData} = useSignTypedData({
  onSuccess: ({signature}) => {
    console.log(signature);
    // Any logic you'd like to execute after a user successfully signs the EIP-712 typed data
  },
  onError: (error) => {
    console.log(error);
    // Any logic you'd like to execute after a user exits the signing flow or there is an error
  }
});

// Then call `signTypedData` in your code, which will invoke these callbacks on completion

As parameters to useSignTypedData, you may include an onSuccess callback and/or an onError callback.

While this component is mounted, any invocation of signTypedData will trigger the onSuccess callback or onError callback on completion, depending on if the data was successfully signed or not.

onSuccess

If set, the onSuccess callback will execute after a user has successfully signed the message. Within this callback, you can access a signature parameter, which is the signature string value generated by the wallet to sign the data.

onError

If set, the onError callback will execute after a user attempts to sign the typed data and there is an error, or if the user exits the signature flow prematurely. Within this callback, you may access an error code with more information about the error.