estimateContractL1Gas
Estimates the L1 data gas to execute an L2 contract write.
Invokes the getL1GasUsed
method on the Gas Price Oracle predeploy contract.
Usage
ts
import { account, publicClient } from './config'
import { wagmiAbi } from './abi'
const l1Fee = await publicClient.estimateContractL1Gas({
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
account,
})
import { account, publicClient } from './config'
import { wagmiAbi } from './abi'
const l1Fee = await publicClient.estimateContractL1Gas({
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
account,
})
ts
export const wagmiAbi = [
...
{
inputs: [],
name: "mint",
outputs: [{ name: "", type: "uint32" }],
stateMutability: "view",
type: "function",
},
...
] as const;
export const wagmiAbi = [
...
{
inputs: [],
name: "mint",
outputs: [{ name: "", type: "uint32" }],
stateMutability: "view",
type: "function",
},
...
] as const;
ts
import { createPublicClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { base } from 'viem/chains'
import { publicActionsL2 } from 'viem/op-stack'
// JSON-RPC Account
export const account = '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'
// Local Account
export const account = privateKeyToAccount(...)
export const publicClient = createPublicClient({
chain: base,
transport: http()
}).extend(publicActionsL2())
import { createPublicClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { base } from 'viem/chains'
import { publicActionsL2 } from 'viem/op-stack'
// JSON-RPC Account
export const account = '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'
// Local Account
export const account = privateKeyToAccount(...)
export const publicClient = createPublicClient({
chain: base,
transport: http()
}).extend(publicActionsL2())
Returns
bigint
The L1 data gas estimate.
Parameters
account
- Type:
Account | Address
The Account to estimate gas from.
Accepts a JSON-RPC Account or Local Account (Private Key, etc).
ts
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
})
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
})
abi
- Type:
Abi
The contract's ABI.
ts
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
})
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
})
address
- Type:
Address
The contract address.
ts
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
})
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
})
functionName
- Type:
string
A function to extract from the ABI.
ts
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
})
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
})
args (optional)
- Type: Inferred from ABI.
Arguments to pass to function call.
ts
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0x1dfe7ca09e99d10835bf73044a23b73fc20623df',
abi: wagmiAbi,
functionName: 'balanceOf',
args: ['0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC'],
})
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0x1dfe7ca09e99d10835bf73044a23b73fc20623df',
abi: wagmiAbi,
functionName: 'balanceOf',
args: ['0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC'],
})
gasPriceOracleAddress (optional)
- Type:
Address
Address of the Gas Price Oracle predeploy contract.
ts
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
gasPriceOracleAddress: '0x420000000000000000000000000000000000000F',
})
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
gasPriceOracleAddress: '0x420000000000000000000000000000000000000F',
})
maxFeePerGas (optional)
- Type:
bigint
Total fee per gas (in wei), inclusive of maxPriorityFeePerGas
.
ts
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
maxFeePerGas: parseGwei('20'),
})
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
maxFeePerGas: parseGwei('20'),
})
maxPriorityFeePerGas (optional)
- Type:
bigint
Max priority fee per gas (in wei).
ts
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
maxPriorityFeePerGas: parseGwei('2'),
})
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
maxPriorityFeePerGas: parseGwei('2'),
})
nonce (optional)
- Type:
number
Unique number identifying this transaction.
ts
const { result } = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
nonce: 69,
})
const { result } = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
nonce: 69,
})
value (optional)
- Type:
bigint
Value (in wei) sent with this transaction.
ts
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
value: parseEther('1')
})
const gas = await publicClient.estimateContractL1Gas({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: wagmiAbi,
functionName: 'mint',
value: parseEther('1')
})