solidity-sha3
web3.sha3
doesn't always match the behavior of sha3
in Solidity. This one does.
- Hashes integers (default size:
uint256
) - Hashes tightly-packed arguments
- Supports hex strings and BigNumber instances
Install
$ npm install --save solidity-sha3
Usage
import sha3 from 'solidity-sha3'
sha3('a')
sha3('0x0a')
sha3(1)
sha3(-1)
sha3(new BigNumber('100'))
sha3('a', 1)
You can also hash a value at a specific size:
import { sha3withsize } from 'solidity-sha3'
sha3withsize(1, 32)
sha3withsize(1, 8)
Be aware that strings will be converted into hex by default. You can use sha3num
to explicitly pad and hash a string as a number. This is useful for Wei that is not a BigNumber instance:
import { sha3num } from 'solidity-sha3'
sha3num(web3.toWei(100))
sha3(web3.toWei(100))
License
ISC © Raine Revere