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:
flashblock- Get current flashblock with full txsflashblock_balance- Balance including preconfirmed txsflashblock_nonce- Nonce for sending next txflashblock_call- Simulate against flashblock stateflashblock_estimate_gas- Gas estimate against flashblockflashblock_logs- Logs up to flashblockflashblock_simulate- Multi-call simulation
§Preconfirmation Helpers
wait_for_preconfirmation- Poll until tx is preconfirmedis_preconfirmed- Check if tx has preconfirmed receipt
Provided Methods§
Sourcefn watch_flashblocks(&self) -> FlashblockPoller<N, Self>where
Self: Sized,
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());
}Sourcefn flashblock(
&self,
) -> impl Future<Output = TransportResult<Option<N::BlockResponse>>> + Send
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());
}Sourcefn flashblock_balance(
&self,
addr: Address,
) -> impl Future<Output = TransportResult<U256>> + Send
fn flashblock_balance( &self, addr: Address, ) -> impl Future<Output = TransportResult<U256>> + Send
Sourcefn flashblock_nonce(
&self,
addr: Address,
) -> impl Future<Output = TransportResult<u64>> + Send
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);Sourcefn flashblock_call(
&self,
tx: &N::TransactionRequest,
) -> impl Future<Output = TransportResult<Bytes>> + Send
fn flashblock_call( &self, tx: &N::TransactionRequest, ) -> impl Future<Output = TransportResult<Bytes>> + Send
Sourcefn flashblock_estimate_gas(
&self,
tx: &N::TransactionRequest,
) -> impl Future<Output = TransportResult<u64>> + Send
fn flashblock_estimate_gas( &self, tx: &N::TransactionRequest, ) -> impl Future<Output = TransportResult<u64>> + Send
Sourcefn flashblock_logs(
&self,
filter: Filter,
) -> impl Future<Output = TransportResult<Vec<Log>>> + Send
fn flashblock_logs( &self, filter: Filter, ) -> impl Future<Output = TransportResult<Vec<Log>>> + Send
Sourcefn flashblock_simulate(
&self,
payload: &SimulatePayload,
) -> impl Future<Output = TransportResult<Vec<SimulatedBlock<N::BlockResponse>>>> + Send
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?;Sourcefn wait_for_preconfirmation(
&self,
tx_hash: TxHash,
) -> impl Future<Output = TransportResult<N::ReceiptResponse>> + Send
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());Sourcefn is_preconfirmed(
&self,
tx_hash: TxHash,
) -> impl Future<Output = TransportResult<bool>> + Send
fn is_preconfirmed( &self, tx_hash: TxHash, ) -> impl Future<Output = TransportResult<bool>> + Send
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.