Skip to main content

@effectstream/precompile

Package: @effectstream/precompile · Source

Generate deterministic EVM-sized (20-byte) addresses from string names by hashing with keccak256. The intended use is "precompile" addresses — synthetic 0x-addresses reserved by an EffectStream node for non-user logic (intrinsic primitives, timers, internal accounts).

Install

bun add @effectstream/precompile
# or
npm install @effectstream/precompile

Standalone usage

Pure functions. Given a name, get an address. Same name, same address — always.

import { generatePrecompile, generatePrecompiles } from "@effectstream/precompile";

const addr = generatePrecompile("MY_FEATURE");
// addr === "0x<first-20-bytes-of-keccak256-of-MY_FEATURE>"

// Bulk-derive a typed map from a string enum.
enum MyNames {
A = "feature-a",
B = "feature-b",
}
const map = generatePrecompiles(MyNames);
// map["feature-a"] === generatePrecompile("feature-a")
// map["feature-b"] === generatePrecompile("feature-b")

The result is an EVM-shaped 0x[40 hex chars] string, usable wherever viem/ethers expects an Address.

Inside EffectStream

Exported through @effectstream/node-sdk/precompile. Names are stable across versions, so an address generated today matches one generated by a future build of the same name.

Key exports

  • generatePrecompile(name: string): HexString0x0x + first 40 hex chars of keccak256(name).
  • generatePrecompiles(names: Record<string, string>) — bulk variant. Returns { [value]: address }.

Examples

Runnable: test/examples.test.ts.