Struct ethers_contract::Abigen

source ·
pub struct Abigen { /* private fields */ }
Available on crate feature abigen only.
Expand description

Builder struct for generating type-safe bindings from a contract’s ABI

Note: Your contract’s ABI must contain the stateMutability field. This is still not supported by Vyper, so you must adjust your ABIs and replace constant functions with view or pure.

To generate bindings for multiple contracts at once see also crate::MultiAbigen.

Example

Running the code below will generate a file called token.rs containing the bindings inside, which exports an ERC20Token struct, along with all its events. Put into a build.rs file this will generate the bindings during cargo build.

Abigen::new("ERC20Token", "./abi.json")?.generate()?.write_to_file("token.rs")?;

Implementations§

Creates a new builder with the given ABI JSON source.

Attempts to load a new builder from an ABI JSON file at the specific path.

Manually adds a solidity event alias to specify what the event struct and function name will be in Rust.

Manually adds a solidity method alias to specify what the method name will be in Rust. For solidity methods without an alias, the snake cased method name will be used.

Manually adds a solidity error alias to specify what the error struct will be in Rust.

Specify whether or not to format the code using a locally installed copy of rustfmt.

Note that in case rustfmt does not exist or produces an error, the unformatted code will be used.

Add a custom derive to the derives for event structs and enums.

This makes it possible to for example derive serde::Serialize and serde::Deserialize for events.

Generates the contract bindings.

Expands the Abigen and returns the ExpandedContract that holds all tokens and the Context that holds the state used during expansion.

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
Creates a value from an iterator. 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

Returns the argument unchanged.

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
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

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
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