View Source Ethers.Contract (Ethers v0.5.5)

Dynamically creates modules for ABIs at compile time.

How to use

You can simply create a new module and call use Ethers.Contract in it with the desired parameters.

# Using an ABI file
defmodule MyProject.Contract do
  use Ethers.Contract, abi_file: "path/to/abi.json"
end

# Providing a default address
defmodule MyProject.Contract do
  use Ethers.Contract, abi_file: "path/to/abi.json", default_address: "0x1234...999"
end

# Using an ABI directly
defmodule MyProject.Contract do
  use Ethers.Contract, abi: [%{"inputs" => [], "type" => "constructor"}, ...]
end

After this, the functions in your contracts should be accessible just by calling

data = MyProject.Contract.example_function(...)

# Use data to handle eth_call
Ethers.call(data, to: "0xADDRESS", from: "0xADDRESS")
{:ok, [...]}

Valid use options

  • abi: Used to pass in the decoded (or even encoded json binay) ABI of contract.
  • abi_file: Used to pass in the file path to the json ABI of contract.
  • default_address: Default contract deployed address to include in the parameters. (Optional)
  • skip_docs: Determines if Ethers should skip generating docs and typespecs. (Default: false)
    • true: Skip docs and typespecs for all functions.
    • false: Generate docs and typespecs for all functions.
    • [{function_name :: atom(), skip_docs :: boolean()}]: Specify for each function.