intrepidshape/elm-web3/1.4.0

NOTE: the latest version is 3.0.0

Web3.Types

Core opaque types for EVM interaction.

All types are opaque — you can't accidentally pass a TxHash where an Address is expected. Construction validates format and returns Maybe so invalid input is a compile-time-visible code path, not a runtime crash.

import Web3.Types as T


-- Validate on input boundary (e.g. from a URL param or user field):
case T.address rawString of
    Just addr ->
        -- addr : T.Address — safe to use everywhere
    Nothing ->
        -- show validation error


-- BlockNumber is used by Contract.Call, Block, Fee, and Query:
T.encodeBlockNumber T.Latest    == Json.Encode.string "latest"
T.encodeBlockNumber (T.BlockNum 1000) == Json.Encode.int 1000

Wei is an alias for Web3.BigInt.BigInt — use Web3.Units.formatEther to convert to a human-readable string.

type Address

A validated Ethereum address (0x + 40 hex chars).

type TxHash

A transaction hash (0x + 64 hex chars).

= BlockNum Int
| Latest
| Pending
| Earliest

A block number — specific or a tag.

type ChainId

An EVM chain ID.

type alias Wei =

Wei amount as a string (uint256 — too large for Int).

A raw hex string.

address : String -> Maybe Address

Create an Address from a hex string. Returns Nothing if invalid.

Extract the string value of an Address.

txHash : String -> Maybe TxHash

Create a TxHash from a hex string.

Extract the string value of a TxHash.

chainId : Int -> ChainId

Create a ChainId.

Extract the integer value of a ChainId.

hexString : String -> Maybe HexString

Create a HexString.

Extract the string value of a HexString.

Encode a BlockNumber for JSON-RPC (e.g. for eth_call block parameter).