Skip to content

getTimeToFinalize

Returns the time until the withdrawal transaction can be finalized. Used for the Withdrawal flow.

Usage

example.ts
import { optimism } from 'viem/chains'
import { account, publicClientL1, publicClientL2 } from './config'
 
const receipt = await publicClientL2.getTransactionReceipt({
  hash: '0x9a2f4283636ddeb9ac32382961b22c177c9e86dd3b283735c154f897b1a7ff4a',
})
 
const [message] = getWithdrawals(receipt)
 
const { 
  period, 
  seconds, 
  timestamp, 
} = await publicClientL1.getTimeToFinalize({ 
  withdrawalHash: message.withdrawalHash, 
  targetChain: optimism 
}) 

Returns

{ period: number, seconds: number, timestamp: number }

  • period in seconds of the finalization stage (max wait time).
  • seconds until the transaction can be finalized.
  • timestamp of when the transaction can be finalized.

Parameters

targetChain

The L2 chain.

const { seconds } = await publicClientL1.getTimeToFinalize({
  withdrawalHash: '0x...', 
  targetChain: optimism, 
})

withdrawalHash

  • Type: Hash

The withdrawal hash.

const { seconds, timestamp } = await publicClientL1.getTimeToFinalize({ 
  withdrawalHash: '0x...', 
  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.getTimeToFinalize({
  withdrawalHash: '0x...',
  l2OutputOracleAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed'
  portalAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed'
})

portalAddress (optional)

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

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

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

const { seconds } = await publicClientL1.getTimeToFinalize({
  withdrawalHash: '0x...',
  l2OutputOracleAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed',
  portalAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed'
})