Skip to content

getTimeToNextL2Output

Returns the time until the next L2 output (after a provided block number) is submitted. Used for the Withdrawal flow.

Usage

import { optimism } from 'viem/chains'
import { account, publicClientL1, publicClientL2 } from './config'
 
const l2BlockNumber = publicClientL2.getBlockNumber()
 
const { 
  interval, 
  seconds, 
  timestamp
} = await publicClientL1.getTimeToNextL2Output({ 
  l2BlockNumber, 
  targetChain: publicClientL2.chain, 
}) 

Returns

{ interval: number, seconds: number, timestamp: number }

  • interval between L2 outputs – the max time to wait for transaction to be proved.
  • Estimated seconds until the next L2 Output is submitted.
  • Estimated timestamp of the next L2 Output.

Parameters

l2BlockNumber

  • Type: bigint

The latest L2 block number.

const l2BlockNumber = publicClientL2.getBlockNumber() 
const { seconds } = await publicClientL1.getTimeToNextL2Output({ 
  l2BlockNumber, 
  targetChain: optimism, 
}) 

targetChain

The L2 chain.

const { seconds } = await publicClientL1.getTimeToNextL2Output({
  l2BlockNumber,
  targetChain: optimism, 
})

intervalBuffer (optional)

  • Type: number
  • Default: 1.1

The buffer to account for discrepencies between non-deterministic time intervals.

const { seconds } = await publicClientL1.getTimeToNextL2Output({ 
  intervalBuffer: 1.2, 
  l2BlockNumber,
  targetChain: optimism, 
}) 

l2OutputOracleAddress (optional)

  • Type: Address
  • Default: targetChain.contracts.l2OutputOracle[chainId].address

The address of the L2 Output Oracle contract. Defaults to the L2 Output Oracle contract specified on the targetChain.

If a l2OutputOracleAddress is provided, the targetChain parameter becomes optional.

const { seconds } = await publicClientL1.getTimeToNextL2Output({
  l2BlockNumber,
  l2OutputOracleAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed'
})