signMessage
Signs an EIP-191 personal sign message via ERC-7739 PersonalSign
format.
This Action is suitable to sign messages for contracts (e.g. ERC-4337 Smart Accounts) that implement (or conform to) ERC-7739 (e.g. Solady's ERC1271.sol).
With the calculated signature, you can use verifyMessage
to verify the signature
Usage
import { account, walletClient } from './config'
const signature_1 = await walletClient.signMessage({
// Account used for signing.
account,
message: 'hello world',
// Verifying contract address (e.g. ERC-4337 Smart Account).
verifier: '0xCB9fA1eA9b8A3bf422a8639f23Df77ea66020eC2'
})
const signature_2 = await walletClient.signMessage({
// Account used for signing.
account,
// Hex data representation of message.
message: { raw: '0x68656c6c6f20776f726c64' },
// Verifying contract address (e.g. ERC-4337 Smart Account)
verifier: '0xCB9fA1eA9b8A3bf422a8639f23Df77ea66020eC2'
})
Account and/or Verifier Hoisting
If you do not wish to pass an account
and/or verifier
to every signMessage
, you can also hoist the Account and/or Verifier on the Wallet Client (see config.ts
).
import { walletClient } from './config'
const signature = await walletClient.signMessage({
message: 'hello world',
})
Returns
The signed message.
Parameters
account
- Type:
Account | Address
Account to used to sign the message.
Accepts a JSON-RPC Account or Local Account (Private Key, etc).
import { walletClient } from './config'
const signature = await walletClient.signMessage({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
verifier: '0xCB9fA1eA9b8A3bf422a8639f23Df77ea66020eC2'
})
message
- Type:
string | { raw: Hex | ByteArray }
Message to sign.
By default, viem signs the UTF-8 representation of the message.
import { walletClient } from './config'
const signature = await walletClient.signMessage({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
verifier: '0xCB9fA1eA9b8A3bf422a8639f23Df77ea66020eC2',
})
To sign the data representation of the message, you can use the raw
attribute.
import { walletClient } from './config'
const signature = await walletClient.signMessage({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: { raw: '0x68656c6c6f20776f726c64' },
verifier: '0xCB9fA1eA9b8A3bf422a8639f23Df77ea66020eC2',
})
verifier
- Type:
Address
The address of the verifying contract (e.g. a ERC-4337 Smart Account). Required if verifierDomain
is not passed.
import { walletClient } from './config'
const signature = await walletClient.signMessage({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
verifier: '0xCB9fA1eA9b8A3bf422a8639f23Df77ea66020eC2',
})
verifierDomain
- Type:
TypedDataDomain
Account domain separator. Required if verifier
is not passed.
import { walletClient } from './config'
const signature = await walletClient.signMessage({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
verifierDomain: {
name: 'SoladyAccount',
version: '1',
chainId: 1,
verifyingContract: '0xCB9fA1eA9b8A3bf422a8639f23Df77ea66020eC2'
},
})