Trait BoundEthInterface

Source
pub trait BoundEthInterface:
    AsRef<DynClient<L1>>
    + 'static
    + Sync
    + Send
    + Debug {
    // Required methods
    fn clone_boxed(&self) -> Box<dyn BoundEthInterface>;
    fn for_component(
        self: Box<Self>,
        component_name: &'static str,
    ) -> Box<dyn BoundEthInterface>;
    fn contract(&self) -> &Contract;
    fn contract_addr(&self) -> H160;
    fn chain_id(&self) -> L1ChainId;
    fn sender_account(&self) -> Address;
    fn allowance_on_account<'life0, 'life1, 'async_trait>(
        &'life0 self,
        token_address: Address,
        address: Address,
        erc20_abi: &'life1 Contract,
    ) -> Pin<Box<dyn Future<Output = Result<U256, ContractCallError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn sign_prepared_tx_for_addr<'life0, 'async_trait>(
        &'life0 self,
        data: Vec<u8>,
        contract_addr: H160,
        options: Options,
    ) -> Pin<Box<dyn Future<Output = Result<SignedCallResult, SigningError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

An extension of EthInterface trait, which is used to perform queries that are bound to a certain contract and account.

The example use cases for this trait would be:

  • An operator that sends transactions and interacts with ZKsync contract.
  • A wallet implementation in the SDK that is tied to a user’s account.

When adding a method to this trait:

  1. Make sure that it’s indeed “bound”. If not, add it to the EthInterface trait instead.
  2. Consider adding the “unbound” version to the EthInterface trait and create a default method implementation that invokes contract / contract_addr / sender_account methods.

Required Methods§

Source

fn clone_boxed(&self) -> Box<dyn BoundEthInterface>

Clones this client.

Source

fn for_component( self: Box<Self>, component_name: &'static str, ) -> Box<dyn BoundEthInterface>

Tags this client as working for a specific component. The component name can be used in logging, metrics etc. The component name should be copied to the clones of this client, but should not be passed upstream.

Source

fn contract(&self) -> &Contract

ABI of the contract that is used by the implementer.

Source

fn contract_addr(&self) -> H160

Address of the contract that is used by the implementer.

Source

fn chain_id(&self) -> L1ChainId

Chain ID of the L1 network the client is configured to connected to.

This value should be externally provided by the user rather than requested from the network to avoid accidental network mismatch.

Source

fn sender_account(&self) -> Address

Address of the account associated with the object implementing the trait.

Source

fn allowance_on_account<'life0, 'life1, 'async_trait>( &'life0 self, token_address: Address, address: Address, erc20_abi: &'life1 Contract, ) -> Pin<Box<dyn Future<Output = Result<U256, ContractCallError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Returns the certain ERC20 token allowance for the pair (Self::sender_account(), address).

Source

fn sign_prepared_tx_for_addr<'life0, 'async_trait>( &'life0 self, data: Vec<u8>, contract_addr: H160, options: Options, ) -> Pin<Box<dyn Future<Output = Result<SignedCallResult, SigningError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Signs the transaction and sends it to the Ethereum network. Expected to use credentials associated with Self::sender_account().

Implementations§

Source§

impl dyn BoundEthInterface

Source

pub async fn nonce_at(&self, block: BlockNumber) -> EnrichedClientResult<U256>

Returns the nonce of the Self::sender_account() at the specified block.

Source

pub async fn current_nonce(&self) -> EnrichedClientResult<U256>

Returns the current nonce of the Self::sender_account().

Source

pub async fn pending_nonce(&self) -> EnrichedClientResult<U256>

Returns the pending nonce of the Self::sender_account().

Source

pub async fn sign_prepared_tx( &self, data: Vec<u8>, options: Options, ) -> Result<SignedCallResult, SigningError>

Similar to [EthInterface::sign_prepared_tx_for_addr], but is fixed over Self::contract_addr().

Source

pub async fn sender_eth_balance(&self) -> EnrichedClientResult<U256>

Returns the ETH balance of Self::sender_account().

Source

pub fn encode_tx_data(&self, func: &str, params: Vec<Token>) -> Vec<u8>

Encodes a function using the Self::contract() ABI.

params are tokenized parameters of the function. Most of the time, you can use Tokenize trait to convert the parameters into tokens.

Trait Implementations§

Source§

impl Clone for Box<dyn BoundEthInterface>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Implementors§