Restless - Ethereum
Ethereum module for restless. Uses ethers.js. Provides utilities such as:
asEthAddress
asBigNumber
Installation
npm install @restless/ethereum
yarn add @restless/ethereum
Sanitizers
asEthAddress
Accepts any string that represents a valid ethereum address. Checks the checksum if present. Returns a normalized representation.
asEthAddress('0xA5fE...f213', 'path')
asEthAddress('0xa5fe...f213', 'path')
asEthAddress('bla bla bla', 'path')
asEthAddress(123, 'path')
asBigNumber
Accepts any string or number that represents an integer. Converts the integer to a BigNumber.
asBigNumber('123', 'path')
asBigNumber(456, 'path')
asBigNumber(1.5, 'path')
asBigNumber(true, 'path')
asHexBytes
Accepts any string that encodes binary data of specific length in hex format. The returned string is always lowercased.
const sanitizer = asHexBytes(3)
sanitizer('0x12ab56', 'path')
sanitizer('0x12AB56', 'path')
sanitizer('0x12AB5', 'path')
sanitizer(1234, 'path')
asTransactionHash
Accepts any string that can be a transaction hash.
const exampleHash = '0xd04b98f48e8f8bcc15c6ae5ac050801cd6dcfd428fb5f9e65c4e16e7807340fa'
asTransactionHash(exampleHash, 'path')
asTransactionHash(exampleHash.toUpperCase(), 'path')
sanitizer('0x12AB5', 'path')
sanitizer(1234, 'path')