Skip to Content
dApp Integration

personal_sign

Signs a message with the specified account. The message is prefixed with "\x19Ethereum Signed Message:\n" before signing to prevent signing malicious transactions.


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' + Buffer.from(message, 'utf8').toString('hex') 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' + Buffer.from(message, 'utf8').toString('hex') 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 === accounts[0])

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 
Last updated on