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
sourceimpl 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) -> Abigen where
S1: Into<String>,
S2: Into<String>,
pub fn add_event_alias<S1, S2>(self, signature: S1, alias: S2) -> Abigen where
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) -> Abigen where
S1: Into<String>,
S2: Into<String>,
pub fn add_method_alias<S1, S2>(self, signature: S1, alias: S2) -> Abigen where
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 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) -> Abigen where
S: Into<String>,
pub fn add_event_derive<S>(self, derive: S) -> Abigen where
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.
Trait Implementations
sourceimpl FromIterator<Abigen> for MultiAbigen
impl FromIterator<Abigen> for MultiAbigen
sourcefn from_iter<I>(iter: I) -> MultiAbigen where
I: IntoIterator<Item = Abigen>,
fn from_iter<I>(iter: I) -> MultiAbigen where
I: IntoIterator<Item = Abigen>,
Creates a value from an iterator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Abigen
impl Send for Abigen
impl Sync for Abigen
impl Unpin for Abigen
impl UnwindSafe for Abigen
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span, returning an
Instrumented wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more