estimateInitiateERC20WithdrawalFee
Estimates the total fee (L1 data fee + L2 execution fee + operator fee) required to initiate an ERC20 withdrawal on the L2. The fee is computed by Mantle's eth_estimateTotalFee RPC method against the L2 bridge call.
Usage
example.ts
import { parseEther } from 'viem'
import { account, publicClientL2 } from './config'
const fee = await publicClientL2.estimateInitiateERC20WithdrawalFee({
account,
request: {
amount: parseEther('1'),
l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
},
})Returns
bigint
The total fee (in wei) to initiate the withdrawal on the L2.
Parameters
account
- Type:
Account | Address
The Account to estimate the fee from.
Accepts a JSON-RPC Account or Local Account (Private Key, etc).
const fee = await publicClientL2.estimateInitiateERC20WithdrawalFee({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
request: {
amount: parseEther('1'),
l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
},
})request.amount
- Type:
bigint
The amount of the ERC20 token (in wei) to withdraw.
const fee = await publicClientL2.estimateInitiateERC20WithdrawalFee({
account,
request: {
amount: parseEther('1'),
l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
},
})request.l2Token
- Type:
Address
The L2 address of the ERC20 token to withdraw.
const fee = await publicClientL2.estimateInitiateERC20WithdrawalFee({
account,
request: {
amount: parseEther('1'),
l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
},
})request.to (optional)
- Type:
Address - Default: the
accountaddress.
The L1 recipient of the withdrawn tokens.
const fee = await publicClientL2.estimateInitiateERC20WithdrawalFee({
account,
request: {
amount: parseEther('1'),
l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
},
})gas (optional)
- Type:
bigint
Gas limit for transaction execution on the L2.
const fee = await publicClientL2.estimateInitiateERC20WithdrawalFee({
account,
request: {
amount: parseEther('1'),
l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
},
gas: 21000n,
})maxFeePerGas (optional)
- Type:
bigint
Total fee per gas (in wei), inclusive of maxPriorityFeePerGas.
const fee = await publicClientL2.estimateInitiateERC20WithdrawalFee({
account,
request: {
amount: parseEther('1'),
l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
},
maxFeePerGas: parseGwei('20'),
})maxPriorityFeePerGas (optional)
- Type:
bigint
Max priority fee per gas (in wei). Only applies to EIP-1559 Transactions.
const fee = await publicClientL2.estimateInitiateERC20WithdrawalFee({
account,
request: {
amount: parseEther('1'),
l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
},
maxFeePerGas: parseGwei('20'),
maxPriorityFeePerGas: parseGwei('2'),
})nonce (optional)
- Type:
number
Unique number identifying this transaction.
const fee = await publicClientL2.estimateInitiateERC20WithdrawalFee({
account,
request: {
amount: parseEther('1'),
l2Token: '0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828',
},
nonce: 69,
})