Skip to content

Installation

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

npm install @ethect/core@alpha effect
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.

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 an HttpClient FetchHttpClient.layer effect/http
Transport.webSocket a WebSocketConstructor Socket.layerWebSocketConstructorGlobal effect/socket
Transport.ipc a Socket NodeSocket.layerNet({ path }) @effect/platform-node
Transport.eip1193 nothing

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

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.

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.

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 to Transport
@ethect/core/ens Ens Ens
@ethect/core/rpc the low-level layer: the eight namespaces, the wire types, Method, Subscription JSON-RPC
@ethect/core/testing AnvilNode, MockProvider, TestWallet, TestSigner Testing
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.

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.

// 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.

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 154.3 kB 50.0 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 and @ethect/core 0.0.0.

Most of a bundle is Effect itself, which an application that already uses Effect pays once.

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.