Block number and block data queries.
-- One-shot block number query:
port web3Cmd : Json.Encode.Value -> Cmd msg
port web3Sub : (Json.Decode.Value -> msg) -> Sub msg
type Msg = GotBlock Block.Msg | ...
subscriptions model =
web3Sub (Json.Decode.decodeValue Block.decoder >> Result.toMaybe >> Maybe.map GotBlock)
fetchBlock : Platform.Cmd msg
fetchBlock =
web3Cmd (Block.encode (Block.getBlockNumber "my-id"))Messages from the JS block port.
A block header with key fields.
Request the current block number. The id is echoed back in the response.
Request a specific block by block number. The id is echoed back.
Start polling the block number every 4 seconds. The id tags each
GotBlockNumber response so you can distinguish multiple watchers.
Request the number of transactions in a block. The second argument is a request ID.
Stop a block-number watcher started with watchBlockNumber.
The id must match the one passed to watchBlockNumber. Clears the JS-side
polling interval and/or the WebSocket newHeads subscription.
web3Cmd (Block.unwatchBlockNumber "block-watch")This is a standalone encoder producing the port value directly — it is
deliberately NOT a new variant of Cmd, because adding a variant
to an exposed custom type is a MAJOR change under Elm's enforced semver
(consumer case expressions over Cmd would stop compiling). A
standalone function keeps this addition MINOR-safe.
Commands to query block data via port.