Skip to content

useSignMessage

Custom hook to sign a message using the provided client. Provides a way to sign messages within the context of an account using Ethereum-specific signature in EIP-191 format. Uses personal_sign to sign arbitrary messages (usually strings). Accepts any plain message as input.

Until the method completes, isSigningMessage is true and signedMessage is null until eventually returning either a 1271 or 6492 signature (if the smart contract account has not been deployed yet), which is useful if you need to render the signature to the UI. signedMessageAsync is useful over signedMessage if you need to chain calls together.

Using 1271 validation, the mechanisms by which you can validate the smart contract account, we verify the message was signed by the smart contract itself rather than the EOA signer.

To reiterate, the signature that is returned must be verified against the account itself not the signer. The final structure of the signature is dictated by how the account does 1271 validation. You don’t want to be verifying in a different way than the way the account itself structures the signatures to be validated. For example LightAccount has three different ways to validate the account.

Import

import { useSignMessage } from "@account-kit/react";

Usage

import { useSignMessage, useSmartAccountClient } from "@account-kit/react";
 
const { client } = useSmartAccountClient({ type: "LightAccount" });
const {
  signMessage,
  signMessageAsync,
  signedMessage,
  isSigningMessage,
  error,
} = useSignMessage({
  client,
  // these are optional
  onSuccess: (result) => {
    // do something on success
  },
  onError: (error) => console.error(error),
});

Parameters

config

UseSignMessageArgs The configuration arguments for the hook, including the client and additional mutation arguments. ref

Returns

UseSignMessageResult An object containing methods and state for signing messages. ref