FlashblocksProviderExt

Trait FlashblocksProviderExt 

Source
pub trait FlashblocksProviderExt<N: Network>:
    Provider<N>
    + Clone
    + Send
    + Sync
    + 'static {
    // Provided methods
    fn watch_flashblocks(&self) -> FlashblockPoller<N, Self>
       where Self: Sized { ... }
    fn flashblock(
        &self,
    ) -> impl Future<Output = TransportResult<Option<N::BlockResponse>>> + Send { ... }
    fn flashblock_balance(
        &self,
        addr: Address,
    ) -> impl Future<Output = TransportResult<U256>> + Send { ... }
    fn flashblock_nonce(
        &self,
        addr: Address,
    ) -> impl Future<Output = TransportResult<u64>> + Send { ... }
    fn flashblock_call(
        &self,
        tx: &N::TransactionRequest,
    ) -> impl Future<Output = TransportResult<Bytes>> + Send { ... }
    fn flashblock_estimate_gas(
        &self,
        tx: &N::TransactionRequest,
    ) -> impl Future<Output = TransportResult<u64>> + Send { ... }
    fn flashblock_logs(
        &self,
        filter: Filter,
    ) -> impl Future<Output = TransportResult<Vec<Log>>> + Send { ... }
    fn flashblock_simulate(
        &self,
        payload: &SimulatePayload,
    ) -> impl Future<Output = TransportResult<Vec<SimulatedBlock<N::BlockResponse>>>> + Send { ... }
    fn wait_for_preconfirmation(
        &self,
        tx_hash: TxHash,
    ) -> impl Future<Output = TransportResult<N::ReceiptResponse>> + Send { ... }
    fn is_preconfirmed(
        &self,
        tx_hash: TxHash,
    ) -> impl Future<Output = TransportResult<bool>> + Send { ... }
}
Expand description

Extension trait for streaming Base flashblocks and querying flashblock state.

Flashblocks provide ~200ms preconfirmations on Base L2. This trait adds methods to stream flashblocks, query pending state, and wait for preconfirmations.

§State Query Methods

All flashblock_* methods query against the pending/flashblock state:

§Preconfirmation Helpers

Provided Methods§

Source

fn watch_flashblocks(&self) -> FlashblockPoller<N, Self>
where Self: Sized,

Watch for flashblock updates via RPC polling.

Polls eth_getBlockByNumber("pending") every 120ms and yields new blocks when the block hash changes.

§Example
use alloy::providers::ProviderBuilder;
use alloy_flashblocks::FlashblocksProviderExt;
use futures_util::StreamExt;

let provider = ProviderBuilder::new()
    .connect_http("https://mainnet-preconf.base.org".parse()?);

let mut stream = provider.watch_flashblocks().into_stream();

while let Some(block) = stream.next().await {
    println!("Block {}: {} txs", block.header.number, block.transactions.len());
}
Source

fn flashblock( &self, ) -> impl Future<Output = TransportResult<Option<N::BlockResponse>>> + Send

Get the current flashblock.

Returns the pending block with transaction hashes. Use the individual transaction hashes to fetch full transaction details if needed.

This is equivalent to eth_getBlockByNumber("pending", false).

§Example
if let Some(block) = provider.flashblock().await? {
    println!("Flashblock {} | {} txs", block.header.number, block.transactions.len());
}
Source

fn flashblock_balance( &self, addr: Address, ) -> impl Future<Output = TransportResult<U256>> + Send

Get balance including preconfirmed transactions.

This is equivalent to eth_getBalance(addr, "pending").

§Example
let balance = provider.flashblock_balance(addr).await?;
println!("Balance (with preconfirmed txs): {} wei", balance);
Source

fn flashblock_nonce( &self, addr: Address, ) -> impl Future<Output = TransportResult<u64>> + Send

Get nonce including preconfirmed transactions.

Use this to determine the nonce for sending your next transaction, accounting for any pending transactions already in the flashblock.

This is equivalent to eth_getTransactionCount(addr, "pending").

§Example
let nonce = provider.flashblock_nonce(addr).await?;
let tx = TransactionRequest::default().nonce(nonce);
Source

fn flashblock_call( &self, tx: &N::TransactionRequest, ) -> impl Future<Output = TransportResult<Bytes>> + Send

Execute a call against flashblock state.

Simulates the transaction against the current pending state, including any preconfirmed transactions.

This is equivalent to eth_call(tx, "pending").

§Example
let result = provider.flashblock_call(&tx).await?;
Source

fn flashblock_estimate_gas( &self, tx: &N::TransactionRequest, ) -> impl Future<Output = TransportResult<u64>> + Send

Estimate gas against flashblock state.

Estimates gas for the transaction against the current pending state.

This is equivalent to eth_estimateGas(tx, "pending").

§Example
let gas = provider.flashblock_estimate_gas(&tx).await?;
let tx = tx.gas_limit(gas);
Source

fn flashblock_logs( &self, filter: Filter, ) -> impl Future<Output = TransportResult<Vec<Log>>> + Send

Get logs up to the current flashblock.

Returns logs matching the filter, including logs from preconfirmed transactions in the current flashblock.

§Example
let filter = Filter::new().address(contract_addr);
let logs = provider.flashblock_logs(filter).await?;
Source

fn flashblock_simulate( &self, payload: &SimulatePayload, ) -> impl Future<Output = TransportResult<Vec<SimulatedBlock<N::BlockResponse>>>> + Send

Simulate multiple transactions against flashblock state.

Executes a multi-call simulation against the current pending state.

This is equivalent to eth_simulateV1 with pending block.

§Example
use alloy::rpc::types::simulate::{SimulatePayload, SimBlock};

let payload = SimulatePayload::default().extend(SimBlock::default());
let results = provider.flashblock_simulate(&payload).await?;
Source

fn wait_for_preconfirmation( &self, tx_hash: TxHash, ) -> impl Future<Output = TransportResult<N::ReceiptResponse>> + Send

Wait for a transaction to be preconfirmed.

Polls for the transaction receipt every 50ms until it appears. This is the Rust equivalent of ethers.js tx.wait(0) for instant preconfirmation feedback on flashblocks-enabled chains.

§Example
let pending = provider.send_transaction(tx).await?;
let receipt = provider.wait_for_preconfirmation(*pending.tx_hash()).await?;
println!("Preconfirmed! Status: {:?}", receipt.status());
Source

fn is_preconfirmed( &self, tx_hash: TxHash, ) -> impl Future<Output = TransportResult<bool>> + Send

Check if a transaction has been preconfirmed.

Returns true if the transaction has a receipt (preconfirmed or finalized).

§Example
if provider.is_preconfirmed(tx_hash).await? {
    println!("Transaction is preconfirmed!");
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<N: Network, P: Provider<N> + Clone + Send + Sync + 'static> FlashblocksProviderExt<N> for P