-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow web3.sha3() to hash more than one thing, and numbers instead of strings. #226
Comments
Aha, I need this too to make life easier 😃 |
This is actually implemented in ethereumjs-abi: var abi = require('ethereumjs-abi')
var BN = require('bn.js')
abi.soliditySHA3(
[ "address", "address", "uint", "uint" ],
[ new BN("43989fb883ba8111221e89123897538475893837", 16), 0, 10000, 1448075779 ]
).toString('hex') |
That would be lovely if it fully worked. Unfortunately, does not work for type bytes32. See examples below:
coded() returns
Reported on ethereumjs-abi: |
I guess this is what you've wanted: http://web3js.readthedocs.io/en/1.0/web3-utils.html#soliditysha3 |
Solidity's sha3() can hash a group of numbers, while web3.sha3() can only hash a single string.
Consider a contract (an auction, say, or in my case a simple game) with secret numerical bids. Suppose the contract stores preimages of the bid hashed with a nonce and maybe a salt. When the bidding is over, the bidders can submit the bid and the nonce to confirm the bid, and solidity can hash them all to confirm the bid is accurate, then work with the bid. This part works fine.
But how does the client generate the preimages to send? web3.sha3() can only hash one string. The string "100" is not the same as the integer one hundred. If I send the string "100" however, the contract would have to waste gas parsing the string. It'd be far easier if web3.sha3 could just hash numbers on its own.
The text was updated successfully, but these errors were encountered: