Skip to content

Why ethect

ethect is a TypeScript library for Ethereum built on Effect: an alternative to viem, with a near zero-dependency state of mind. It reads and writes contracts, sends transactions, follows events and connects wallets. This page says what you get, what the package holds, and what it does not have.

import { Effect } from "effect";
import { Address, Erc20, Signer, Tx } from "@ethect/core";
const token = Erc20.at(Address.makeUnsafe("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"));
const TO = Address.makeUnsafe("0x70997970C51812dc3A010C7d01b50e0d17dc79C8");
const program = Effect.gen(function* () {
const balance = yield* token.balanceOf(yield* Signer.address); // bigint
return yield* Tx.send(token.transfer(TO, balance / 2n)); // the receipt, once in a block
});
// Effect<Receipt, …, Signer | Transport>

The type of the program says what it returns, how it can fail, and what it needs: a node, and someone who signs. Which node and which signer is decided where the program runs: see the quick start.

  • Tokens and vaults, with no ABI to write. Erc20, Erc721, Erc1155 and Erc4626 are built in, and extend adds what a contract has more.
  • Any other contract from its signatures. Abi.parse reads them as text, Abi.fromJson takes the ABI you already have. A call is a value: it is built, passed around, and sent or read later.
  • Reads merge by themselves. Reads issued together leave as one multicall, at one block. Nothing has to be gathered by hand.
  • One line sends, with a key or with a wallet. Tx.send signs, sends and waits. Several calls are one prompt on a wallet that batches, and the same code elsewhere.
  • Errors are values. No effect throws. The custom error of a contract is a typed failure caught by its tag, and the compiler knows which failures you have not handled.
  • Events are decoded, and watched as a stream. Ev.watch is pushed over a WebSocket and polled over HTTP: the line is the same.
  • Wallets are found and followed. The installed wallets announce themselves, and a connection follows the account and the chain the user picks.
  • A secret is never a string. A private key is a Redacted, and so is a URL with a key in it: neither can end up in a log or in an error.
  • Tests run against a real node. AnvilNode gives each test its own anvil, and TestWallet is a wallet whose user is the test.
  • Plain JSON-RPC 2.0 on the wire. Every method a node serves is also a typed function, for when you want one request and nothing around it.

The package is @ethect/core, at an early version: its API can still change. It has one entry point per part.

It depends on two packages, both for cryptography: @noble/curves for the secp256k1 signatures and @noble/hashes for keccak-256. effect is its one peer dependency. Nothing else is installed with it.

Part Import from Holds
Contracts @ethect/core Abi, Fn, Err, Ev, Contract, and the standards: Erc20, Erc721, Erc1155, Erc4626
Reads and sends @ethect/core Call, Tx, Signer, Block
Wallets @ethect/core Wallets, Connection, Chain
The base @ethect/core transports, errors, Address, Hex, Hash, Quantity
Names @ethect/core/ens Ens
JSON-RPC @ethect/core/rpc 161 methods and 5 subscription kinds, with the wire types
Testing @ethect/core/testing AnvilNode, MockProvider, TestWallet, TestSigner

Everything is tested against anvil. The reads of the JSON-RPC layer have also been run against Geth, reth, Erigon, Nethermind and the clients of several other chains: see the list. No real wallet and no browser are part of a test: wallets are tested with TestWallet and with providers that answer as the EIPs say.

Not there So
a React package the hooks are a few lines you keep: see the setup of the wallet picker
WalletConnect, and other connectors Wallets.of takes a provider you built
SIWE Signature.verifyMessage checks the signature, and the message is yours to write and to read
unit helpers such as parseEther by decision: Effect’s BigDecimal does it. See Amounts and decimals
a list of chains a Chain is data you write, and you give the URL of the node
mnemonics and HD accounts Signer.privateKey takes one key
blob and EIP-7702 transactions signed with a key TxUnsupported, with the reason "signing"
a fallback transport, automatic retries a wrapper you write, Effect.retry
account abstraction, OP Stack and ZKsync extensions none
viem ethect
A read await client.readContract({ address, abi, functionName, args }) yield* token.balanceOf(owner)
A send writeContract, then waitForTransactionReceipt yield* Tx.send(token.transfer(to, amount))
When it runs when you call it when you run the program
Where it goes the client you created the transport and the signer you provide
Several reads multicall, or batch.multicall on the client merged without asking
A failure a thrown error, found with instanceof or error.walk a value in the error channel, matched by tag
What can fail documented per action in the type of the call
Watching a callback and an unwatch function a Stream that stops when you stop reading it
Results bigint, number and named types and statuses the same choices
An address a `0x${string}` string a branded lowercase string, sent in its EIP-55 form

Coming from viem maps each function you know to its counterpart.

  • You do not use Effect and do not want to. Every call is an Effect. The essentials fit on one page, but they are not optional.
  • You need something of the table above. WalletConnect and a React package are the ones an application misses first.
  • You need an API that no longer moves. The version is early.
  • You need Windows for tests. AnvilNode needs a POSIX shell.