# `Cartouche.Erc20`
[🔗](https://github.com/zenhive/cartouche/blob/main/lib/cartouche/erc_20.ex#L1)

A wrapper for an [ERC-20 contract](https://eips.ethereum.org/EIPS/eip-20),
allowing the code to interact by pulling data from the contract, or sending
transaction to it.

## API Functions
| Function | Arity | Description | Param Kinds |
| --- | --- | --- | --- |
| `transfer` | 4 | Execute an ERC-20 `transfer(address,uint256)` transaction. | `token: value`, `destination: value`, `amount_wei: value`, `exec_opts: value` |
| `call_trx` | 3 | Run ABI-encoded ERC-20 calldata as a read-only `eth_call`. | `token: value`, `call_data: value`, `call_opts: value` |
| `exec_trx` | 3 | Execute ABI-encoded ERC-20 calldata as a signed transaction. | `token: value`, `call_data: value`, `exec_opts: value` |
| `errors` | 0 | Return the ERC-20 error signatures known to this wrapper. | - |

# `call_opts`

```elixir
@type call_opts() :: Keyword.t()
```

# `exec_opts`

```elixir
@type exec_opts() :: Keyword.t()
```

# `call_trx`

```elixir
@spec call_trx(Cartouche.contract(), binary(), call_opts()) :: term()
```

Performs an `eth_call` against the given ERC-20 token with the provided
ABI-encoded `call_data` and zero value/gas. Returns the call's return data
without sending a transaction. `call_opts` is forwarded to
`Cartouche.RPC.call_trx/2` with this module's known error signatures
merged in.

# `errors`

```elixir
@spec errors() :: [String.t()]
```

Returns a list of known error codes (ABI signatures), which can be used
when parsing error messages from contract calls.

# `exec_trx`

```elixir
@spec exec_trx(Cartouche.contract(), binary(), exec_opts()) ::
  {:ok, binary()} | {:error, term()}
```

Executes a transaction against the given ERC-20 token, using the provided
ABI-encoded `call_data`. The configured Cartouche signer signs and submits
the transaction; `exec_opts` is forwarded to `Cartouche.RPC.execute_trx/3`
with this module's known error signatures merged in.

# `transfer`

```elixir
@spec transfer(
  Cartouche.contract(),
  Cartouche.address(),
  non_neg_integer(),
  exec_opts()
) ::
  {:ok, binary()} | {:error, term()}
```

Executes a `transfer` transaction.

Arguments:
  - `destination`: The destination address
  - `amount_wei`: The amount, in token wei, to transfer.
  - `exec_opts`: Execution options, such as the gas price for the transaction.

## Examples

    iex> {:ok, _trx_id} = Cartouche.Erc20.transfer(<<0xCC::160>>, <<0xDD::160>>, 100_000)

---

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