intrepidshape/elm-web3/2.1.0

NOTE: the latest version is 3.0.0

Web3.Contract.Send

Type-safe contract write calls (eth_sendTransaction).

Build a write call, encode it for the JS port, optionally estimate gas first.

-- Non-payable: approve
approve : Address -> BigInt -> WriteCall
approve spender amount =
    writeCall
        { contract = tokenAddress
        , method = "approve"
        , args = [ Encode.address spender, Encode.uint256 amount ]
        }


-- Payable: buy
buy : BigInt -> Wei -> WriteCall
buy minTokens value =
    payableCall
        { contract = routerAddress
        , method = "buy"
        , args = [ Encode.uint256 minTokens ]
        , value = value
        }

A write call to a contract.

{ contract : Address
, method : String
, args : List Value
}

Create a non-payable write call.

{ contract : Address
, data : String
}

Create a write call from pre-built hex calldata -- the result of Web3.Abi.Calldata.calldata. The JS port bridge sends data directly without re-encoding.

approve : T.Address -> T.Address -> BigInt -> WriteCall
approve contract spender amount =
    writeCallRaw
        { contract = contract
        , data =
            Calldata.calldata "095ea7b3"
                [ Calldata.address spender
                , Calldata.uint256 amount
                ]
        }
{ contract : Address
, method : String
, args : List Value
, value : BigInt
}

Create a payable write call with a value.

{ contract : Address
, data : String
, value : BigInt
}

Create a payable write call from pre-built hex calldata + a value.

Set a gas limit.

Set the sender explicitly.

Without this the JS bridge estimates and sends from the wallet's first account. Set it when the connected account is not the account the call must run as -- an estimate taken from the wrong msg.sender is a different transaction, and for anything permissioned it either reverts or reports a gas figure the real send will not match.

approve spender amount
    |> withFrom userAddress
    |> estimateGas
    |> web3Cmd
encode : WriteCall -> Value

Encode a write call for the JS port.

Encode a write call as an estimateGas command for the JS port.

estimateGas myWriteCall
-- sends { tag: "estimateGas", contract: ..., method: ..., args: ..., value: ... }
-- raw-calldata calls send { tag: "estimateGas", contract: ..., data: ... }
-- JS responds with { tag: "gasEstimate", gas: "21000" }

Emits exactly the same calldata, value and sender fields as encode does for the same call, so the returned figure applies to the transaction that is about to be signed. Prior to 2.1 this dropped data and from, which made every raw-calldata estimate an estimate of a different transaction.

{ bytecode : String
, args : List Value
, gasLimit : Maybe Int
}
-> Value

Encode a contract deployment for submission via the port.

encodeRawSend : String -> Value

Encode a raw signed transaction for broadcast via the port.