I want to verify if message-hash has a particular contract method.

Like below web3 code generates a rawTransaction having,messageHash,v, r, s, rawTransaction

let rawTransaction = {
        'from': fromAddress,
        'gasLimit': web3js.utils.toHex(310000),
        'to': contractAddress,
        'gasPrice': web3js.utils.toHex(20 * 1e9),
        'value': "0x0",
        'data': contract.methods.transfer(toAddress, amount).encodeABI(),
        'nonce': web3js.utils.toHex(count),
  web3js.eth.accounts.signTransaction(rawTransaction, PK);

i.e if message hash from the above signed transaction is 0x9de6f7321d6374c8e26a1cd043daa71719175af97ed0f098260bf117db48dcbf

How can I create same hash in contract by passing above data for verification that given transaction hash is for transfer with all given values?

I have tried keccak256(abi.encodePacked()) using above data but it is generating different hash, may be I am doing something wrong.

  • Do you want to verify the transaction hash or the transaction signature? Do you want to validate on-chain or off-chain?
    – Ismael
    May 26, 2020 at 20:33

1 Answer 1


Make sure of these 2 ponits:

  1. While singing transaction, make sure to add leading 0x in the private key.
  2. Add "\x19Ethereum Signed Message:\n32 before msg in the smart contract.
   bytes32 hash = keccak256(abi.encodePacked(
        "\x19Ethereum Signed Message:\n32",

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.