// Call.all
Three reads, one request
Reads issued together leave as one multicall, at one block.
const holding = Call.all({ symbol: usdc.symbol(), decimals: usdc.decimals(), balance: usdc.balanceOf(OWNER),});Layer, a failure is a value, and reads merge into one request.bun add @ethect/core@alpha effect// one type
A call to a contract is a value. Its type 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 it run
Each lane is a request: to your node, or to the signer. What a lane gives back is a value, or a failure with a tag.
// Call.all
Reads issued together leave as one multicall, at one block.
const holding = Call.all({ symbol: usdc.symbol(), decimals: usdc.decimals(), balance: usdc.balanceOf(OWNER),});// Tx.send
Signed, sent and waited for. The node and the signer are provided where it runs.
const receipt = yield* Tx.send(usdc.transfer(TO, balance / 2n));// Effect<Receipt, Failure<E>, Signer | Transport>// Effect.catchTag
The wallet says no. The failure has a tag, and catching it takes it out of the type.
Tx.send(vault.deposit(amount, ME)).pipe( Effect.catchTag("Rejected", () => Effect.succeed("You refused to sign")),);// Effect.retry
The node drops two requests. An exponential schedule tries again, four times at most.
ownerOf(nft, tokenId).pipe( Effect.retry({ while: (error) => error._tag === "TransportError", schedule: Schedule.exponential("250 millis"), times: 4, }),);// coming from viem
Each viem function has a counterpart. What changes is where the node is chosen, and what you know about a failure before it happens. Coming from viem maps them all.
6 collapsed lines
import { createPublicClient, erc20Abi, http } from "viem";import { mainnet } from "viem/chains";
declare const url: string;const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";const OWNER = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
const client = createPublicClient({ chain: mainnet, transport: http(url), batch: { multicall: true },});
const usdc = { address: USDC, abi: erc20Abi } as const;
try { const [symbol, balance] = await Promise.all([ client.readContract({ ...usdc, functionName: "symbol" }), client.readContract({ ...usdc, functionName: "balanceOf", args: [OWNER] }), ]);} catch (error) { // error: unknown}unknown5 collapsed lines
import { Effect } from "effect";import { Address, Call, Erc20 } from "@ethect/core";
const USDC = Address.makeUnsafe("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48");const OWNER = Address.makeUnsafe("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
const usdc = Erc20.at(USDC);
export const holding = Call.all({ symbol: usdc.symbol(), balance: usdc.balanceOf(OWNER),}).pipe( // the node is down: a value, not an exception Effect.catchReason("TransportError", "Unreachable", () => Effect.succeed({ symbol: "?", balance: 0n }), ),);Layer, provided where it runs// in the box
@noble/curves for the secp256k1 signatures and @noble/hashes for keccak-256. effect is its
one peer dependency. Nothing else is installed with it.
@ethect/coreThe main APIsContracts (Abi, Fn, Err, Ev, Contract and the four standards), reads and sends (Call, Tx, Signer), wallets, transports, errors and primitives.
Erc20 · Call · Tx · Signer@ethect/core/rpcThe JSON-RPC layerEvery method as a typed function that returns an Effect, with the wire types it takes and gives.
161 methods · 5 subscriptions@ethect/core/ensNamesA name to an address and back, its text records and its avatar. An empty Option where there is none.
Ens@ethect/core/testingTest toolsA local anvil node, a mock provider, a wallet and a signer for tests.
AnvilNode · MockProvider · TestWallet · TestSigner// status
Versions are published under the alpha tag of npm, and the API can still change from one to
the next. Why ethect has the whole list of
what is missing.
Tested againstanvil· the reads of the JSON-RPC layer also run againstGethrethErigonNethermind
Redacted · never in a logThe quick start reads from a local anvil node, then sends it a transaction.
bun add @ethect/core@alpha effect