# Installation

Install `@ethect/core` together with `effect`, its one peer dependency.

**npm**

```sh
npm install @ethect/core@alpha effect
```

**pnpm**

```sh
pnpm add @ethect/core@alpha effect
```

**bun**

```sh
bun add @ethect/core@alpha effect
```

**yarn**

```sh
yarn add @ethect/core@alpha effect
```

## Requirements

| Requirement | Version | Notes |
| --- | --- | --- |
| `effect` | `^4.1.7` | Required peer dependency. ethect is built on Effect v4. |
| Dependencies | | Two, installed with the package: `@noble/curves` and `@noble/hashes`, for signatures and hashes. |
| TypeScript | | Types resolve under `moduleResolution` `nodenext` and `bundler`. Set `"strict": true`. |
| Type checker | | The package and consumer fixtures are checked with TypeScript 7, `bun check` and tsrs. |
| Module format | ESM | No CommonJS build: use `import`. |
| Runtime | | The library uses no Node API. It is tested on Node. |

## What each transport needs

A transport takes its network access from a layer you provide, which is how one library runs
on every platform.

| Transport | Needs | Provide | From |
| --- | --- | --- | --- |
| [`Transport.http`](https://ethect.dev/reference/transport/http/) | an `HttpClient` | `FetchHttpClient.layer` | `effect/http` |
| [`Transport.webSocket`](https://ethect.dev/reference/transport/web-socket/) | a `WebSocketConstructor` | `Socket.layerWebSocketConstructorGlobal` | `effect/socket` |
| [`Transport.ipc`](https://ethect.dev/reference/transport/ipc/) | a `Socket` | `NodeSocket.layerNet({ path })` | `@effect/platform-node` |
| [`Transport.eip1193`](https://ethect.dev/reference/transport/eip1193/) | nothing | | |

The first two ship with `effect` and use the global `fetch` and `WebSocket`. IPC needs the
platform package:

```sh
npm install @effect/platform-node
```

`@effect/platform-node` also has an HTTP client built on undici (`NodeHttpClient.layerUndici`)
and a WebSocket constructor built on the `ws` package (`NodeWS.layerWebSocketConstructor`), for
when you want them instead of the globals.

## Verify the setup

```ts
import { Effect } from "effect";
import { Abi, Address } from "@ethect/core";

const ACCOUNT = Address.makeUnsafe("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");

// `abi.encode(address)`, as an effect
console.log(await Effect.runPromise(Abi.encode(Abi.address, ACCOUNT)));
// 0x000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa96045
```

This runs without a network. If it typechecks and prints the address as 32 bytes, continue
with the [quick start](https://ethect.dev/getting-started/quick-start/).

## Entry points

The package has four entry points, one per part of the library.

| Import from | Holds | Documented under |
| --- | --- | --- |
| `@ethect/core` | contracts, calls, events, transactions and wallets, with `Transport`, `Eip1193`, the errors, `Address`, `Hex`, `Hash`, `Quantity` | Reference, from [`Abi`](https://ethect.dev/reference/abi/) to [`Transport`](https://ethect.dev/reference/transport/) |
| `@ethect/core/ens` | `Ens` | [Ens](https://ethect.dev/reference/ens/) |
| `@ethect/core/rpc` | the low-level layer: the eight namespaces, the wire types, `Method`, `Subscription` | [JSON-RPC](https://ethect.dev/rpc/) |
| `@ethect/core/testing` | `AnvilNode`, `MockProvider`, `TestWallet`, `TestSigner` | [Testing](https://ethect.dev/reference/testing/) |

```ts
import { Address, Transport } from "@ethect/core";
import { type Block, Eth } from "@ethect/core/rpc";
import { AnvilNode, MockProvider } from "@ethect/core/testing";
```

- **Each module is a namespace.** `Eth.getBalance`, `Address.make`, `Transport.http`.
- **The root entry point holds the main APIs, and what every program uses.** The low-level
  calls have their own, `@ethect/core/rpc`.

### Module paths

A module that exports types also has a path of its own, the entry point it belongs to
followed by its name: `@ethect/core/Address`, `@ethect/core/rpc/Log`. TypeScript names a type
through that path in a declaration it emits, and you can import the module from it.

```ts
// balances.d.ts, emitted for `export const balance = Erc20.at(USDC).balanceOf(user)`
export declare const balance: import("@ethect/core/Call").View<bigint, never>;
```

This is what lets a program that emits declarations, a library or a package of a monorepo
built with `composite`, export a call or a contract from a file that imports neither `Call`
nor `Address`.

| Path | Modules |
| --- | --- |
| `@ethect/core/<Module>` | `Address`, `Hash`, `Hex`, `Quantity`, `Abi`, `Fn`, `Err`, `Ev`, `Revert`, `Contract`, `Call`, `Tx`, `Signer`, `Wallets`, `Connection`, `Block`, `Chain`, `Eip1193`, `Transport`, `AbiError`, `CodecError`, `RpcError`, `TransportError` |
| `@ethect/core/ens/<Module>` | `Ens` |
| `@ethect/core/rpc/<Module>` | `Method`, `Subscription`, `Debug`, and the wire types: `BlockId`, `AccessList`, `Account`, `Authorization`, `Block`, `BlockAccessList`, `FeeHistory`, `Filter`, `Log`, `Proof`, `Receipt`, `Transaction`, `Withdrawal`, `BlockOverride`, `Simulate`, `StateOverride`, `TransactionRequest`, `CallFrame`, `Prestate`, `StructLog`, `Trace`, `Capabilities`, `ChainConfig`, `MineOptions`, `MinedBlock`, `NodeInfo`, `NodeMetadata`, `SyncStatus`, `TransactionPool`, `Calls`, `CallsStatus`, `Permission`, `PermissionGrant`, `SubAccount`, `WalletAsset`, `WalletCapabilities`, `WalletChain`, `WatchAsset` |
| `@ethect/core/testing/<Module>` | `AnvilNode`, `MockProvider`, `TestSigner`, `TestWallet` |

- **The examples of these docs import from the four entry points.** A path gives the same
  module: `import * as Abi from "@ethect/core/Abi"` is the `Abi` of `@ethect/core`.
- **A namespace of methods alone has no path.** `Eth`, `Net`, `Web3`, `Txpool`, `Wallet`,
  `Anvil` and `Evm` export no type: `@ethect/core/rpc/Eth` does not resolve.
- **No other path is exported.** `@ethect/core/Eth` does not resolve, and neither does a
  file of the package.

## Bundle size

A bundler that shakes namespace re-exports keeps the methods a program calls and drops the
rest, whatever the form of the import.

| What is bundled | Minified | Gzipped |
| --- | --- | --- |
| Effect alone: the same request written with `Schema` and `HttpClient` | 129.8 kB | 41.6 kB |
| ethect: `Address`, `Transport` and one `Eth.getBalance` | 157.3 kB | 52.6 kB |

Each row is one program: a single `eth_getBalance` over HTTP with `FetchHttpClient`, bundled
for the browser and minified with rolldown 1.3.4, on `effect` 4.1.7.

Most of a bundle is Effect itself, which an application that already uses Effect pays once.
The errors of a node are [Schema classes](https://ethect.dev/reference/errors/#the-three-errors): a program
that has no Schema class of its own pays 7.5 kB for them, 2.3 kB gzipped.

esbuild does not shake them: with esbuild 0.28.2 the same two programs are 403.8 kB and
540.9 kB minified, since it keeps every definition of the namespaces a program names.

## Next steps

- [Quick start](https://ethect.dev/getting-started/quick-start/): a read and a send against a local node.
- [Effect essentials](https://ethect.dev/guides/effect-essentials/): what you need to know about Effect.
- [Transports](https://ethect.dev/guides/transports/): choosing a transport, and providing it once.
