{"method": "personal_sign", "params": [message, account, password]}

The param message is a hex string, how can I generate it from a tx?

What I want to ask is, if I have a tx, for example: {from:0x1234,to:0x4321,value:xxxx,gas:xxx,gasPrice:xxxx}

How can I generate the message?

I try to find a sample of it but got nothing. Hope someone can give an example. Very thanks.

  • 1
    Actually, try using eth_signTypedData
    – Doug Kent
    Jul 20, 2018 at 12:55

2 Answers 2


You can use personal_sign as following:

import Web3 from 'web3';
web3 = new Web3(web3.currentProvider);

web3.personal.sign(web3.toHex("message to sign"), "from_address", function(err, 
signature) {
      console.log('signature: ' + signature);

When the MetaMask app is installed in the user's browser and logged in, the MetaMask will pop up the sign window, which looks like:

enter image description here

The signature looks like 0x206xxxxxxxxxx18f47ec659e12531f47c22d8402378c697f1ae18b22bbe4610702c95c35f5098141fd3c54a9e9f4eb80b21b6d692bfb3f6e05008fc06af9c2201b (just x-ed a couple of characters..)

  • how to verify the signature?
    – i--
    Dec 11, 2022 at 7:18

Something like this might work for you:

var ethUtil = require('ethereumjs-util');
var ethereumjs = require('ethereumjs-abi);

const nonce = 0;
const message = ethereumjs.soliditySHA3(           
    ["address", "address", "uint", "uint", "uint", "uint"],
    [from, to, amount, gas, gasPrice, nonce]

{"method": "personal_sign", "params": [ethUtil.bufferToHex(new Buffer(message, 'utf8')), account, password]}

However, the prompt from MetaMask looks ugly since the message it displays is coming from binary data. I'm still wondering how to fix that.

  • Did you managed how to change the message?
    – Justice47
    Oct 7, 2021 at 8:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.