# 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`](#gasprice) | `eth_gasPrice` | `bigint` | The node's suggestion for a legacy gas price. |
| [`maxPriorityFeePerGas`](#maxpriorityfeepergas) | `eth_maxPriorityFeePerGas` | `bigint` | The node's suggestion for a priority fee. |
| [`baseFee`](#basefee) | `eth_baseFee` | `bigint` | The base fee of the next block. |
| [`blobBaseFee`](#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>`](https://ethect.dev/rpc/method/#calling-a-method). For fees over
a range of blocks, use [`Eth.feeHistory`](https://ethect.dev/rpc/eth/fee-history/).

## gasPrice

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

```ts
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.

## maxPriorityFeePerGas

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

```ts
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.

## baseFee

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

```ts
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`](https://ethect.dev/rpc/eth/fee-history/).

## blobBaseFee

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

```ts
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`.

## Behavior

- **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](https://ethect.dev/rpc/guides/values/).
- **Together in one request.** With [batching](https://ethect.dev/rpc/guides/batching/) on, the four calls made with
  `Effect.all` and `concurrency: "unbounded"` leave as one HTTP request.
