Struct ethers_contract::Abigen
source · pub struct Abigen { /* private fields */ }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§
source§impl Abigen
impl Abigen
sourcepub fn new<S>(contract_name: &str, abi_source: S) -> Result<Abigen, Report>where
S: AsRef<str>,
pub fn new<S>(contract_name: &str, abi_source: S) -> Result<Abigen, Report>where
S: AsRef<str>,
Creates a new builder with the given ABI JSON source.
sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Abigen, Report>
pub fn from_file(path: impl AsRef<Path>) -> Result<Abigen, Report>
Attempts to load a new builder from an ABI JSON file at the specific path.
sourcepub fn add_event_alias<S1, S2>(self, signature: S1, alias: S2) -> Abigenwhere
S1: Into<String>,
S2: Into<String>,
pub fn add_event_alias<S1, S2>(self, signature: S1, alias: S2) -> Abigenwhere
S1: Into<String>,
S2: Into<String>,
Manually adds a solidity event alias to specify what the event struct and function name will be in Rust.
sourcepub fn add_method_alias<S1, S2>(self, signature: S1, alias: S2) -> Abigenwhere
S1: Into<String>,
S2: Into<String>,
pub fn add_method_alias<S1, S2>(self, signature: S1, alias: S2) -> Abigenwhere
S1: Into<String>,
S2: Into<String>,
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.
sourcepub fn add_error_alias<S1, S2>(self, signature: S1, alias: S2) -> Abigenwhere
S1: Into<String>,
S2: Into<String>,
pub fn add_error_alias<S1, S2>(self, signature: S1, alias: S2) -> Abigenwhere
S1: Into<String>,
S2: Into<String>,
Manually adds a solidity error alias to specify what the error struct will be in Rust.
sourcepub fn rustfmt(self, rustfmt: bool) -> Abigen
pub fn rustfmt(self, rustfmt: bool) -> Abigen
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.
sourcepub fn add_event_derive<S>(self, derive: S) -> Abigenwhere
S: Into<String>,
pub fn add_event_derive<S>(self, derive: S) -> Abigenwhere
S: Into<String>,
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.
sourcepub fn generate(self) -> Result<ContractBindings, Report>
pub fn generate(self) -> Result<ContractBindings, Report>
Generates the contract bindings.
sourcepub fn expand(self) -> Result<(ExpandedContract, Context), Report>
pub fn expand(self) -> Result<(ExpandedContract, Context), Report>
Expands the Abigen and returns the ExpandedContract that holds all tokens and the
Context that holds the state used during expansion.