npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ethernauta/abi

v0.0.48

Published

ABI encode/decode codecs for Ethernauta — function signatures, event topics, parameter encoding/decoding.

Readme

bundlejs

Philosophy

This module is an un-opinionated representation of the Solidity ABI specification. It covers two responsibilities:

  • Runtime ABI codec — encode function calls / constructor calls, decode function results, decode Error(string) / Panic(uint256) revert payloads, encode + decode event topics and logs.
  • Code generation — emit ready-to-use TypeScript methods from an ABI JSON or a Foundry artifact.

Generated methods come in two flavors:

  • Callable<T> for view / pure functions — consumed by a contract resolver, fires eth_call.
  • Signable<Bytes> for state-changing functions — consumed by a signer resolver, returns the signed raw transaction ready for eth_sendRawTransaction.

Modules

API

Encode a function call

import { build_signature, encode_function_call, function_selector, to_selector } from "@ethernauta/abi"
import { bytes_to_hex } from "@ethernauta/utils"

const signature = build_signature("transfer", ["address", "uint256"])
const selector = function_selector(signature)        // Bytes4 — keccak256(signature)[0:4]
const calldata = encode_function_call(
  signature,
  ["address", "uint256"],
  ["0x515e9e0565fdddd4f8a9759744734154da453585", 1n],
)
const input = bytes_to_hex(calldata) // "0xa9059cbb000000…"

// Also exported: `to_selector(name, inputs)` — same as
// `function_selector(build_signature(name, inputs))`.

Encode a constructor call

import { encode_constructor_call } from "@ethernauta/abi"

const init_code = encode_constructor_call(
  bytecode,                  // Uint8Array — runtime + constructor
  ["address", "uint256"],    // constructor input types
  ["0x…", 1n],
)

Decode a function result

import { decode_function_result } from "@ethernauta/abi"

const [decoded] = decode_function_result(
  ["uint256"],
  "0x0000000000000000000000000000000000000000000000000000000000000002",
)
// 2n

Decode raw call data

Inverse of encode_function_call — useful for wallets inspecting an unknown input field.

import { decode_function_call } from "@ethernauta/abi"

const args = decode_function_call(["address", "uint256"], calldata)

Decode a revert payload

import { decode_revert_reason } from "@ethernauta/abi"

const reason = decode_revert_reason(revert_bytes)
// { kind: "error", message: "ERC20: transfer to the zero address" }
// or { kind: "panic", code: 0x11 }
// or { kind: "raw", data: "0x…" }

RevertReasonSchema is exported for callers that want to validate / parse external payloads.

Encode and decode event topics + logs

import {
  encode_event_topics,
  event_topic_hash,
  decode_event_log,
  decode_logs,
} from "@ethernauta/abi"

// Build the topic filter for an event signature
const topics = encode_event_topics({
  signature: "Transfer(address,address,uint256)",
  indexed: ["address", "address", "uint256"],
  filter: [from_address, undefined, undefined],
})

// Hash a single event signature
const topic0 = event_topic_hash("Transfer(address,address,uint256)")

// Decode a single log against a known ABI shape
const event = decode_event_log({
  signature: "Transfer(address,address,uint256)",
  inputs: [
    { name: "from", type: "address", indexed: true },
    { name: "to", type: "address", indexed: true },
    { name: "value", type: "uint256", indexed: false },
  ],
  topics: [topic0, "0x…", "0x…"],
  data: "0x…",
})

// Walk a batch of logs from `eth_getLogs`
const decoded = decode_logs(events_abi, raw_logs)

Compose codecs by hand — make_codec and the primitives

When the call shape varies at runtime (a registry that holds heterogeneous types), build the codec from primitive AbiCodec<T> instances.

import {
  type AbiCodec,
  address, bool, bytes, bytes4, bytes32,
  string_, uint256, hash32,
  array, tuple,
  encode_sequence, decode_sequence,
  make_codec,
} from "@ethernauta/abi"

const codec = tuple({ to: address(), value: uint256() })
const packed = encode_sequence([codec], [{ to: "0x…", value: 1n }])
const [decoded] = decode_sequence([codec], packed)

// `make_codec("uint256")` returns the primitive by Solidity name
const dynamic = make_codec("address")

uint256 also exposes raw width helpers — read_uint256 / write_uint256 for tight loops that bypass the AbiCodec envelope.

Parse and walk an ABI

import {
  parse_abi,
  type Description,
  DescriptionSchema,
} from "@ethernauta/abi"

const descriptions = parse_abi(ERC20_ABI)
// Description = function | constructor | fallback | receive | event | error

Generate methods programmatically

import {
  type Description,
  DescriptionSchema,
  emit_name_for,
  emit_file_basename_for,
  generate,
} from "@ethernauta/abi/generator"
import { array, parse } from "valibot"

const descriptions = parse(array(DescriptionSchema), ERC721_ABI)
const functions = descriptions.filter(
  (description): description is Description => description.type === "function",
)
generate(functions, "app") // methods will be generated at "app/methods"

// Pure name helpers (the same ones the generator uses internally)
const fn_name = emit_name_for("transferFrom") // "transferFrom"
const file_name = emit_file_basename_for("transferFrom") // "transfer-from"

Generate methods via the CLI

npx ethernauta abi --in abis/IERC20.abi.json --out app/methods

See @ethernauta/cli for the full CLI reference.