# Types

The wire types: what a node or wallet sends and receives. Each is a module that exports an
Effect `Schema` and the TypeScript type it decodes to. They belong to the
[JSON-RPC layer](https://ethect.dev/rpc/) and are imported from `@ethect/core/rpc`.

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

// Name a type in your own signatures.
const failed = (receipt: Receipt.Receipt): boolean => receipt.status === "reverted";

const check = (hash: `0x${string}`) =>
  Effect.map(Eth.getTransactionReceipt(hash), (receipt) =>
    receipt === null ? undefined : failed(receipt),
  );
```

## Naming

Every module follows the same pattern.

| Export | Is | Example |
| --- | --- | --- |
| `X.schema` | the schema of the module's main shape | `Receipt.schema` |
| `X.X` | the type that schema decodes to | `Receipt.Receipt` |
| `X.nameSchema` | the schema of another shape of the module | `Block.headerSchema`, `Receipt.statusSchema` |
| `X.Name` | the type of that shape | `Block.Header`, `Receipt.Status` |

```ts
import type { Block, Transaction } from "@ethect/core/rpc";
import { Log, Receipt } from "@ethect/core/rpc";

type Header = Block.Header;
type Eip1559 = Transaction.Eip1559;

Receipt.schema; // decodes a receipt
Log.schema; // decodes a log
```

## Conventions

The same rules hold for every type. [Values on the wire](https://ethect.dev/rpc/guides/values/) explains them.

| On the wire | In code |
| --- | --- |
| a large quantity: wei, gas, a block number, a timestamp | `bigint` |
| a small quantity: a chain id, a nonce, an index, a count | `number` |
| an address | [`Address.Address`](https://ethect.dev/reference/primitives/address/), lowercase, and sent in its EIP-55 form |
| a hash, bytes | `` `0x${string}` `` |
| a type or status code | a name: `"eip1559"`, `"success"` |
| a field a node may omit or send as `null` | an optional field |
| a field that is `null` in a known situation | a field typed `\| null` |
| a field the schema does not know | dropped |

## Chain

| Type | Describes |
| --- | --- |
| [`Block`](https://ethect.dev/rpc/types/block/) | a block: its header, with transaction hashes, or with transactions in full |
| [`BlockId`](https://ethect.dev/rpc/types/block-id/) | how a call names a block: a number, a tag, or a hash object |
| [`Transaction`](https://ethect.dev/rpc/types/transaction/) | a signed transaction as a node returns it, one shape per type |
| [`TransactionRequest`](https://ethect.dev/rpc/types/transaction-request/) | a transaction as a caller describes it |
| [`Receipt`](https://ethect.dev/rpc/types/receipt/) | what executing a transaction did |
| [`Log`](https://ethect.dev/rpc/types/log/) | an event log |
| [`Filter`](https://ethect.dev/rpc/types/filter/) | which logs to match |
| [`FeeHistory`](https://ethect.dev/rpc/types/fee-history/) | what `eth_feeHistory` returns |
| [`AccessList`](https://ethect.dev/rpc/types/access-list/) | the addresses and slots a transaction declares it touches |
| [`Authorization`](https://ethect.dev/rpc/types/authorization/) | an EIP-7702 authorization |
| [`Withdrawal`](https://ethect.dev/rpc/types/withdrawal/) | a validator withdrawal |
| [`Proof`](https://ethect.dev/rpc/types/proof/) | a Merkle proof of an account and its storage |
| [`Account`](https://ethect.dev/rpc/types/account/) | an account's state |
| [`SyncStatus`](https://ethect.dev/rpc/types/sync-status/) | whether a node is syncing, and how far it is |
| [`ChainConfig`](https://ethect.dev/rpc/types/chain-config/) | the fork configuration a node runs |
| [`Capabilities`](https://ethect.dev/rpc/types/capabilities/) | what history a node keeps |
| [`BlockAccessList`](https://ethect.dev/rpc/types/block-access-list/) | what a block read and wrote, per account |

## Execution

| Type | Describes |
| --- | --- |
| [`StateOverride`](https://ethect.dev/rpc/types/state-override/) | state a call pretends is on chain |
| [`BlockOverride`](https://ethect.dev/rpc/types/block-override/) | header fields a call pretends its block has |
| [`Simulate`](https://ethect.dev/rpc/types/simulate/) | the payload and the result of `eth_simulateV1` |

## Tracing

| Type | Describes |
| --- | --- |
| [`Trace`](https://ethect.dev/rpc/types/trace/) | the tracers a `debug_trace*` call can run |
| [`StructLog`](https://ethect.dev/rpc/types/struct-log/) | the struct logger: one log per opcode |
| [`CallFrame`](https://ethect.dev/rpc/types/call-frame/) | the `callTracer`: the tree of calls |
| [`Prestate`](https://ethect.dev/rpc/types/prestate/) | the `prestateTracer`: the accounts touched |

## Test node

| Type | Describes |
| --- | --- |
| [`MineOptions`](https://ethect.dev/rpc/types/mine-options/) | what to mine |
| [`MinedBlock`](https://ethect.dev/rpc/types/mined-block/) | a mined block with what its transactions did |
| [`NodeInfo`](https://ethect.dev/rpc/types/node-info/) | how a test node is set up |
| [`NodeMetadata`](https://ethect.dev/rpc/types/node-metadata/) | what identifies a test node |
| [`TransactionPool`](https://ethect.dev/rpc/types/transaction-pool/) | the node's transaction pool |

## Wallet

| Type | Describes |
| --- | --- |
| [`WalletChain`](https://ethect.dev/rpc/types/wallet-chain/) | a chain as an app describes it to a wallet |
| [`WatchAsset`](https://ethect.dev/rpc/types/watch-asset/) | a token an app suggests a wallet track |
| [`Permission`](https://ethect.dev/rpc/types/permission/) | a wallet permission |
| [`PermissionGrant`](https://ethect.dev/rpc/types/permission-grant/) | permissions for a session key or account |
| [`Calls`](https://ethect.dev/rpc/types/calls/) | a batch of calls for a wallet to send |
| [`CallsStatus`](https://ethect.dev/rpc/types/calls-status/) | the status of a batch |
| [`WalletCapabilities`](https://ethect.dev/rpc/types/wallet-capabilities/) | the optional features of a wallet |
| [`WalletAsset`](https://ethect.dev/rpc/types/wallet-asset/) | the assets a wallet holds for an account |
| [`SubAccount`](https://ethect.dev/rpc/types/sub-account/) | an account owned by a wallet's main account |

## Using a schema directly

A schema decodes data that did not come through a method, and encodes native values back to
the wire.

```ts
import { Effect, Schema } from "effect";
import { Block } from "@ethect/core/rpc";

const decodeHeader = (json: unknown) =>
  Schema.decodeUnknownEffect(Block.headerSchema)(json);
// Effect<Block.Header, Schema.SchemaError>

const encodeHeader = Schema.encodeEffect(Block.headerSchema);
// (header: Block.Header) => Effect<the wire object, Schema.SchemaError>
```

To add the fields of your chain to a type, see
[A wider result](https://ethect.dev/rpc/guides/custom-methods/#a-wider-result).
