# `Ethers.Types`
[🔗](https://github.com/ExWeb3/elixir_ethers/blob/v0.6.12/lib/ethers/types.ex#L1)

EVM types and compound type definitions

# `t_address`

```elixir
@type t_address() :: &lt;&lt;_::336&gt;&gt; | &lt;&lt;_::160&gt;&gt;
```

Ethereum address in its hex format with 0x or in its binary format

## Examples
- `"0xdAC17F958D2ee523a2206206994597C13D831ec7"`
- `<<218, 193, 127, 149, 141, 46, 229, 35, 162, 32, 98, 6, 153, 69, 151, 193, 61, 131, 30, 199>>`

# `t_bitsizes`

```elixir
@type t_bitsizes() ::
  256
  | 248
  | 240
  | 232
  | 224
  | 216
  | 208
  | 200
  | 192
  | 184
  | 176
  | 168
  | 160
  | 152
  | 144
  | 136
  | 128
  | 120
  | 112
  | 104
  | 96
  | 88
  | 80
  | 72
  | 64
  | 56
  | 48
  | 40
  | 32
  | 24
  | 16
  | 8
```

# `t_bytesizes`

```elixir
@type t_bytesizes() ::
  32
  | 31
  | 30
  | 29
  | 28
  | 27
  | 26
  | 25
  | 24
  | 23
  | 22
  | 21
  | 20
  | 19
  | 18
  | 17
  | 16
  | 15
  | 14
  | 13
  | 12
  | 11
  | 10
  | 9
  | 8
  | 7
  | 6
  | 5
  | 4
  | 3
  | 2
  | 1
```

# `t_evm_types`

```elixir
@type t_evm_types() ::
  {:uint, t_bitsizes()}
  | {:int, t_bitsizes()}
  | {:bytes, t_bytesizes()}
  | :bytes
  | :string
  | :address
  | {:array, t_evm_types()}
  | {:array, t_evm_types(), non_neg_integer()}
  | {:tuple, [t_evm_types()]}
```

# `t_hash`

```elixir
@type t_hash() :: &lt;&lt;_::528&gt;&gt;
```

keccak hash in its hex format with 0x

## Examples
- `"0xd4288c8e733eb71a39fe2e8dd4912ce54d8d26d9874f30309b26b4b071260422"`

# `t_pub_key`

```elixir
@type t_pub_key() ::
  &lt;&lt;_::520&gt;&gt; | &lt;&lt;_::512&gt;&gt; | &lt;&lt;_::264&gt;&gt; | &lt;&lt;_::1042&gt;&gt; | &lt;&lt;_::1026&gt;&gt; | &lt;&lt;_::530&gt;&gt;
```

Public key either in its uncompressed format (64 bytes MAY BE prefixed with 0x04) or its
compressed format (32 bytes MUST BE prefixed with 0x02 or 0x03)

It can be hex encoded but only with 0x prefix.

Compressed public key MUST have a prefix.

# `default`

Returns the default value in the given type if supported.

## Examples

    iex> Ethers.Types.default(:address)
    "0x0000000000000000000000000000000000000000"

    iex> Ethers.Types.default({:int, 32})
    0

    iex> Ethers.Types.default({:uint, 8})
    0

    iex> Ethers.Types.default({:int, 128})
    0

    iex> Ethers.Types.default(:string)
    ""

    iex> Ethers.Types.default(:bytes)
    ""

    iex> Ethers.Types.default({:bytes, 8})
    <<0, 0, 0, 0, 0, 0, 0, 0>>

# `matches_type?`

```elixir
@spec matches_type?(term(), t_evm_types()) :: boolean()
```

Checks if a given data matches a given solidity type

## Examples

    iex> Ethers.Types.matches_type?(false, :bool)
    true

    iex> Ethers.Types.matches_type?(200, {:uint, 8})
    true

    iex> Ethers.Types.matches_type?(400, {:uint, 8})
    false

    iex> Ethers.Types.matches_type?("0xdAC17F958D2ee523a2206206994597C13D831ec7", :address)
    true

# `max`

Returns the maximum possible value in the given type if supported.

## Examples

    iex> Ethers.Types.max({:uint, 8})
    255

    iex> Ethers.Types.max({:int, 8})
    127

    iex> Ethers.Types.max({:uint, 16})
    65535

    iex> Ethers.Types.max({:int, 16})
    32767

    iex> Ethers.Types.max({:uint, 128})
    340282366920938463463374607431768211455

    iex> Ethers.Types.max({:int, 128})
    170141183460469231731687303715884105727

# `min`

Returns the minimum possible value in the given type if supported.

## Examples

    iex> Ethers.Types.min({:uint, 8})
    0

    iex> Ethers.Types.min({:int, 8})
    -128

    iex> Ethers.Types.min({:uint, 16})
    0

    iex> Ethers.Types.min({:int, 16})
    -32768

    iex> Ethers.Types.min({:int, 24})
    -8388608

    iex> Ethers.Types.min({:int, 128})
    -170141183460469231731687303715884105728

# `to_elixir_type`

Converts EVM data types to typespecs for documentation

# `typed`

```elixir
@spec typed(term(), t_evm_types() | nil) :: {:typed, term(), term()} | no_return()
```

Validates and creates typed values to use with functions or events.

Typed values are useful when there are multiple overloads of same function or event and you need
to specify one of them to be used.

Also raises with ArgumentError in case value does not match the given type.

## Examples

    iex> Ethers.Types.typed({:uint, 256}, 5)
    {:typed, {:uint, 256}, 5}

    iex> Ethers.Types.typed(:bytes, <<0, 1, 2>>)
    {:typed, :bytes, <<0, 1, 2>>}

---

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