1

I have this solidity method:

function hashData(bytes32 data) public constant returns (bytes32) {
    var hash = keccak256(data, msg.sender);
    return hash;
  }

for a data = "0x707974686f6e62" and address = "0x4c5f885b9854ce17e5620098e53f3032be002fed"

I dont get the same result using web3.sha3(data,address)

3

In Solidity, sha3 and keccak256 are aliases, so their output will be identical.

web3.sha3 is a different function in a different programming language (I assume JavaScript). You would probably find web3.utils.soliditySha3 helpful because as it reproduces the packing that Solidity does.

ethereumjs-abi has a similar function in case you're not using web3.js 1.0.

3

Try to use web3 1.0 and web3.utils.soliditySha3 to execute the sha3/keccak256 in the same way that Solidity would.

Will calculate the sha3 of given input parameters in the same way solidity would. This means arguments will be ABI converted and tightly packed before being hashed.

more info

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.