gasPriceOracle.ts
Overview
The [gasPriceOracle.ts](/projects/291/69091) file exports a constant `GAS_PRICE_ORACLE_ABI` which is an **Application Binary Interface (ABI)** describing the interface of a smart contract related to gas price and fee calculations on a blockchain platform. This ABI is used by Ethereum-compatible clients and libraries (such as ethers.js or web3.js) to interact programmatically with the Gas Price Oracle smart contract deployed on the network.
The ABI includes read-only and state-changing functions that expose gas price data, fee calculations, and configuration parameters relevant to transaction cost estimations. These details are essential for dApps, wallets, or other blockchain tools that need to query or compute gas fees dynamically.
Detailed Explanation
GAS_PRICE_ORACLE_ABI
Type:
readonlyarray of objects describing contract functions.Purpose: Defines the external interface of the Gas Price Oracle smart contract for interaction.
Each element in the array corresponds to a function in the smart contract, described by the following properties:
Property | Description |
|---|---|
`inputs` | Array of input parameters with their types and names. |
`name` | The function's name. |
`outputs` | Array of output parameters with their types and names. |
The mutability of the function ([view](/projects/291/68815), `pure`, `nonpayable`), indicating read or write access. | |
`type` | The type of ABI element, here always `'function'`. |
Functions in the ABI
Function Name | Inputs | Outputs | State Mutability | Description / Usage |
|---|---|---|---|---|
`DECIMALS` | None | `uint256` | Returns the number of decimals used for fee precision. | |
`baseFee` | None | `uint256` | Returns the current base fee for gas. | |
`baseFeeScalar` | None | `uint32` | Returns a scalar value applied to the base fee, possibly for adjustment. | |
`blobBaseFee` | None | `uint256` | Returns the base fee related to "blob" transactions (special transaction types). | |
`blobBaseFeeScalar` | None | `uint32` | Returns a scalar applied to the blob base fee. | |
`decimals` | None | `uint256` | `pure` | Returns the decimals; similar to `DECIMALS` but marked pure (does not read blockchain state). |
`gasPrice` | None | `uint256` | Returns the current gas price used for transactions. | |
`getL1Fee` | `_data: bytes` | `uint256` | Given transaction data, returns the Layer 1 fee associated with it. | |
`getL1GasUsed` | `_data: bytes` | `uint256` | Given transaction data, returns the Layer 1 gas used by the transaction. | |
`isEcotone` | None | `bool` | Returns whether the contract is in "Ecotone" mode (likely a special operational mode). | |
`l1BaseFee` | None | `uint256` | Returns the Layer 1 base fee for transactions. | |
`overhead` | None | `uint256` | Returns an overhead fee value added to gas calculations. | |
`scalar` | None | `uint256` | Returns a scalar multiplier applied to fees. | |
`setEcotone` | None | None | `nonpayable` | State-changing function to enable Ecotone mode (no inputs or outputs). |
`version` | None | `string` | Returns the version string of the Gas Price Oracle contract. |
Usage Examples
1. Querying the Current Gas Price
import { ethers } from 'ethers';
import { GAS_PRICE_ORACLE_ABI } from './gasPriceOracle';
const provider = new ethers.providers.JsonRpcProvider('https://your.rpc.url');
const gasPriceOracleAddress = '0xYourContractAddress';
const gasPriceOracle = new ethers.Contract(gasPriceOracleAddress, GAS_PRICE_ORACLE_ABI, provider);
async function getGasPrice() {
const gasPrice = await gasPriceOracle.gasPrice();
console.log(`Current gas price: ${gasPrice.toString()}`);
}
getGasPrice();
2. Calculating Layer 1 Fee for Transaction Data
const txData = '0x...'; // Transaction data in bytes
async function getL1Fee() {
const fee = await gasPriceOracle.getL1Fee(txData);
console.log(`L1 fee for transaction: ${fee.toString()}`);
}
getL1Fee();
Important Implementation Details
The ABI is marked as
constandas constto ensure type safety and immutability in TypeScript.Functions like
getL1FeeandgetL1GasUsedtake raw transaction data as input, allowing the contract to calculate fees based on actual transaction contents.Scalars and overhead values provide flexibility for dynamic fee adjustment without changing core logic.
The
setEcotonefunction indicates a configurable operational mode, possibly enabling or disabling certain fee calculation behaviors.The distinction between
baseFeeandl1BaseFeesuggests layered fee calculations, possibly differentiating between L1 (main chain) and L2 (layer 2) fees.
Interactions with Other Parts of the System
This ABI is a critical interface for any component that needs to estimate or pay gas fees, including wallets, dApps, relayers, and transaction builders.
It interacts with the blockchain network at the smart contract address level, providing real-time fee data.
Higher-level modules in the project may use this ABI with Ethereum provider libraries to fetch or monitor gas prices and fees.
The ABI supports both read-only operations and a single state-modifying operation (
setEcotone), implying controlled configuration from authorized callers.It likely operates as part of a broader fee management or transaction pricing module within the application’s business logic layer.
Mermaid Class Diagram
The following diagram illustrates the structure of the Gas Price Oracle contract interface represented by this ABI. It shows the available functions, their mutability, and relationships:
classDiagram
class GasPriceOracle {
<<interface>>
+DECIMALS() uint256
+baseFee() uint256
+baseFeeScalar() uint32
+blobBaseFee() uint256
+blobBaseFeeScalar() uint32
+decimals() uint256
+gasPrice() uint256
+getL1Fee(_data: bytes) uint256
+getL1GasUsed(_data: bytes) uint256
+isEcotone() bool
+l1BaseFee() uint256
+overhead() uint256
+scalar() uint256
+setEcotone()
+version() string
}
Summary
gasPriceOracle.ts exports the ABI for a Gas Price Oracle smart contract.
The ABI defines functions to retrieve gas prices, base fees, fee scalars, and to compute Layer 1 fees based on transaction data.
It provides essential data for components needing accurate and dynamic gas fee information.
The file itself contains no logic but serves as an interface contract definition for blockchain interactions.
It integrates with Ethereum provider libraries and other system modules handling transaction creation and fee estimation.
This documentation should enable developers to understand, utilize, and integrate the Gas Price Oracle ABI efficiently within their applications.