intrepidshape/elm-web3-ui/2.2.0

NOTE: the latest version is 4.0.0

Web3.Ui.AbiInput

Render a typed input for any Solidity argument shape — address, uint*, int*, bool, string, bytes, bytesN, T[], T[N], and tuple (recursively).

The component is stateless, like every other primitive in this library. The caller owns a Value per ABI argument and passes it back in on every render. Validation feedback is wired the same way (error : Maybe String).

A complete write flow looks like this:

-- in your Model
type alias Model =
    { fooArg : Web3.Ui.AbiInput.Value
    , fooError : Maybe String
    , …
    }


-- in init
init =
    { fooArg = Web3.Ui.AbiInput.initFor fooField, … }


-- in your view
Web3.Ui.AbiInput.view []
    { field = fooField
    , value = model.fooArg
    , onChange = FooArgChanged
    , error = model.fooError
    }


-- when the user clicks Send, parse to JSON
case Web3.Ui.AbiInput.parse fooField model.fooArg of
    Ok jsonValue -> -- pass to Web3.Contract.Send
    Err msg      -> ( { model | fooError = Just msg }, Cmd.none )
view : List (Attribute msg) -> Config msg -> Html msg

Render the input(s) for one ABI argument.

Composes the existing Web3.Ui.Input.* primitives, recursing into arrays and tuples. Class names follow the BEM convention web3-abi-input / web3-abi-input__label / web3-abi-input__error / web3-abi-input__list / web3-abi-input__tuple.

type alias Config msg =
{ field : Field
, value : Value
, onChange : Value -> msg
, error : Maybe String
}

Configuration for view.

type Field

Description of one ABI argument: name, Solidity type string, and (for tuples) the recursive list of child fields.

{ name : String
, solType : String
, children : List Field
}
-> Field

Construct a Field.

fieldName : Field -> String

Extract the field's display name.

fieldSolType : Field -> String

Extract the field's Solidity type string (e.g. "uint256", "address[]").

Extract a field's recursive children (tuple fields), empty otherwise.

type Value

Opaque user-input value for an ABI argument of any shape.

Scalars carry their raw input buffer (a String); arrays carry a list of inner values; tuples carry an ordered list of field values matching their Field.children.

valueString : String -> Value

Construct a scalar value from a raw input buffer.

Construct a list value (for T[] / T[N] arguments).

Construct a tuple value.

stringValue : Value -> Maybe String

Extract the raw input buffer from a scalar value, if it is one.

listValues : Value -> Maybe (List Value)

Extract array elements, if this is a list value.

tupleValues : Value -> Maybe (List Value)

Extract tuple field values, if this is a tuple value.

Build the empty Value matching a Field's shape.

For scalars, returns valueString "". For dynamic arrays, an empty list. For fixed arrays, a list of N empty inner values. For tuples, a tuple of empty values matching the field's children.

parse : Field -> Value -> Result String Value

Parse a Value against its Field into a Json.Encode.Value ready for the JS port. Returns Err message on the first validation failure.

parseSlot : Field -> Value -> Result String Slot

Parse a Value against its Field into a Calldata.Slot.

This is the canonical parser for the pure-Elm calldata path — codegen tools emit parseSlot calls and feed the resulting slots to Web3.Abi.Calldata.calldata plus a baked selector, producing complete "0x…" calldata with zero JavaScript involvement.

Use parseSlot when building readCallRaw / writeCallRaw; use the existing parse when you need the legacy method+args port shape.