Skip to content

Gas prices

The four methods that return one fee figure each, in wei: the node’s suggestions for a gas price and a priority fee, and the base fee and blob base fee of the next block.

Method JSON-RPC Returns Description
gasPrice eth_gasPrice bigint The node’s suggestion for a legacy gas price.
maxPriorityFeePerGas eth_maxPriorityFeePerGas bigint The node’s suggestion for a priority fee.
baseFee eth_baseFee bigint The base fee of the next block.
blobBaseFee eth_blobBaseFee bigint | null The blob base fee of the next block.

None of them takes a parameter, and each returns an Effect<bigint, Method.Error, Transport>. For fees over a range of blocks, use Eth.feeHistory.

Returns the node’s suggestion for a legacy gas price, in wei.

import { Effect } from "effect";
import { Eth } from "@ethect/core/rpc";
const price = Eth.gasPrice().pipe(
Effect.map((wei) => `${wei / 10n ** 9n} gwei`), // "2 gwei"
);
  • JSON-RPC: eth_gasPrice
  • Parameters: none.
  • Returns: bigint, in wei. On a chain with EIP-1559 it covers the base fee and a priority fee.

Returns the node’s suggestion for the priority fee of an EIP-1559 transaction, in wei.

import { Effect } from "effect";
import { Eth } from "@ethect/core/rpc";
const fees = Effect.gen(function* () {
const maxPriorityFeePerGas = yield* Eth.maxPriorityFeePerGas();
const baseFee = yield* Eth.baseFee();
// room for the base fee to double before the transaction is priced out
return { maxPriorityFeePerGas, maxFeePerGas: baseFee * 2n + maxPriorityFeePerGas };
});
  • JSON-RPC: eth_maxPriorityFeePerGas
  • Parameters: none.
  • Returns: bigint, in wei.

Returns the base fee of the next block, in wei.

import { Effect } from "effect";
import { Eth } from "@ethect/core/rpc";
const next = Eth.baseFee().pipe(
Effect.map((wei) => `${wei} wei`), // "1000000000 wei"
);
  • JSON-RPC: eth_baseFee
  • Parameters: none.
  • Returns: bigint, in wei. It is the last entry of baseFeePerGas in Eth.feeHistory.

Returns the blob base fee of the next block, in wei: the price of one unit of blob gas for an EIP-4844 transaction.

import { Effect } from "effect";
import { Eth } from "@ethect/core/rpc";
const blobFee = Eth.blobBaseFee().pipe(
Effect.map((wei) => (wei === null ? null : { maxFeePerBlobGas: wei * 2n })),
);
  • JSON-RPC: eth_blobBaseFee
  • Parameters: none.
  • Returns: bigint | null, in wei. null on a chain without blobs: Arbitrum nitro answers null.
  • A suggestion, not a quote. gasPrice and maxPriorityFeePerGas are the node’s own estimates. Two providers can answer differently for the same block.
  • bigint throughout. Fees are wei and never lose precision. See values on the wire.
  • Together in one request. With batching on, the four calls made with Effect.all and concurrency: "unbounded" leave as one HTTP request.