intrepidshape/elm-web3/1.4.0

NOTE: the latest version is 3.0.0

Web3.Contract.Event

Contract event watching via port subscriptions.

-- Subscribe to Transfer events
subscriptions model =
    Event.watchEvent
        { contract = tokenAddress
        , event = "Transfer"
        , filter = []
        }
        |> Event.decoder transferDecoder
        |> onContractEvent TransferReceived
type alias EventFilter =
{ contract : Address
, event : String
, topics : List (Maybe String)
}

An event subscription filter.

type alias EventLog a =
{ data : a
, contract : Address
, topics : List String
, blockNumber : Int
, txHash : TxHash
, logIndex : Int
}

A decoded event log.

type alias GetLogsQuery =
{ contract : Address
, fromBlock : BlockNumber
, toBlock : BlockNumber
, topics : List (Maybe String)
}

A query for getLogs with fromBlock/toBlock range.

watchEvent : EventFilter -> Value

Create an event watch command.

encode : EventFilter -> Value

Encode an event filter for the JS port.

decoder : Decoder a -> Decoder (EventLog a)

Decode a watchEvent log from the JS port.

Requires the message to have tag: "eventLog" — use logsDecoder for the batch getLogs response which wraps logs in an array.

getLogs : GetLogsQuery -> Value

Encode a getLogs query for the JS port.

logsDecoder : Decoder a -> Decoder (List (EventLog a))

Decode a list of event logs with a custom data decoder.

Decodes the { tag: "logs", logs: [...] } response from getLogs.