WDK logoWDK documentation

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

You can sign a message with the account's private key using account.sign():

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

Verify a Signature

You can verify a signature using a read-only account. Use account.toReadOnlyAccount() to create one, then call readOnlyAccount.verify():

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

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