Cartouche.Erc20 (Cartouche v0.2.0)

Copy Markdown View Source

A wrapper for an ERC-20 contract, allowing the code to interact by pulling data from the contract, or sending transaction to it.

Summary

Functions

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.

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

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.

Types

call_opts()

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

exec_opts()

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

Functions

call_trx(token, call_data, call_opts)

@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()

@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(token, call_data, exec_opts)

@spec exec_trx(Cartouche.contract(), binary(), exec_opts()) :: 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(token, destination, amount_wei, exec_opts \\ [])

@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>>, <<0xDD>>, 100_000)