alloy_provider

Struct PendingTransactionBuilder

source
pub struct PendingTransactionBuilder<T, N: Network> { /* private fields */ }
Expand description

A builder for configuring a pending transaction watcher.

§Examples

Send and wait for a transaction to be confirmed 2 times, with a timeout of 60 seconds:

// Send a transaction, and configure the pending transaction.
let builder = provider.send_transaction(tx)
    .await?
    .with_required_confirmations(2)
    .with_timeout(Some(std::time::Duration::from_secs(60)));
// Register the pending transaction with the provider.
let pending_tx = builder.register().await?;
// Wait for the transaction to be confirmed 2 times.
let tx_hash = pending_tx.await?;

This can also be more concisely written using watch:

let tx_hash = provider.send_transaction(tx)
    .await?
    .with_required_confirmations(2)
    .with_timeout(Some(std::time::Duration::from_secs(60)))
    .watch()
    .await?;

Implementations§

source§

impl<T: Transport + Clone, N: Network> PendingTransactionBuilder<T, N>

source

pub const fn new(provider: RootProvider<T, N>, tx_hash: TxHash) -> Self

Creates a new pending transaction builder.

source

pub const fn from_config( provider: RootProvider<T, N>, config: PendingTransactionConfig, ) -> Self

Creates a new pending transaction builder from the given configuration.

source

pub const fn inner(&self) -> &PendingTransactionConfig

Returns the inner configuration.

source

pub fn into_inner(self) -> PendingTransactionConfig

Consumes this builder, returning the inner configuration.

source

pub const fn provider(&self) -> &RootProvider<T, N>

Returns the provider.

source

pub fn split(self) -> (RootProvider<T, N>, PendingTransactionConfig)

Consumes this builder, returning the provider and the configuration.

source

pub const fn tx_hash(&self) -> &TxHash

Returns the transaction hash.

source

pub fn set_tx_hash(&mut self, tx_hash: TxHash)

Sets the transaction hash.

source

pub const fn with_tx_hash(self, tx_hash: TxHash) -> Self

Sets the transaction hash.

source

pub const fn required_confirmations(&self) -> u64

Returns the number of confirmations to wait for.

source

pub fn set_required_confirmations(&mut self, confirmations: u64)

Sets the number of confirmations to wait for.

source

pub const fn with_required_confirmations(self, confirmations: u64) -> Self

Sets the number of confirmations to wait for.

source

pub const fn timeout(&self) -> Option<Duration>

Returns the timeout.

source

pub fn set_timeout(&mut self, timeout: Option<Duration>)

Sets the timeout.

source

pub const fn with_timeout(self, timeout: Option<Duration>) -> Self

Sets the timeout.

source

pub async fn register( self, ) -> Result<PendingTransaction, PendingTransactionError>

Registers the watching configuration with the provider.

This does not wait for the transaction to be confirmed, but returns a PendingTransaction that can be awaited at a later moment.

See:

  • watch for watching the transaction without fetching the receipt.
  • get_receipt for fetching the receipt after the transaction has been confirmed.
source

pub async fn watch(self) -> Result<TxHash, PendingTransactionError>

Waits for the transaction to confirm with the given number of confirmations.

See:

  • register: for registering the transaction without waiting for it to be confirmed.
  • get_receipt for fetching the receipt after the transaction has been confirmed.
source

pub async fn get_receipt( self, ) -> Result<N::ReceiptResponse, PendingTransactionError>

Waits for the transaction to confirm with the given number of confirmations, and then fetches its receipt.

Note that this method will call eth_getTransactionReceipt on the root provider, and not on a specific network provider. This means that any overrides or customizations made to the network provider will not be used.

See:

  • register: for registering the transaction without waiting for it to be confirmed.
  • watch for watching the transaction without fetching the receipt.

Trait Implementations§

source§

impl<T: Debug, N: Debug + Network> Debug for PendingTransactionBuilder<T, N>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, N> Freeze for PendingTransactionBuilder<T, N>

§

impl<T, N> RefUnwindSafe for PendingTransactionBuilder<T, N>

§

impl<T, N> Send for PendingTransactionBuilder<T, N>
where T: Sync + Send,

§

impl<T, N> Sync for PendingTransactionBuilder<T, N>
where T: Sync + Send,

§

impl<T, N> Unpin for PendingTransactionBuilder<T, N>

§

impl<T, N> UnwindSafe for PendingTransactionBuilder<T, N>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more