# The eth_ methods (Eth)

The eth namespace. Every eth_ method an execution client serves, as a typed function, with the eth_subscribe kinds under Eth.subscribe.

The `eth_` namespace: what an execution client serves. Each export is one JSON-RPC method as a
typed function, and the `eth_subscribe` kinds are under
[`Eth.subscribe`](https://ethect.dev/rpc/eth/subscribe/).

```ts
import { Effect } from "effect";
import { Eth } from "@ethect/core/rpc";

const head = Effect.gen(function* () {
  const number = yield* Eth.blockNumber();
  const block = yield* Eth.getBlockByNumber(number, false);
  return block?.hash;
});
```

A method takes its JSON-RPC params in order and returns an
[`Effect`](https://ethect.dev/rpc/method/#calling-a-method) of the decoded result. The name is the wire
name without its prefix: `eth_getBalance` is `Eth.getBalance`.

## Node

| Method | JSON-RPC | Returns | Description |
| --- | --- | --- | --- |
| [`chainId`](https://ethect.dev/rpc/eth/chain-id/) | `eth_chainId` | `number` | The chain id of the network. |
| [`blockNumber`](https://ethect.dev/rpc/eth/block-number/) | `eth_blockNumber` | `bigint` | The number of the most recent block. |
| [`syncing`](https://ethect.dev/rpc/eth/syncing/) | `eth_syncing` | `false` or progress | Whether the node is syncing, and how far it is. |
| [`accounts`](https://ethect.dev/rpc/eth/accounts/) | `eth_accounts` | `Address[]` | The accounts the node or wallet holds keys for. |
| [`coinbase`](https://ethect.dev/rpc/eth/node/#coinbase) | `eth_coinbase` | `Address` | The address that receives the node's block rewards. |
| [`protocolVersion`](https://ethect.dev/rpc/eth/node/#protocolversion) | `eth_protocolVersion` | `number` | The version of the `eth` wire protocol. |
| [`config`](https://ethect.dev/rpc/eth/node/#config) | `eth_config` | `ChainConfig` | The fork configuration: current, next and last. |
| [`capabilities`](https://ethect.dev/rpc/eth/node/#capabilities) | `eth_capabilities` | `Capabilities` | What history the node keeps. |

## Blocks

| Method | JSON-RPC | Returns | Description |
| --- | --- | --- | --- |
| [`getBlockByNumber`](https://ethect.dev/rpc/eth/get-block-by-number/) | `eth_getBlockByNumber` | `Block \| null` | A block by number or tag. |
| [`getBlockByHash`](https://ethect.dev/rpc/eth/get-block-by-hash/) | `eth_getBlockByHash` | `Block \| null` | A block by hash. |
| [`getBlockReceipts`](https://ethect.dev/rpc/eth/get-block-receipts/) | `eth_getBlockReceipts` | `Receipt[] \| null` | The receipts of every transaction in a block. |
| [`getHeaderByNumber`](https://ethect.dev/rpc/eth/block-details/#getheaderbynumber) | `eth_getHeaderByNumber` | `Header \| null` | A block header by number or tag. |
| [`getHeaderByHash`](https://ethect.dev/rpc/eth/block-details/#getheaderbyhash) | `eth_getHeaderByHash` | `Header \| null` | A block header by hash. |
| [`getBlockTransactionCountByNumber`](https://ethect.dev/rpc/eth/block-details/#getblocktransactioncountbynumber) | `eth_getBlockTransactionCountByNumber` | `number \| null` | How many transactions a block has, by number or tag. |
| [`getBlockTransactionCountByHash`](https://ethect.dev/rpc/eth/block-details/#getblocktransactioncountbyhash) | `eth_getBlockTransactionCountByHash` | `number \| null` | How many transactions a block has, by hash. |
| [`getUncleCountByBlockNumber`](https://ethect.dev/rpc/eth/block-details/#getunclecountbyblocknumber) | `eth_getUncleCountByBlockNumber` | `number \| null` | How many uncles a block has, by number or tag. |
| [`getUncleCountByBlockHash`](https://ethect.dev/rpc/eth/block-details/#getunclecountbyblockhash) | `eth_getUncleCountByBlockHash` | `number \| null` | How many uncles a block has, by hash. |
| [`getUncleByBlockNumberAndIndex`](https://ethect.dev/rpc/eth/block-details/#getunclebyblocknumberandindex) | `eth_getUncleByBlockNumberAndIndex` | `Block \| null` | An uncle of a block, by block number or tag and position. |
| [`getUncleByBlockHashAndIndex`](https://ethect.dev/rpc/eth/block-details/#getunclebyblockhashandindex) | `eth_getUncleByBlockHashAndIndex` | `Block \| null` | An uncle of a block, by block hash and position. |
| [`getBlockAccessList`](https://ethect.dev/rpc/eth/block-details/#getblockaccesslist) | `eth_getBlockAccessList` | `BlockAccessList \| null` | What a block read and wrote, per account. |

## Transactions

| Method | JSON-RPC | Returns | Description |
| --- | --- | --- | --- |
| [`getTransactionByHash`](https://ethect.dev/rpc/eth/get-transaction-by-hash/) | `eth_getTransactionByHash` | `Transaction \| null` | A transaction by hash, pending or mined. |
| [`getTransactionReceipt`](https://ethect.dev/rpc/eth/get-transaction-receipt/) | `eth_getTransactionReceipt` | `Receipt \| null` | The receipt of a mined transaction. |
| [`getTransactionByBlockNumberAndIndex`](https://ethect.dev/rpc/eth/transaction-lookups/#gettransactionbyblocknumberandindex) | `eth_getTransactionByBlockNumberAndIndex` | `Transaction \| null` | A transaction by its position in a block, by number or tag. |
| [`getTransactionByBlockHashAndIndex`](https://ethect.dev/rpc/eth/transaction-lookups/#gettransactionbyblockhashandindex) | `eth_getTransactionByBlockHashAndIndex` | `Transaction \| null` | A transaction by its position in a block, by block hash. |
| [`getTransactionBySenderAndNonce`](https://ethect.dev/rpc/eth/transaction-lookups/#gettransactionbysenderandnonce) | `eth_getTransactionBySenderAndNonce` | `Transaction \| null` | The transaction an account sent with a given nonce. |
| [`getRawTransactionByHash`](https://ethect.dev/rpc/eth/transaction-lookups/#getrawtransactionbyhash) | `eth_getRawTransactionByHash` | `Hex \| null` | A transaction in its signed, encoded form, by hash. |
| [`getRawTransactionByBlockNumberAndIndex`](https://ethect.dev/rpc/eth/transaction-lookups/#getrawtransactionbyblocknumberandindex) | `eth_getRawTransactionByBlockNumberAndIndex` | `Hex \| null` | The same, by position in a block, by number or tag. |
| [`getRawTransactionByBlockHashAndIndex`](https://ethect.dev/rpc/eth/transaction-lookups/#getrawtransactionbyblockhashandindex) | `eth_getRawTransactionByBlockHashAndIndex` | `Hex \| null` | The same, by position in a block, by block hash. |
| [`pendingTransactions`](https://ethect.dev/rpc/eth/transaction-lookups/#pendingtransactions) | `eth_pendingTransactions` | `Transaction[]` | The transactions in the node's pending pool. |

## State

| Method | JSON-RPC | Returns | Description |
| --- | --- | --- | --- |
| [`getBalance`](https://ethect.dev/rpc/eth/get-balance/) | `eth_getBalance` | `bigint` | The balance of an account, in wei. |
| [`getTransactionCount`](https://ethect.dev/rpc/eth/get-transaction-count/) | `eth_getTransactionCount` | `number` | The number of transactions an account has sent: its next nonce. |
| [`getCode`](https://ethect.dev/rpc/eth/get-code/) | `eth_getCode` | `Hex` | The code of a contract. |
| [`getStorageAt`](https://ethect.dev/rpc/eth/get-storage-at/) | `eth_getStorageAt` | `Hex` | The value of one storage slot of a contract. |
| [`getStorageValues`](https://ethect.dev/rpc/eth/get-storage-values/) | `eth_getStorageValues` | `Record<Address, Hex[]>` | The values of several slots of several contracts. |
| [`getProof`](https://ethect.dev/rpc/eth/get-proof/) | `eth_getProof` | `Proof` | The Merkle proof of an account and of storage slots. |
| [`getAccount`](https://ethect.dev/rpc/eth/get-account/) | `eth_getAccount` | `Account \| null` | An account's nonce, balance, storage root and code hash. |

## Execution

| Method | JSON-RPC | Returns | Description |
| --- | --- | --- | --- |
| [`call`](https://ethect.dev/rpc/eth/call/) | `eth_call` | `Hex` | Runs a call without sending a transaction. |
| [`estimateGas`](https://ethect.dev/rpc/eth/estimate-gas/) | `eth_estimateGas` | `bigint` | The gas a transaction would need. |
| [`createAccessList`](https://ethect.dev/rpc/eth/create-access-list/) | `eth_createAccessList` | `AccessList.Result` | The access list a transaction would use. |
| [`simulateV1`](https://ethect.dev/rpc/eth/simulate-v1/) | `eth_simulateV1` | simulated blocks | Simulates calls in a sequence of blocks. |

## Fees

| Method | JSON-RPC | Returns | Description |
| --- | --- | --- | --- |
| [`feeHistory`](https://ethect.dev/rpc/eth/fee-history/) | `eth_feeHistory` | `FeeHistory` | Base fees, gas usage and priority fees over a range of blocks. |
| [`gasPrice`](https://ethect.dev/rpc/eth/fees/#gasprice) | `eth_gasPrice` | `bigint` | The node's suggestion for a legacy gas price. |
| [`maxPriorityFeePerGas`](https://ethect.dev/rpc/eth/fees/#maxpriorityfeepergas) | `eth_maxPriorityFeePerGas` | `bigint` | The node's suggestion for a priority fee. |
| [`baseFee`](https://ethect.dev/rpc/eth/fees/#basefee) | `eth_baseFee` | `bigint` | The base fee of the next block. |
| [`blobBaseFee`](https://ethect.dev/rpc/eth/fees/#blobbasefee) | `eth_blobBaseFee` | `bigint \| null` | The blob base fee of the next block. |

## Logs and filters

| Method | JSON-RPC | Returns | Description |
| --- | --- | --- | --- |
| [`getLogs`](https://ethect.dev/rpc/eth/get-logs/) | `eth_getLogs` | `Log[]` | The logs matching a filter. |
| [`newFilter`](https://ethect.dev/rpc/eth/filters/#newfilter) | `eth_newFilter` | `Hex` | Installs a log filter on the node. |
| [`newBlockFilter`](https://ethect.dev/rpc/eth/filters/#newblockfilter) | `eth_newBlockFilter` | `Hex` | Installs a filter that collects new block hashes. |
| [`newPendingTransactionFilter`](https://ethect.dev/rpc/eth/filters/#newpendingtransactionfilter) | `eth_newPendingTransactionFilter` | `Hex` | Installs a filter that collects pending transaction hashes. |
| [`getFilterChanges`](https://ethect.dev/rpc/eth/filters/#getfilterchanges) | `eth_getFilterChanges` | `Hash[]` or `Log[]` | What a filter collected since it was last polled. |
| [`getFilterLogs`](https://ethect.dev/rpc/eth/filters/#getfilterlogs) | `eth_getFilterLogs` | `Log[]` | Every log matching a log filter. |
| [`uninstallFilter`](https://ethect.dev/rpc/eth/filters/#uninstallfilter) | `eth_uninstallFilter` | `boolean` | Removes a filter. |

## Sending and signing

| Method | JSON-RPC | Returns | Description |
| --- | --- | --- | --- |
| [`sendTransaction`](https://ethect.dev/rpc/eth/send-transaction/) | `eth_sendTransaction` | `Hash` | Signs and sends a transaction from an account the node or wallet holds. |
| [`sendTransactionSync`](https://ethect.dev/rpc/eth/send-transaction-sync/) | `eth_sendTransactionSync` | `Receipt` | The same, and waits for the receipt. |
| [`sendRawTransaction`](https://ethect.dev/rpc/eth/send-raw-transaction/) | `eth_sendRawTransaction` | `Hash` | Sends a signed, encoded transaction. |
| [`sendRawTransactionSync`](https://ethect.dev/rpc/eth/send-raw-transaction-sync/) | `eth_sendRawTransactionSync` | `Receipt` | The same, and waits for the receipt. |
| [`fillTransaction`](https://ethect.dev/rpc/eth/fill-transaction/) | `eth_fillTransaction` | `{ raw, tx }` | Fills in what a request leaves out, without sending it. |
| [`signTransaction`](https://ethect.dev/rpc/eth/sign-transaction/) | `eth_signTransaction` | `Hex` | Signs a transaction without sending it. |
| [`sign`](https://ethect.dev/rpc/eth/sign/) | `eth_sign` | `Hex` | Signs a message with an account's key. |
| [`signTypedDataV4`](https://ethect.dev/rpc/eth/sign-typed-data-v4/) | `eth_signTypedData_v4` | `Hex` | Signs EIP-712 typed data. |

## Subscriptions

A subscription is a `Stream`, and it needs a transport that can push: WebSocket, IPC or
EIP-1193. See [Subscriptions](https://ethect.dev/rpc/guides/subscriptions/).

| Kind | `eth_subscribe` param | Item | Description |
| --- | --- | --- | --- |
| [`subscribe.newHeads`](https://ethect.dev/rpc/eth/subscribe/new-heads/) | `newHeads` | `Block.Header` | The header of each block added to the chain. |
| [`subscribe.logs`](https://ethect.dev/rpc/eth/subscribe/logs/) | `logs` | `Log` | The logs matching a filter, as blocks are added. |
| [`subscribe.newPendingTransactions`](https://ethect.dev/rpc/eth/subscribe/new-pending-transactions/) | `newPendingTransactions` | `Hash` or `Transaction` | The transactions entering the pending pool. |
| [`subscribe.transactionReceipts`](https://ethect.dev/rpc/eth/subscribe/transaction-receipts/) | `transactionReceipts` | `ReadonlyArray<Receipt>` | The receipts of each block added to the chain. |
| [`subscribe.syncing`](https://ethect.dev/rpc/eth/subscribe/syncing/) | `syncing` | sync status | The sync status, each time it changes. |

## Not defined

These `eth_` methods have no definition in the namespace. Any of them is
[one line to add](https://ethect.dev/rpc/guides/custom-methods/).

| Methods | Why |
| --- | --- |
| `eth_subscribe`, `eth_unsubscribe` | covered by [`Eth.subscribe`](https://ethect.dev/rpc/eth/subscribe/) and the [`Subscriptions`](https://ethect.dev/reference/transport/#subscriptions) service |
| `eth_mining`, `eth_hashrate`, `eth_getWork`, `eth_submitWork`, `eth_submitHashrate` | proof-of-work leftovers |
| `eth_callMany`, `eth_callBundle`, `eth_resend`, `eth_getAccountInfo`, `eth_signRawTransaction`, `eth_sendRawTransactionConditional`, `eth_signTypedData` v1 and v3 | client-specific or superseded |
