2

https://github.com/ethereum/go-ethereum/wiki/Management-APIs

{"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.

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

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..)

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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