Struct substreams_ethereum::Abigen
source · [−]pub struct Abigen { /* private fields */ }
Expand description
Builder struct for generating type-safe bindings Rust code directly in your project from a contract’s ABI. This is equivalent to code generated by macro use_contract.
Example
Running the code below will generate a file called erc721.rs
containing the
bindings inside, which exports an erc
struct, along with all its events. Put into a
build.rs
file this will generate the bindings during cargo build
.
use anyhow::{Ok, Result};
use substreams_ethereum::Abigen;
fn main() -> Result<(), anyhow::Error> {
Abigen::new("ERC721", "abi/erc721.json")?
.generate()?
.write_to_file("src/abi/erc721.rs")?;
Ok(())
}
Implementations
sourceimpl Abigen
impl Abigen
Builder struct for generating type-safe bindings Rust code directly in your project from a contract’s ABI. This is equivalent to code generated by macro use_contract.
Example
Running the code below will generate a file called erc721.rs
containing the
bindings inside, which exports an erc
struct, along with all its events. Put into a
build.rs
file this will generate the bindings during cargo build
.
use anyhow::{Ok, Result};
use substreams_ethereum::Abigen;
fn main() -> Result<(), anyhow::Error> {
Abigen::new("ERC721", "abi/erc721.json")?
.generate()?
.write_to_file("src/abi/erc721.rs")?;
Ok(())
}
sourcepub fn new<S>(_contract_name: S, path: S) -> Result<Abigen, Error> where
S: AsRef<str>,
pub fn new<S>(_contract_name: S, path: S) -> Result<Abigen, Error> where
S: AsRef<str>,
Creates a new builder for the given contract name and where the ABI JSON file can be found
at path
, which is relative to the your crate’s root directory (where Cargo.toml
file is located).
pub fn generate(&self) -> Result<GeneratedBindings, Error>
Trait Implementations
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