A wrapper for an ERC-20 contract, 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. | - |
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.
Executes a transfer transaction.
Types
Functions
@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.
@spec errors() :: [String.t()]
Returns a list of known error codes (ABI signatures), which can be used when parsing error messages from contract calls.
@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.
@spec transfer( Cartouche.contract(), Cartouche.address(), non_neg_integer(), exec_opts() ) :: {:ok, binary()} | {:error, term()}
Executes a transfer transaction.
Arguments:
destination: The destination addressamount_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)