Struct substreams_ethereum::Abigen
source · pub struct Abigen<'a> { /* 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§
source§impl<'a> Abigen<'a>
impl<'a> Abigen<'a>
sourcepub fn new<S>(_contract_name: S, path: S) -> Result<Abigen<'a>, Error>where
S: AsRef<str>,
pub fn new<S>(_contract_name: S, path: S) -> Result<Abigen<'a>, 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).
sourcepub fn from_bytes<S>(
_contract_name: S,
abi_bytes: &'a [u8]
) -> Result<Abigen<'a>, Error>where
S: AsRef<str>,
pub fn from_bytes<S>( _contract_name: S, abi_bytes: &'a [u8] ) -> Result<Abigen<'a>, Error>where S: AsRef<str>,
Creates a new builder for the given contract name and where the ABI bytes can be found at ‘abi_bytes’.
pub fn generate(&self) -> Result<GeneratedBindings, Error>
Trait Implementations§
Auto Trait Implementations§
impl<'a> RefUnwindSafe for Abigen<'a>
impl<'a> Send for Abigen<'a>
impl<'a> Sync for Abigen<'a>
impl<'a> Unpin for Abigen<'a>
impl<'a> UnwindSafe for Abigen<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more