pub struct Evm {
pub client: EvmClient,
}Expand description
EVM Client for interacting with various EVM chains
Fields§
§client: EvmClientImplementations§
Source§impl Evm
impl Evm
Sourcepub async fn get_block_by_number(
&self,
block_number: BlockNumber,
) -> Result<Option<Block<H256>>, EvmError>
pub async fn get_block_by_number( &self, block_number: BlockNumber, ) -> Result<Option<Block<H256>>, EvmError>
Get block by number (height) - returns block with transaction hashes
Sourcepub async fn get_block_by_hash(
&self,
block_hash: H256,
) -> Result<Option<Block<H256>>, EvmError>
pub async fn get_block_by_hash( &self, block_hash: H256, ) -> Result<Option<Block<H256>>, EvmError>
Get block by hash - returns block with transaction hashes
Sourcepub async fn get_block_with_txs(
&self,
block_number: BlockNumber,
) -> Result<Option<Block<Transaction>>, EvmError>
pub async fn get_block_with_txs( &self, block_number: BlockNumber, ) -> Result<Option<Block<Transaction>>, EvmError>
Get block with full transaction details
Sourcepub async fn get_block_with_txs_by_hash(
&self,
block_hash: H256,
) -> Result<Option<Block<Transaction>>, EvmError>
pub async fn get_block_with_txs_by_hash( &self, block_hash: H256, ) -> Result<Option<Block<Transaction>>, EvmError>
Get block with full transaction details by hash
Sourcepub async fn new(evm_type: EvmType) -> Result<Self, EvmError>
pub async fn new(evm_type: EvmType) -> Result<Self, EvmError>
Create a new EVM client without wallet
§Example
use evm_utils::Evm;
use evm_client::EvmType;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
let evm = Evm::new(EvmType::Ethereum).await?;
let chain_id = evm.get_chain_id().await?;
println!("Connected to chain ID: {}", chain_id);
Ok(())
}Sourcepub async fn with_wallet(
evm_type: EvmType,
private_key: &str,
) -> Result<Self, EvmError>
pub async fn with_wallet( evm_type: EvmType, private_key: &str, ) -> Result<Self, EvmError>
Create a new EVM client with wallet
§Example
use evm_utils::Evm;
use evm_client::EvmType;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
let private_key = "your_private_key_here";
let evm = Evm::with_wallet(EvmType::Ethereum, private_key).await?;
let balance = evm.get_wallet_balance().await?;
println!("Wallet balance: {}", balance);
Ok(())
}Sourcepub async fn get_chain_id(&self) -> Result<u64, EvmError>
pub async fn get_chain_id(&self) -> Result<u64, EvmError>
Get chain ID
§Example
async fn example(evm: Evm) -> Result<(), Box<dyn std::error::Error>> {
let chain_id = evm.get_chain_id().await?;
println!("Chain ID: {}", chain_id);
Ok(())
}Sourcepub async fn get_block_number(&self) -> Result<u64, EvmError>
pub async fn get_block_number(&self) -> Result<u64, EvmError>
Get block number
§Example
async fn example(evm: Evm) -> Result<(), Box<dyn std::error::Error>> {
let block_number = evm.get_block_number().await?;
println!("Current block number: {}", block_number);
Ok(())
}Sourcepub async fn get_balance(&self, address: Address) -> Result<U256, EvmError>
pub async fn get_balance(&self, address: Address) -> Result<U256, EvmError>
Get balance of an address
§Example
use ethers::types::Address;
async fn example(evm: Evm) -> Result<(), Box<dyn std::error::Error>> {
let address: Address = "0x742d35Cc6634C0532925a3b8D6B5d7a4C03a3a7d".parse()?;
let balance = evm.get_balance(address).await?;
println!("Balance: {}", balance);
Ok(())
}Sourcepub async fn get_transaction_count(
&self,
address: Address,
) -> Result<u64, EvmError>
pub async fn get_transaction_count( &self, address: Address, ) -> Result<u64, EvmError>
Get transaction count (nonce) for an address
§Example
use ethers::types::Address;
async fn example(evm: Evm) -> Result<(), Box<dyn std::error::Error>> {
let address: Address = "0x742d35Cc6634C0532925a3b8D6B5d7a4C03a3a7d".parse()?;
let nonce = evm.get_transaction_count(address).await?;
println!("Nonce: {}", nonce);
Ok(())
}Sourcepub async fn get_gas_price(&self) -> Result<U256, EvmError>
pub async fn get_gas_price(&self) -> Result<U256, EvmError>
Get gas price
§Example
async fn example(evm: Evm) -> Result<(), Box<dyn std::error::Error>> {
let gas_price = evm.get_gas_price().await?;
println!("Gas price: {}", gas_price);
Ok(())
}Sourcepub async fn send_transaction(
&self,
tx: TransactionRequest,
) -> Result<H256, EvmError>
pub async fn send_transaction( &self, tx: TransactionRequest, ) -> Result<H256, EvmError>
Send a raw transaction
§Example
use ethers::types::{TransactionRequest, Address, U256};
async fn example(evm: Evm) -> Result<(), Box<dyn std::error::Error>> {
let to_address: Address = "0x742d35Cc6634C0532925a3b8D6B5d7a4C03a3a7d".parse()?;
let tx = TransactionRequest::new()
.to(to_address)
.value(U256::from(1000000000000000u64));
let tx_hash = evm.send_transaction(tx).await?;
println!("Transaction sent: {:?}", tx_hash);
Ok(())
}Sourcepub async fn get_transaction_receipt(
&self,
tx_hash: H256,
) -> Result<Option<TransactionReceipt>, EvmError>
pub async fn get_transaction_receipt( &self, tx_hash: H256, ) -> Result<Option<TransactionReceipt>, EvmError>
Get transaction receipt
§Example
use ethers::types::H256;
async fn example(evm: Evm) -> Result<(), Box<dyn std::error::Error>> {
let tx_hash: H256 = "0x...".parse()?;
let receipt = evm.get_transaction_receipt(tx_hash).await?;
if let Some(receipt) = receipt {
println!("Transaction status: {}", receipt.status);
}
Ok(())
}Sourcepub async fn get_logs(&self, filter: Filter) -> Result<Vec<Log>, EvmError>
pub async fn get_logs(&self, filter: Filter) -> Result<Vec<Log>, EvmError>
Get logs by filter
§Example
use ethers::types::Filter;
use ethers::types::Address;
async fn example(evm: Evm) -> Result<(), Box<dyn std::error::Error>> {
let contract_address: Address = "0x...".parse()?;
let filter = Filter::new()
.address(contract_address)
.from_block(1000000)
.to_block(1000100);
let logs = evm.get_logs(filter).await?;
println!("Found {} logs", logs.len());
Ok(())
}Sourcepub async fn get_wallet_balance(&self) -> Result<U256, EvmError>
pub async fn get_wallet_balance(&self) -> Result<U256, EvmError>
Get native token balance for the wallet
§Example
async fn example(evm: Evm) -> Result<(), Box<dyn std::error::Error>> {
let balance = evm.get_wallet_balance().await?;
println!("Wallet balance: {}", balance);
Ok(())
}Sourcepub fn get_trade_service(self: Arc<Self>) -> Trade
pub fn get_trade_service(self: Arc<Self>) -> Trade
Get trade service for executing trades
§Example
use std::sync::Arc;
async fn example(evm: Evm) -> Result<(), Box<dyn std::error::Error>> {
let evm_arc = Arc::new(evm);
let trade_service = evm_arc.clone().get_trade_service();
Ok(())
}Sourcepub fn get_trade_listener(self: Arc<Self>) -> TradeEventListener
pub fn get_trade_listener(self: Arc<Self>) -> TradeEventListener
Get trade event listener for monitoring trade events
§Example
use std::sync::Arc;
async fn example(evm: Evm) -> Result<(), Box<dyn std::error::Error>> {
let evm_arc = Arc::new(evm);
let trade_listener = evm_arc.clone().get_trade_listener();
Ok(())
}Sourcepub fn get_mempool_service(self: Arc<Self>) -> MempoolService
pub fn get_mempool_service(self: Arc<Self>) -> MempoolService
Get mempool service for mempool interactions
§Example
use std::sync::Arc;
async fn example(evm: Evm) -> Result<(), Box<dyn std::error::Error>> {
let evm_arc = Arc::new(evm);
let mempool_service = evm_arc.clone().get_mempool_service();
Ok(())
}Sourcepub fn get_mempool_listener(self: Arc<Self>) -> MempoolListener
pub fn get_mempool_listener(self: Arc<Self>) -> MempoolListener
Get mempool listener for monitoring mempool activities
§Example
use std::sync::Arc;
async fn example(evm: Evm) -> Result<(), Box<dyn std::error::Error>> {
let evm_arc = Arc::new(evm);
let mempool_listener = evm_arc.clone().get_mempool_listener();
Ok(())
}Sourcepub fn get_block_service(self: Arc<Self>) -> BlockService
pub fn get_block_service(self: Arc<Self>) -> BlockService
Get block service for block-related operations
§Example
use std::sync::Arc;
async fn example(evm: Evm) -> Result<(), Box<dyn std::error::Error>> {
let evm_arc = Arc::new(evm);
let block_service = evm_arc.clone().get_block_service();
let latest_block = block_service.get_latest_block().await?;
if let Some(block) = latest_block {
println!("Latest block: #{}", block.number.unwrap_or_default());
}
Ok(())
}Sourcepub async fn listen_latest_blocks(
&self,
) -> Result<Receiver<Block<H256>>, EvmError>
pub async fn listen_latest_blocks( &self, ) -> Result<Receiver<Block<H256>>, EvmError>
Listen to the latest block (listen to newly generated blocks in real time)
§Example
let mut block_receiver = trade_service.listen_latest_blocks().await?;
while let Some(block) = block_receiver.recv().await {
println!("New block: #{}", block.number.unwrap_or_default());
}Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Evm
impl !UnwindSafe for Evm
impl Freeze for Evm
impl Send for Evm
impl Sync for Evm
impl Unpin for Evm
impl UnsafeUnpin for Evm
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> JsonSchemaMaybe for T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.