Produces an ERC-1271-compatible signature over a plain message.
Request
import { stringToHex } from 'viem'
const signature = await provider.request<`0x${string}`>({
method: 'personal_sign',
params: [stringToHex('I acknowledge the terms.'), address],
})
Parameters
Hex-encoded message bytes.
Smart-account address. Must match the connected account.
Returns
0x${string}, the signature, packed for ERC-1271 verification.
Errors
| Code | Cause |
|---|
4001 | User rejected the signature |
4100 | Wallet not connected |
Verification
import { publicClient } from './viem'
const isValid = await publicClient.verifyMessage({
address,
message: 'I acknowledge the terms.',
signature,
})
viem handles ERC-1271 (and ERC-6492 for undeployed accounts) automatically.