sha3
of address-type argument calculated in solidity
function get_sha() constant returns (address, bytes32) {
return (msg.sender, sha3(msg.sender));
}
is different from that calculated in web3js using buffer constructed from hex representation of the argument:
returned from contract:
address:0xca35b7d915458ef540ade6068dfe2f44e8fa733c
bytes32:0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03
returned by web3js:
> web3.sha3(Buffer.from('ca35b7d915458ef540ade6068dfe2f44e8fa733c', 'hex').toString())
'0xd53a2663473d029b80bddef493a064cc91bad113e4a61353b243b769c6909222'
They match if I compare sha3s of string-type arguments like "a"
, but don't match in case of address-type argument. I also tried to pad string inside Buffer.from(...)
with 24 zeros on the left and on the right, so that it would represent 32 bytes, but the result is still incorrect.
How can I make web3's value match that of solidity's?