abi v0.1.0 ABI.TypeDecoder

ABI.TypeDecoder is responsible for decoding types to the format expected by Solidity. We generally take a function selector and binary data and decode that into the original arguments according to the specification.

Link to this section Summary

Functions

Decodes the given data based on the function selector

Link to this section Functions

Link to this function decode(encoded_data, function_selector)

Decodes the given data based on the function selector.

Note, we don’t currently try to guess the function name?

Examples

iex> "00000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001"
...> |> Base.decode16!(case: :lower)
...> |> ABI.TypeDecoder.decode(
...>      %ABI.FunctionSelector{
...>        function: "baz",
...>        types: [
...>          {:uint, 32},
...>          :bool
...>        ],
...>        returns: :bool
...>      }
...>    )
[69, true]

iex> "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b00000000000000000000000000000000000000000068656c6c6f20776f726c64"
...> |> Base.decode16!(case: :lower)
...> |> ABI.TypeDecoder.decode(
...>      %ABI.FunctionSelector{
...>        function: "baz",
...>        types: [
...>          :string
...>        ]
...>      }
...>    )
["hello world"]
Link to this function decode_bytes(data, size)
decode_bytes(binary(), integer()) :: {binary(), binary()}