Sign messages

This guide will teach you how to sign messages using your Smart Wallet. Message signing is a key feature that allows users to authenticate and prove ownership of their wallet without spending gas.

Smart Wallets will generate signatures that can be validated using ERC-1271. If the wallet is an undeployed smart contract account (also known as a counterfactual address), then the signature will be wrapped according to ERC-6492.

Prerequisites

  • API key from your dashboard
  • A Smart Wallet with an associated signer

What is message signing?

Message signing allows users to:

  • Authenticate without spending gas
  • Prove ownership of their wallet
  • Sign arbitrary data for offchain verification
  • Interact with dApps that require signature-based authentication

Smart Wallets support EIP-191 message signing, which is the standard for Ethereum message signing. You may also see EIP-191 referred to as the personal_sign message format.

Text messages

Required SDK version: ^v4.59.1

Use the useSignMessage hook to sign text messages with your Smart Wallet.

signTextMessage.tsx
1import { useSignMessage, useSmartAccountClient } from "@account-kit/react";
2
3export default function SignTextMessage() {
4 const { client } = useSmartAccountClient({});
5 const { signMessageAsync } = useSignMessage({
6 client,
7 });
8
9 const handleSignTextMessage = async () => {
10 const signature = await signMessageAsync({
11 message: "Hello, world!",
12 });
13
14 console.log("Signature:", signature);
15 };
16
17 return (
18 <div>
19 <button onClick={handleSignTextMessage}>Sign Text Message</button>
20 </div>
21 );
22}

Raw hex messages

Required SDK version: ^v4.59.1

Use the useSignMessage hook to sign raw hex messages with your Smart Wallet.

signRawMessage.tsx
1import { useSignMessage, useSmartAccountClient } from "@account-kit/react";
2
3export default function SignRawMessage() {
4 const { client } = useSmartAccountClient({});
5 const { signMessageAsync } = useSignMessage({
6 client,
7 });
8
9 const handleSignRawMessage = async () => {
10 const signature = await signMessageAsync({
11 message: {
12 raw: "0x48656c6c6f2c20776f726c6421", // "Hello, world!" in hex
13 },
14 });
15
16 console.log("Raw signature:", signature);
17 };
18
19 return (
20 <div>
21 <button onClick={handleSignRawMessage}>Sign Raw Message</button>
22 </div>
23 );
24}

Next steps

Build more:

Troubleshooting: