estimateContractTotalFee
Estimates the total (L1 data + L2) fee to execute an L2 contract write.
Invokes the getL1Fee
method on the Gas Price Oracle predeploy contract.
Usage
example.ts
import { account, publicClient } from './config'
import { wagmiAbi } from './abi'
const fee = await publicClient.estimateContractTotalFee({
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
account,
})
Returns
bigint
The total (L1 + L2) fee estimate (in wei).
Parameters
account
- Type:
Account | Address
The Account to estimate fee from.
Accepts a JSON-RPC Account or Local Account (Private Key, etc).
const fee = await publicClient.estimateContractTotalFee({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
})
abi
- Type:
Abi
The contract's ABI.
const fee = await publicClient.estimateContractTotalFee({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
})
address
- Type:
Address
The contract address.
const fee = await publicClient.estimateContractTotalFee({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
})
functionName
- Type:
string
A function to extract from the ABI.
const fee = await publicClient.estimateContractTotalFee({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
})
args (optional)
- Type: Inferred from ABI.
Arguments to pass to function call.
const fee = await publicClient.estimateContractTotalFee({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0x1dfe7ca09e99d10835bf73044a23b73fc20623df',
abi: wagmiAbi,
functionName: 'balanceOf',
args: ['0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC'],
})
gasPriceOracleAddress (optional)
- Type:
Address
Address of the Gas Price Oracle predeploy contract.
const fee = await publicClient.estimateContractTotalFee({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
gasPriceOracleAddress: '0x420000000000000000000000000000000000000F',
})
maxFeePerGas (optional)
- Type:
bigint
Total fee per gas (in wei), inclusive of maxPriorityFeePerGas
.
const fee = await publicClient.estimateContractTotalFee({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
maxFeePerGas: parseGwei('20'),
})
maxPriorityFeePerGas (optional)
- Type:
bigint
Max priority fee per gas (in wei).
const fee = await publicClient.estimateContractTotalFee({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
maxPriorityFeePerGas: parseGwei('2'),
})
nonce (optional)
- Type:
number
Unique number identifying this transaction.
const fee = await publicClient.estimateContractTotalFee({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
nonce: 69,
})
value (optional)
- Type:
bigint
Value (in wei) sent with this transaction.
const fee = await publicClient.estimateContractTotalFee({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
value: parseEther('1')
})