String/Type Conversion and Application Helpers
Convert an Address to a String
Convert an Address to a string conforming to the EIP-55 checksum.
Note: This lowercases all the characters inside the Address and runs it through the checksum algorithm.
Check if given string is a valid address.
Note: Works on mixed case strings, with or without the 0x.
Check if given string is a valid checksum address.
Safely convert a string into Hex.
Convert a Hex into a string.
Check if given string is valid Hex
Convert Given Hex into ASCII. Will fail if Hex is an uneven length.
Convert Given Hex into UTF8. Will fail if Hex is an uneven length.
Append two Hex's together.
hexAppend (Hex 0x12) (Hex 0x34) == Hex 0x1234Concatenate a list of Hex's
hexConcat [ Hex 0x12, Hex 0x34, Hex 0x56 ] == Hex 0x 00123456Safely convert a string to a TxHash.
Convert a given TxHash to a string.
Check if given string is a valid TxHash.
i.e. Hex and 64 characters long.
Safely convert a given string to a BlockHash.
Convert a given BlockHash to a string.
Check if given string is a valid BlockHash.
i.e. Hex and 64 characters long.
Convert a contract function name to it's 4-byte function signature.
Utils.functionSig "transfer(address,uint256)" == Hex "a9059cbb"Hash a given string into it's SHA3/Keccak256 form.
Checks if a given string is valid hex and 64 chars long.
Same as ethereum_keccak_256 from this library.
User beware!! These are sidestepping the power of Elm, and it's static types.
Undoubtedly convenient for baking values, like contract addresses, into your source code.
All values coming from the outside world, like user input or server responses, should use the safe functions.
Config for a retry task
Retry a given Task till it succeeds, or runs out of time.
The below will wait for 5 minutes until giving up, and polls every 5 seconds.
pollForMinedTx : HttpProvider -> TxHash -> Task Http.Error TxReceipt
pollForMinedTx ethNode txHash =
Eth.getTxReceipt ethNode txHash
|> retry { attempts = 60, sleep = 5 }Useful for decoding past a result straight into a Msg. Comes in handy with Eth.Sentry.Event values.
transferDecoder : Value -> Msg
transferDecoder =
valueToMsg Transfer Error transferEventDecoder
type Msg
= Transfer (Event Transfer)
| Error Decode.ErrorPrepends a string wiht "0x" Useful for displaying hex values
Removes "0x" or "0X" from string. Useful for dealing with hex strings that might have "0x" prepended.
Makes sure a string of bytes is an even number, thus valid hexdecimal.
Returns 64 chars (32 bytes) from the left side of a string.
Drops 64 chars (32 bytes) from the left side of a string.
Pads a string with '0' till it's length is 64 chars.
Safely convert a string into an address.
All lowercase or uppercase strings, shaped like addresses, will result in
Ok. Mixed case strings will returnErrif the EIP-55 checksum is invalid.