View Source Ethers.Contract (Ethers v0.0.3)
Dynamically creates modules for ABIs at compile time.
how-to-use
How to use
You can simply create a new module and call use Ethers.Contract in it with the desired parameters.
defmodule MyProject.Contract do
use Ethers.Contract, abi_file: "path/to/abi.json"
endAfter this, the functions in your contracts should be accessible just by calling
data = MyProject.Contract.example_function(...)
# Use data to handle eth_call
Ethers.Contract.call(data, to: "0xADDRESS", from: "0xADDRESS")
{:ok, [...]}
valid-use-options
Valid use options
abi: Used to pass in the encoded/decoded json ABI of contract.abi_file: Used to pass in the file path to the json ABI of contract.default_address: Default contract deployed address. Can be overridden with:tooption in every function.
execution-options
Execution Options
These can be specified for all the actions by contracts.
action: Type of action for this function. Here are available values.:calluseseth_callto call the function and get the result. Will not change blockchain state or cost gas.:senduseseth_sendTransactionto call:estimate_gasuseseth_estimateGasto estimate the gas usage of this transaction.:prepareonly prepares thedataneeded to make a transaction. Useful for Multicall.
from: The address of the wallet making this transaction. The private key should be loaded in the rpc server (For example: go-ethereum). Must be in"0x..."format.gas: The gas limit for your transaction.rpc_client: The RPC module implementing Ethereum JSON RPC functions. Defaults toEthereumex.HttpClientrpc_opts: Options to pass to the RCP client e.g.:url.to: The address of the recipient contract. It will be defaulted todefault_addressif it was specified in Contract otherwise is required. Must be in"0x..."format.
Link to this section Summary
Link to this section Types
@type action() :: :call | :send | :prepare
@type t_event_output() :: %{ topics: [binary()], address: Ethers.Types.t_address(), selector: ABI.FunctionSelector.t() }
@type t_function_output() :: %{ data: binary(), to: Ethers.Types.t_address(), selector: ABI.FunctionSelector.t() }