Skip to content
On this page

signMessage

Calculates an Ethereum-specific signature in the form of keccak256("\x19Ethereum Signed Message:\n" + len(message) + message)).

With the calculated signature, you can:

Usage

ts
import { getAccount } from 'viem'
import { walletClient } from './client'
 
const account = getAccount('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266')
 
const signature = await walletClient.signMessage({ 
  account,
  data: '0xdeadbeaf',
})
// "0xa3f20717a250c2b0b729b7e5becbff67fdaef7e0699da4de7ca5895b02a170a12d887fd3b17bfdce3481f10bea41f45ba9f709d39ce8325427b57afcfc994cee1b"
ts
import { createWalletClient, custom } from 'viem'

export const walletClient = createWalletClient({
  transport: custom(window.ethereum)
})

Returns

Hex

The signed message.

Parameters

account

Account to use for signing. Read more.

ts
const signature = await walletClient.signMessage({
  account: getAccount('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'), 
  data: '0xdeadbeaf',
})

data

  • Type: string

Message to sign.

ts
const signature = await walletClient.signMessage({
  account: getAccount('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'),
  data: 'hello world', 
})

JSON-RPC Methods

  • JSON-RPC Accounts:
  • Local Accounts
    • Signs locally. No JSON-RPC request.

Released under the MIT License.