Skip to content

waitToFinalize

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

Internally calls getTimeToFinalize and waits the returned seconds.

Usage

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

Parameters

targetChain

The L2 chain.

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

withdrawalHash

  • Type: Hash

The withdrawal hash.

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