WDK logoWDK documentation
StartWalletsDeFi & FiatAI & CLITools

Sign and Verify Messages

Sign messages and EIP-712 typed data with smart accounts.

This guide explains how to sign messages, verify signatures, and sign EIP-712 typed data.

Sign a Message

Sign a message as the Safe using account.sign(). The owner signs an EIP-712 SafeMessage bound to the Safe address and chain ID:

Sign Message
const signature = await account.sign('Hello, ERC-4337!')
console.log('Signature:', signature)

Verify a Signature

Use account.toReadOnlyAccount() when you need a read-only view that can verify before and after the Safe is deployed:

Verify Signature
const readOnlyAccount = await account.toReadOnlyAccount()
const isValid = await readOnlyAccount.verify('Hello, ERC-4337!', signature)
console.log('Signature valid:', isValid)

For a deployed Safe, verification calls the Safe contract’s ERC-1271 isValidSignature(). For an undeployed Safe, it recovers the signer from the SafeMessage signature and compares it with the known owner. An undeployed account created with fromSafeAddress() has no owner and throws UnsupportedOperationError. Verification checks deployment through the RPC provider.

Sign Typed Data (EIP-712)

You can sign EIP-712 structured data using account.signTypedData():

Sign Typed Data
const typedData = {
  domain: {
    name: 'MyDApp',
    version: '1',
    chainId: 1,
    verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
  },
  types: {
    Mail: [
      { name: 'from', type: 'address' },
      { name: 'to', type: 'address' },
      { name: 'contents', type: 'string' }
    ]
  },
  message: {
    from: '0x1234567890abcdef1234567890abcdef12345678',
    to: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
    contents: 'Hello!'
  }
}

const typedDataSignature = await account.signTypedData(typedData)
console.log('Typed data signature:', typedDataSignature)

You can verify typed data signatures using readOnlyAccount.verifyTypedData():

Verify Typed Data
const readOnlyAccount = await account.toReadOnlyAccount()
const isValid = await readOnlyAccount.verifyTypedData(typedData, typedDataSignature)
console.log('Typed data signature valid:', isValid)

Next Steps

Learn how to handle errors and manage resources.

On this page