Generate Go bindings from artifacts via abigen.wasm compiled from Abigen, without requiring the Go toolchain.
npm install -g abigenjsThis package includes:
- Runtime CLI:
abigenjs - Programmatic API:
Generator(CommonJS module atsrc/abigen/generator.cjs)
abigenjs <paths to JSONs/dirs...> [-o <outDir>] [-v <v1|v2>] [--deployable] [--abigen-path <path>] [--verbose|--quiet] [--clean]- Defaults:
-o generated-types/bindings,-v v2. - Inputs: JSON files or directories (recursively scanned) containing contract artifacts or ABI-only JSON.
- Artifacts: expected fields are
contractName,sourceName, andabi. If--deployableis set,bytecodeis also required. - ABI-only inputs: If a JSON file is either (a) a raw ABI array or (b) an object with an
abiarray (and optionalbytecode), AbigenJS will infercontractNamefrom the filename and use an emptysourceName. When--deployableis passed butbytecodeis missing, non-deployable bindings will still be generated and a warning will be printed. - abigen.wasm: A packaged
abigen.wasmis used by default;--abigen-pathlets you override the path if needed. - Quiet mode:
--quietsuppresses all non-error output and warnings, and overrides--verbose.
Examples:
# Generate without deployable bindings from a directory of artifacts
abigenjs -o ./gen -v v1 tests/mock_data
# Generate with deployable bindings for a single artifact file
abigenjs --deployable tests/mock_data/ERC20Mock.json
# Use a custom abigen.wasm path (optional)
abigenjs -o ./gen -v v1 --abigen-path ./bin/abigen.wasm tests/mock_dataimport { Generator, Artifact } from "abigenjs/generator";
const gen = new Generator("./gen", "v1");
await gen.clean();
await gen.generate([artifact1, artifact2], /* deployable */ false, /* verbose */ false);- Environment variables are not forwarded into
abigen.wasm: The embedded Go WASM runtime intentionally omits passing host ENV to the binary.