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