# `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.

# `decode`

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> "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd6"
    ...> |> Base.decode16!(case: :lower)
    ...> |> ABI.TypeDecoder.decode(
    ...>      %ABI.FunctionSelector{
    ...>        function: "baz",
    ...>        types: [
    ...>          {:int, 8}
    ...>        ],
    ...>        returns: [:int]
    ...>      }
    ...>    )
    [-42]

    iex> ABI.TypeEncoder.encode(["hello world"],[:string])
    ...> |> ABI.TypeDecoder.decode(
    ...>      %ABI.FunctionSelector{
    ...>        function: nil,
    ...>        types: [
    ...>          :string
    ...>        ]
    ...>      }
    ...>    )
    ["hello world"]

    iex> "00000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000001"
    ...> |> Base.decode16!(case: :lower)
    ...> |> ABI.TypeDecoder.decode(
    ...>      %ABI.FunctionSelector{
    ...>        function: nil,
    ...>        types: [
    ...>          {:tuple, [{:uint, 32}, :bool]}
    ...>        ]
    ...>      }
    ...>    )
    [{17, true}]

    iex> ABI.TypeEncoder.encode([[17,1]],[{:array,{:uint,32}}])
    ...> |> ABI.TypeDecoder.decode(
    ...>      %ABI.FunctionSelector{
    ...>        function: nil,
    ...>        types: [
    ...>          {:array, {:uint, 32}}
    ...>        ]
    ...>      }
    ...>    )
    [[17, 1]]

    iex> ABI.TypeEncoder.encode([[17, 1], true, <<16, 32>>], [{:array, {:uint, 32}},:bool,{:bytes, 2}])
    ...> |> ABI.TypeDecoder.decode(
    ...>      %ABI.FunctionSelector{
    ...>        function: nil,
    ...>        types: [
    ...>          {:array, {:uint, 32}},
    ...>          :bool,
    ...>          {:bytes, 2}
    ...>        ]
    ...>      }
    ...>    )
    [[17, 1], true, <<16, 32>>]

    iex> ABI.TypeEncoder.encode([{"awesome", true}], [{:tuple, [:string, :bool]}])
    ...> |> ABI.TypeDecoder.decode(
    ...>      %ABI.FunctionSelector{
    ...>        function: nil,
    ...>        types: [
    ...>          {:tuple, [:string, :bool]}
    ...>        ]
    ...>      }
    ...>    )
    [{"awesome", true}]

    iex> ABI.TypeEncoder.encode([{[]}],[{:tuple, [{:array, :address}]}])
    ...> |> ABI.TypeDecoder.decode(
    ...>      %ABI.FunctionSelector{
    ...>        function: nil,
    ...>        types: [
    ...>          {:tuple, [{:array, :address}]}
    ...>        ]
    ...>      }
    ...>    )
    [{[]}]

    iex> ABI.TypeEncoder.encode( [{
    ...>  "Unauthorized",
    ...>  [
    ...>    184341788326688649239867304918349890235378717380,
    ...>    765664983403968947098136133435535343021479462042,
    ...>  ]
    ...> }], [{:tuple,[:string, {:array, {:uint, 256}}]}])
    ...> |> ABI.TypeDecoder.decode(
    ...>      %ABI.FunctionSelector{
    ...>        function: nil,
    ...>        types: [{:tuple,[
    ...>          :string,
    ...>          {:array, {:uint, 256}}
    ...>        ]}]
    ...>      }
    ...>    )
    [{
      "Unauthorized",
      [
        184341788326688649239867304918349890235378717380,
        765664983403968947098136133435535343021479462042,
      ]
    }]

# `decode_bytes`

```elixir
@spec decode_bytes(binary(), non_neg_integer(), :left) :: {binary(), binary()}
```

# `decode_bytes`

```elixir
@spec decode_bytes(binary(), non_neg_integer(), :right, binary()) ::
  {binary(), binary()}
```

# `decode_bytes`

```elixir
@spec decode_bytes(binary(), non_neg_integer(), :right, binary(), binary()) ::
  {binary(), binary()}
```

# `decode_raw`

Similar to `ABI.TypeDecoder.decode/2` except accepts a list of types instead
of a function selector.

## Examples

    iex> ABI.TypeEncoder.encode([{"awesome", true}], [{:tuple, [:string, :bool]}])
    ...> |> ABI.TypeDecoder.decode_raw([{:tuple, [:string, :bool]}])
    [{"awesome", true}]

# `do_decode_raw`

# `mod`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
