use ethers_core::{ abi::{Detokenize, Error as AbiError, Function, InvalidOutputType}, types::{Address, BlockNumber, Bytes, TransactionRequest, TxHash, U256}, }; use ethers_providers::{JsonRpcClient, ProviderError}; use ethers_signers::{Client, ClientError, Signer}; use std::{fmt::Debug, marker::PhantomData, sync::Arc}; use thiserror::Error as ThisError; #[derive(ThisError, Debug)] /// An Error which is thrown when interacting with a smart contract pub enum ContractError { /// Thrown when the ABI decoding fails #[error(transparent)] DecodingError(#[from] AbiError), /// Thrown when detokenizing an argument #[error(transparent)] DetokenizationError(#[from] InvalidOutputType), /// Thrown when a client call fails #[error(transparent)] ClientError(#[from] ClientError), /// Thrown when a provider call fails #[error(transparent)] ProviderError(#[from] ProviderError), /// Thrown during deployment if a constructor argument was passed in the `deploy` /// call but a constructor was not present in the ABI #[error("constructor is not defined in the ABI")] ConstructorError, /// Thrown if a contract address is not found in the deployment transaction's /// receipt #[error("Contract was not deployed")] ContractNotDeployed, } #[derive(Debug, Clone)] #[must_use = "contract calls do nothing unless you `send` or `call` them"] /// Helper for managing a transaction before submitting it to a node pub struct ContractCall
{
/// The raw transaction object
pub tx: TransactionRequest,
/// The ABI of the function being called
pub function: Function,
/// Optional block number to be used when calculating the transaction's gas and nonce
pub block: Option ContractCall {
/// Sets the `from` field in the transaction to the provided value
pub fn from ContractCall
where
S: Signer,
P: JsonRpcClient,
D: Detokenize,
{
/// Returns the underlying transaction's ABI encoded data
pub fn calldata(&self) -> Option