signMessage
Calculates an Ethereum-specific signature in EIP-191 format: keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))
.
With the calculated signature, you can:
- use
verifyMessage
to verify the signature, - use
recoverMessageAddress
to recover the signing address from a signature.
Usage
ts
import { getAccount } from 'viem'
import { walletClient } from './client'
const account = getAccount('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266')
const signature = await walletClient.signMessage({
account,
message: 'hello world',
})
// "0xa461f509887bd19e312c0c58467ce8ff8e300d3c1a90b608a760c5b80318eaf15fe57c96f9175d6cd4daad4663763baa7e78836e067d0163e9a2ccf2ff753f5b1b"
ts
import { createWalletClient, custom } from 'viem'
export const walletClient = createWalletClient({
transport: custom(window.ethereum)
})
Returns
The signed message.
Parameters
account
- Type:
Address
Account to use for signing. Read more.
ts
const signature = await walletClient.signMessage({
account: getAccount('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'),
message: 'hello world',
})
data
- Type:
string
Message to sign.
ts
const signature = await walletClient.signMessage({
account: getAccount('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'),
message: 'hello world',
})
JSON-RPC Methods
- JSON-RPC Accounts:
- Local Accounts
- Signs locally. No JSON-RPC request.