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.
Configure callbacks for Privy’s signMessage method on the useSignMessage hook:
import {useSignMessage} from '@privy-io/react-auth';const {signMessage} = useSignMessage({ onSuccess: ({signature}) => { console.log(signature); // Any logic you'd like to execute after a user successfully signs a message }, onError: (error) => { console.log(error); // Any logic you'd like to execute after a user exits the message signing flow or there is an error }});// Then call `signMessage` in your code, which will invoke these callbacks on completion
As parameters to useSignMessage, you may include an onSuccess callback and/or an onError callback.
While this component is mounted, any invocation of signMessage will trigger the onSuccess callback or onError callback on completion, depending on if the message was successfully signed or not.
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 message.
If set, the onError callback will execute after a user attempts to sign a message 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.
Use the signMessage method exported from the useSignMessage hook to sign a message with an Ethereum embedded wallet.
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.
Configure callbacks for Privy’s signMessage method on the useSignMessage hook:
import {useSignMessage} from '@privy-io/react-auth';const {signMessage} = useSignMessage({ onSuccess: ({signature}) => { console.log(signature); // Any logic you'd like to execute after a user successfully signs a message }, onError: (error) => { console.log(error); // Any logic you'd like to execute after a user exits the message signing flow or there is an error }});// Then call `signMessage` in your code, which will invoke these callbacks on completion
As parameters to useSignMessage, you may include an onSuccess callback and/or an onError callback.
While this component is mounted, any invocation of signMessage will trigger the onSuccess callback or onError callback on completion, depending on if the message was successfully signed or not.
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 message.
If set, the onError callback will execute after a user attempts to sign a message 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.
Request a message signature on the wallets Ethereum provider.
guard let user = privy.user else { // If user is null, user is not authenticated return}// Retrieve list of user's embedded Ethereum walletslet ethereumWallets = user.embeddedEthereumWallets// Grab the desired wallet. Here, we retrieve the first walletguard let wallet = ethereumWallets.first else { // No ETH wallets return}let data = EthereumRpcRequest(method: "personal_sign", params: ["A message to sign", wallet.address])let signature = try await wallet.provider.request(data)print("Result signature: \(signature)")
// Get Privy userval user = privy.user// check if user is authenticatedif (user != null) { // Retrieve list of user's embedded Ethereum wallets val ethereumWallets = user.embeddedEthereumWallets if (ethereumWallets.isNotEmpty()) { // Grab the desired wallet. Here, we retrieve the first wallet val ethereumWallet = ethereumWallets.first() // Make an rpc request ethereumWallet.provider.request( request = EthereumRpcRequest( method = "personal_sign", params = listOf("A message to sign", ethereumWallet.address), ), ) }}