estimateTotalFee
Estimates the total fee (L1 data fee + L2 execution fee + operator fee) required to execute a transaction on the L2, as computed by Mantle's eth_estimateTotalFee RPC method.
Usage
example.ts
import { parseEther } from 'viem'
import { account, publicClientL2 } from './config'
const fee = await publicClientL2.estimateTotalFee({
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1'),
})Returns
bigint
The total fee (in wei) to execute the transaction on the L2.
Parameters
account (optional)
- Type:
Account | Address - Default:
client.account
The Account to estimate the fee from. The node accepts a request without from, so this is optional.
Accepts a JSON-RPC Account or Local Account (Private Key, etc).
const fee = await publicClientL2.estimateTotalFee({
account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1'),
})to (optional)
- Type:
Address
The transaction recipient.
const fee = await publicClientL2.estimateTotalFee({
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1'),
})value (optional)
- Type:
bigint
Value (in wei) sent with this transaction.
const fee = await publicClientL2.estimateTotalFee({
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1'),
})data (optional)
- Type:
0x${string}
Contract code or a hashed method call with encoded args.
const fee = await publicClientL2.estimateTotalFee({
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
data: '0xdeadbeef',
})gas (optional)
- Type:
bigint
Gas limit for transaction execution on the L2.
const fee = await publicClientL2.estimateTotalFee({
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1'),
gas: 21000n,
})maxFeePerGas (optional)
- Type:
bigint
Total fee per gas (in wei), inclusive of maxPriorityFeePerGas.
const fee = await publicClientL2.estimateTotalFee({
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1'),
maxFeePerGas: parseGwei('20'),
})maxPriorityFeePerGas (optional)
- Type:
bigint
Max priority fee per gas (in wei). Only applies to EIP-1559 Transactions.
const fee = await publicClientL2.estimateTotalFee({
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1'),
maxFeePerGas: parseGwei('20'),
maxPriorityFeePerGas: parseGwei('2'),
})nonce (optional)
- Type:
number
Unique number identifying this transaction.
const fee = await publicClientL2.estimateTotalFee({
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1'),
nonce: 69,
})