Struct ethers_contract_abigen::MultiAbigen[][src]

pub struct MultiAbigen { /* fields omitted */ }
Expand description

Generates bindings for a series of contracts

This type can be used to generate multiple ContractBindings and put them all in a single rust module, (eg. a contracts directory).

This can be used to

  1. write all bindings directly into a new directory in the project’s source directory, so that it is included in the repository. 2) write all bindings to the value of cargo’s OUT_DIR in a build script and import the bindings as include!(concat!(env!("OUT_DIR"), "/mod.rs"));.

However, the main purpose of this generator is to create bindings for option 1) and write all contracts to some contracts module in src, like src/contracts/mod.rs once via a build script or a test. After that it’s recommend to remove the build script and replace it with an integration test (See MultiAbigen::ensure_consistent_bindings) that fails if the generated code is out of date. This has several advantages:

  • No need for downstream users to compile the build script
  • No need for downstream users to run the whole abigen! generation steps
  • The generated code is more usable in an IDE
  • CI will fail if the generated code is out of date (if abigen! or the contract’s ABI itself changed)

See MultiAbigen::ensure_consistent_bindings for the recommended way to set this up to generate the bindings once via a test and then use the test to ensure consistency.

Implementations

Create a new instance from a series of already resolved Abigen

Create a new instance from a series (contract name, abi_source)

See Abigen::new

Reads all json files contained in the given dir and use the file name for the name of the ContractBindings. This is equivalent to calling MultiAbigen::new with all the json files and their filename.

Example
abi
├── ERC20.json
├── Contract1.json
├── Contract2.json
...
let gen = MultiAbigen::from_json_files("./abi").unwrap();

Write all bindings into a single rust file instead of separate modules

Generates all the bindings and writes them to the given module

Example

Read all json abi files from the ./abi directory

abi
├── ERC20.json
├── Contract1.json
├── Contract2.json
...

and write them to the ./src/contracts location as

src/contracts
├── mod.rs
├── er20.rs
├── contract1.rs
├── contract2.rs
...
let gen = MultiAbigen::from_json_files("./abi").unwrap();
gen.write_to_module("./src/contracts").unwrap();

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more