getL2Output
Retrieves the first L2 output proposal that occurred after a provided block number. Used for the Withdrawal flow.
Usage
ts
import { optimism } from 'viem/chains'
import { account, publicClientL1 } from './config'
const output = await publicClientL1.getL2Output({
l2BlockNumber: 69420n,
targetChain: optimism,
})
import { optimism } from 'viem/chains'
import { account, publicClientL1 } from './config'
const output = await publicClientL1.getL2Output({
l2BlockNumber: 69420n,
targetChain: optimism,
})
ts
import { createPublicClient, custom, http } from 'viem'
import { mainnet, optimism } from 'viem/chains'
import { publicActionsL1 } from 'viem/op-stack'
export const publicClientL1 = createPublicClient({
chain: mainnet,
transport: http()
}).extend(publicActionsL1())
import { createPublicClient, custom, http } from 'viem'
import { mainnet, optimism } from 'viem/chains'
import { publicActionsL1 } from 'viem/op-stack'
export const publicClientL1 = createPublicClient({
chain: mainnet,
transport: http()
}).extend(publicActionsL1())
Returns
GetL2OutputReturnType
The L2 output proposal.
Parameters
l2BlockNumber
- Type:
bigint
The L2 block number.
ts
const output = await publicClientL1.getL2Output({
l2BlockNumber: 69420n,
targetChain: optimism,
})
const output = await publicClientL1.getL2Output({
l2BlockNumber: 69420n,
targetChain: optimism,
})
targetChain
- Type:
Chain
The L2 chain.
ts
const output = await publicClientL1.getL2Output({
l2BlockNumber,
targetChain: optimism,
})
const output = await publicClientL1.getL2Output({
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.
ts
const output = await publicClientL1.getL2Output({
l2BlockNumber,
l2OutputOracleAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed'
})
const output = await publicClientL1.getL2Output({
l2BlockNumber,
l2OutputOracleAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed'
})