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.
Configure a working RPC provider for the account's chain before signing. Both sign() and signTypedData() resolve the SafeMessage chain ID through eth_chainId, even when you supply config.chainId. The successful lookup is cached. A mismatch with config.chainId throws ConfigurationError. Disposed accounts or signers can throw DisposalError. Custom signers must implement signTypedData(). See signing requirements for propagated provider and signer errors.
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:
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.
Undeployed Safe Signatures
WDK can verify a signature before deployment when it knows the Safe owner. Deploy the Safe before using the signature with a permit or login flow that calls ERC-1271 isValidSignature() on the Safe contract.
Sign Typed Data (EIP-712)
You can sign EIP-712 structured data using account.signTypedData(). The same provider, signer and undeployed Safe limitations apply.
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():
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.