intrepidshape/elm-web3/2.1.0

NOTE: the latest version is 3.0.0

Web3.Fee

Gas price and fee history queries.

fetchGasPrice : Platform.Cmd msg
fetchGasPrice =
    web3Cmd (Fee.encode (Fee.getGasPrice "gas-query"))
type Cmd
= RequestGasPrice String
| RequestFeeHistory String Int

Commands to query fee data via port.

type Msg
= GotGasPrice String BigInt
| GotFeeHistory String FeeHistory

Messages from the JS fee port.

type alias FeeHistory =
{ baseFeePerGas : List BigInt
, gasUsedRatio : List Float
, oldestBlock : Int
}

Historical fee data from eth_feeHistory.

getGasPrice : String -> Cmd

Request the current gas price (eth_gasPrice). The id is echoed back.

getFeeHistory : String -> Int -> Cmd

Request fee history for the last blockCount blocks.

encode : Cmd -> Value

Encode a Cmd for the JS port.

decoder : Decoder Msg

Decode Msg responses from the JS port.

getMaxPriorityFee : String -> Value

Request the current max priority fee per gas (eth_maxPriorityFeePerGas). The id is echoed back in the maxPriorityFee response.

web3Cmd (Fee.getMaxPriorityFee "priority-1")

This is a standalone encoder that produces the port value directly -- it is deliberately NOT a new variant of Cmd. Adding a variant to an exposed custom type is a MAJOR change under Elm's enforced semver (every case expression over Cmd or Msg in consumer code would stop compiling), so this addition ships as a pair of standalone functions to stay MINOR-safe. Decode the response with maxPriorityFeeDecoder.

maxPriorityFeeDecoder : Decoder ( String, BigInt )

Decode the maxPriorityFee response from the JS port into ( id, wei ).

Standalone (not a Msg variant) for the same additive-safety reason as getMaxPriorityFee: extending Msg would be a MAJOR version bump.

case D.decodeValue Fee.maxPriorityFeeDecoder incoming of
    Ok ( id, wei ) ->
        -- wei : BigInt -- suggested maxPriorityFeePerGas
    Err _ ->
        -- not a maxPriorityFee response