Skip to main content

Base Flash Block

Reading Orderbook and Open Orders Using Flashblock (Pending State)

This guide explains how to read orderbook state and open orders using the latest Flashblock state on Base by using the pending block tag.

This example uses @clober/v2-sdk v1.0.2.

On Base, the pending block tag executes calls against the latest Flashblock state, which represents the sequencer's current in-progress block.


1. Reading the Orderbook State (Flashblock)

You can read the latest orderbook state using blockTag: "pending".

const market = await getMarket({
chainId: chain.id,
token0: USDC,
token1: ETH,
blockTag: 'pending'
})

This ensures the orderbook reflects:

  • The latest finalized block
  • Any transactions already included in the current Flashblock

This is useful for:

  • Accurate arbitrage calculations
  • Pre-trade state estimation
  • Simulation against the next block state

2. Reading Open Orders

You can query open orders using blockTag: "pending":

const openOrders = await getOpenOrders({
chainId: chain.id,
userAddress: walletClient.account.address,
blockTag: 'pending'
})

⚠️ Important Note About Open Orders

getOpenOrders() does not fully reflect Flashblock state.

Open orders are indexed using a Subgraph, so the returned data may lag behind the latest Flashblock state.

This means:

  • Newly opened orders
  • Recently filled orders
  • Recently cancelled orders

may not yet be reflected in the result.


Getting the Exact On-Chain Open Order State

To retrieve the exact on-chain state, you should:

  1. Store the Open Order IDs locally when orders are created.
  2. Query each order directly from the contract using getOnChainOpenOrders.

Example:

const orders = await getOnChainOpenOrders({
chainId: chain.id,
orderIds: [
"12345",
"12346"
],
options: {
blockTag: "pending"
}
})

This approach ensures:

  • Accurate order status
  • Flashblock-aware reads when using blockTag: "pending"
  • No dependency on Subgraph indexing delays

Summary

QueryFlashblock Accurate
getMarket()✅ Yes
getOpenOrders()⚠️ Not guaranteed (Subgraph lag)
getOnChainOpenOrders()✅ Yes

For Flashblock-accurate open order state, store orderIds locally and read them directly using getOnChainOpenOrders.