getTimeToNextGame
Returns the time until the next L2 dispute game (after the provided block number) is submitted. Used for the Withdrawal flow.
Usage
example.ts
import { optimism } from 'viem/chains'
import { account, publicClientL1, publicClientL2 } from './config'
const l2BlockNumber = publicClientL2.getBlockNumber()
const {
interval,
seconds,
timestamp
} = await publicClientL1.getTimeToNextGame({
l2BlockNumber,
targetChain: publicClientL2.chain,
})
Returns
{ interval: number, seconds: number, timestamp: number }
- Estimated
interval
between dispute games – the max time to wait for transaction to be proved. - Estimated
seconds
until the next dispute game is submitted. - Estimated
timestamp
of the next dispute game.
Parameters
l2BlockNumber
- Type:
bigint
The latest L2 block number.
const l2BlockNumber = publicClientL2.getBlockNumber()
const { seconds } = await publicClientL1.getTimeToNextGame({
l2BlockNumber,
targetChain: optimism,
})
targetChain
- Type:
Chain
The L2 chain.
const { seconds } = await publicClientL1.getTimeToNextGame({
l2BlockNumber,
targetChain: optimism,
})
disputeGameFactoryAddress (optional)
- Type:
Address
- Default:
targetChain.contracts.disputeGameFactory[chainId].address
The address of the DisputeGameFactory
contract. Defaults to the DisputeGameFactory
contract specified on the targetChain
.
If a disputeGameFactoryAddress
is provided, the targetChain
parameter becomes optional.
const { seconds } = await publicClientL1.getTimeToNextGame({
l2BlockNumber,
disputeGameFactoryAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed'
})
intervalBuffer (optional)
- Type:
number
- Default:
1.1
The buffer to account for discrepancies between non-deterministic time intervals.
const { seconds } = await publicClientL1.getTimeToNextGame({
intervalBuffer: 1.2,
l2BlockNumber,
targetChain: optimism,
})
portalAddress (optional)
- Type:
Address
- Default:
targetChain.contracts.portal[chainId].address
The address of the Portal
contract. Defaults to the Portal
contract specified on the targetChain
.
If a portalAddress
is provided, the targetChain
parameter becomes optional.
const { seconds } = await publicClientL1.getTimeToNextGame({
l2BlockNumber,
portalAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed'
})