estimateFinalizeWithdrawalGas
Estimates gas required to finalize a withdrawal that occurred on an L2.
Usage
import { optimism } from 'viem/chains'
import { account, publicClientL1 } from './config'
const gas = await publicClientL1.estimateFinalizeWithdrawalGas({
account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
targetChain: optimism,
withdrawal: { ... },
})
Returns
bigint
The estimated gas.
Parameters
account
- Type:
Account | Address
The Account to send the transaction from.
Accepts a JSON-RPC Account or Local Account (Private Key, etc).
const hash = await client.estimateFinalizeWithdrawalGas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
withdrawal: { /* ... */ },
targetChain: optimism,
})
chain (optional)
- Type:
Chain
- Default:
client.chain
The L1 chain. If there is a mismatch between the wallet's current chain & this chain, an error will be thrown.
import { mainnet } from 'viem/chains'
const hash = await client.estimateFinalizeWithdrawalGas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
chain: mainnet,
withdrawal: { /* ... */ },
targetChain: optimism,
})
gas (optional)
- Type:
bigint
Gas limit for transaction execution on the L1.
const hash = await client.estimateFinalizeWithdrawalGas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
l2OutputIndex: 4529n,
gas: 420_000n,
outputRootProof: { /* ... */ },
withdrawalProof: [ /* ... */ ],
withdrawal: { /* ... */ },
targetChain: optimism,
})
maxFeePerGas (optional)
- Type:
bigint
Total fee per gas (in wei), inclusive of maxPriorityFeePerGas
.
const hash = await client.estimateFinalizeWithdrawalGas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
l2OutputIndex: 4529n,
maxFeePerGas: parseGwei('20'),
outputRootProof: { /* ... */ },
withdrawalProof: [ /* ... */ ],
withdrawal: { /* ... */ },
targetChain: optimism,
})
maxPriorityFeePerGas (optional)
- Type:
bigint
Max priority fee per gas (in wei). Only applies to EIP-1559 Transactions
const hash = await client.estimateFinalizeWithdrawalGas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
l2OutputIndex: 4529n,
maxFeePerGas: parseGwei('20'),
maxPriorityFeePerGas: parseGwei('2'),
outputRootProof: { /* ... */ },
withdrawalProof: [ /* ... */ ],
withdrawal: { /* ... */ },
targetChain: optimism,
})
nonce (optional)
- Type:
number
Unique number identifying this transaction.
const hash = await client.estimateFinalizeWithdrawalGas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
withdrawal: { /* ... */ },
nonce: 69,
targetChain: optimism,
})
portalAddress (optional)
- Type:
Address
- Default:
targetChain.contracts.portal[chainId].address
The address of the Optimism Portal contract. Defaults to the Optimism Portal contract specified on the targetChain
.
If a portalAddress
is provided, the targetChain
parameter becomes optional.
const hash = await client.estimateFinalizeWithdrawalGas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
l2OutputIndex: 4529n,
outputRootProof: { /* ... */ },
portalAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed'
targetChain: optimism,
withdrawalProof: [ /* ... */ ],
withdrawal: { /* ... */ },
})
targetChain
- Type:
Chain
The L2 chain to execute the transaction on.
import { mainnet } from 'viem/chains'
const hash = await client.estimateFinalizeWithdrawalGas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
withdrawal: { /* ... */ },
targetChain: optimism,
})
withdrawal
- Type:
bigint
The withdrawal.
const hash = await client.estimateFinalizeWithdrawalGas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
l2OutputIndex: 4529n,
gas: 420_000n,
outputRootProof: { /* ... */ },
withdrawalProof: [ /* ... */ ],
withdrawal: { /* ... */ },
targetChain: optimism,
})