Skip to content

signMessage (Smart Account)

Calculates an Ethereum-specific signature in EIP-191 format: keccak256("\x19Ethereum Signed Message:\n" + len(message) + message)).

Uses the Smart Account's Owner to sign the message.

Usage

example.ts
import { toCoinbaseSmartAccount } from 'viem/account-abstraction'
import { client, owner } from './config.js'
 
const account = await toSmartAccount({
  client,
  owners: [owner],
})
 
const signature = await account.signMessage({ 
  message: 'hello world', 
}) 

Returns

Hex

The signed message.

Parameters

message

  • Type: string | { raw: Hex | ByteArray }

Message to sign.

By default, viem signs the UTF-8 representation of the message.

const signature = await account.signMessage({
  message: 'hello world', 
})

To sign the data representation of the message, you can use the raw attribute.

const signature = await account.signMessage({
  message: { raw: '0x68656c6c6f20776f726c64' }, 
})