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

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.

stateMutability

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`

view

Returns the number of decimals used for fee precision.

`baseFee`

None

`uint256`

view

Returns the current base fee for gas.

`baseFeeScalar`

None

`uint32`

view

Returns a scalar value applied to the base fee, possibly for adjustment.

`blobBaseFee`

None

`uint256`

view

Returns the base fee related to "blob" transactions (special transaction types).

`blobBaseFeeScalar`

None

`uint32`

view

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`

view

Returns the current gas price used for transactions.

`getL1Fee`

`_data: bytes`

`uint256`

view

Given transaction data, returns the Layer 1 fee associated with it.

`getL1GasUsed`

`_data: bytes`

`uint256`

view

Given transaction data, returns the Layer 1 gas used by the transaction.

`isEcotone`

None

`bool`

view

Returns whether the contract is in "Ecotone" mode (likely a special operational mode).

`l1BaseFee`

None

`uint256`

view

Returns the Layer 1 base fee for transactions.

`overhead`

None

`uint256`

view

Returns an overhead fee value added to gas calculations.

`scalar`

None

`uint256`

view

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`

view

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


Interactions with Other Parts of the System


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

This documentation should enable developers to understand, utilize, and integrate the Gas Price Oracle ABI efficiently within their applications.