Skip to Content
dApps
On this page

personal_sign

Signs a message with the specified account. The message is prefixed with "\x19Ethereum Signed Message:\n" before signing to separate message signatures from raw transaction signing.


Parameters

IndexTypeDescription
0stringMessage to sign (hex encoded)
1stringAddress to sign with

Returns

string - The signature (65-byte hex string)


Example

const message = 'Hello, OneKey!' const hexMessage = '0x' + Array.from(new TextEncoder().encode(message), byte => byte.toString(16).padStart(2, '0')).join('') const signature = await window.$onekey.ethereum.request({ method: 'personal_sign', params: [hexMessage, accounts[0]] }) console.log('Signature:', signature)

Using ethers.js

import { hashMessage, recoverAddress } from 'ethers' const message = 'Hello, OneKey!' const hexMessage = '0x' + Array.from(new TextEncoder().encode(message), byte => byte.toString(16).padStart(2, '0')).join('') const signature = await window.$onekey.ethereum.request({ method: 'personal_sign', params: [hexMessage, accounts[0]] }) // Verify signature const recoveredAddress = recoverAddress(hashMessage(message), signature) console.log('Verified:', recoveredAddress.toLowerCase() === accounts[0].toLowerCase())

Errors

CodeMessageDescription
4001User rejected the requestUser denied the signature request
-32602Invalid paramsInvalid message or address

Notes

  • Message must be hex encoded with 0x prefix
  • The actual signed message is: "\x19Ethereum Signed Message:\n" + len(message) + message
  • For signing typed data, use eth_signTypedData_v4 instead
  • Specified by EIP-191 

For authentication, verify the intended domain, account, expiration, and single-use server challenge. A valid signature over a fixed example message is not a complete sign-in flow.

Last updated on