Skip to content

Commit e4f165d

Browse files
authored
Basic CLI (#1)
* Completed basic AbigenJS CLI * Updated CI * Fixed typo * Updated README * Added shebang * Updated eslint * Added an ability to generate bindings from ABI only * Updated .github * Updated args and README * Removed redundant tests * Linting * Added husky and resolved comments after review * Updated README
1 parent 036e609 commit e4f165d

24 files changed

+6264
-0
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# These owners will be requested for review when someone opens a pull request.
2+
* @KyrylR @Arvolear
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Bug Report
2+
description: File a bug report
3+
labels: ["bug"]
4+
assignees:
5+
- arvolear
6+
body:
7+
- type: markdown
8+
attributes:
9+
value: Thanks for taking the time to fill out this bug report!
10+
- type: input
11+
id: version
12+
attributes:
13+
label: "AbigenJS version"
14+
placeholder: "1.2.3"
15+
validations:
16+
required: true
17+
- type: textarea
18+
id: what-happened
19+
attributes:
20+
label: What happened?
21+
description: A brief description of what happened and what you expected to happen
22+
validations:
23+
required: true
24+
- type: textarea
25+
id: reproduction-steps
26+
attributes:
27+
label: "Minimal reproduction steps"
28+
description: "The minimal steps needed to reproduce the bug"
29+
validations:
30+
required: true
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Feature request
2+
description: Suggest a new feature
3+
labels: ["feature"]
4+
assignees:
5+
- arvolear
6+
body:
7+
- type: textarea
8+
id: feature-description
9+
attributes:
10+
label: "Describe the feature"
11+
description: "A description of what you would like to see in AbigenJS"
12+
validations:
13+
required: true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
name: Other issue
3+
about: Other kind of issue
4+
---
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Lint and Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
- dev
9+
10+
permissions:
11+
contents: read
12+
13+
concurrency:
14+
group: ci-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
lint:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v5
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: 22
28+
cache: npm
29+
30+
- name: Install dependencies
31+
run: npm ci
32+
33+
- name: Lint (Prettier + ESLint)
34+
run: npm run lint
35+
36+
build_and_test:
37+
runs-on: ubuntu-latest
38+
needs: lint
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v5
42+
43+
- name: Setup Node.js
44+
uses: actions/setup-node@v4
45+
with:
46+
node-version: 22
47+
cache: npm
48+
49+
- name: Install dependencies
50+
run: npm ci
51+
52+
- name: Build
53+
run: npm run build
54+
55+
- name: Test
56+
run: npm test

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# dependencies (bun install)
2+
node_modules
3+
4+
# output
5+
out
6+
dist
7+
*.tgz
8+
9+
# code coverage
10+
coverage
11+
*.lcov
12+
13+
# logs
14+
logs
15+
_.log
16+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
17+
18+
# dotenv environment variable files
19+
.env
20+
.env.development.local
21+
.env.test.local
22+
.env.production.local
23+
.env.local
24+
25+
# caches
26+
.eslintcache
27+
.cache
28+
*.tsbuildinfo
29+
30+
# IntelliJ based IDEs
31+
.idea
32+
33+
# Finder (MacOS) folder config
34+
.DS_Store

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm run lint-fix && git add -u

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
dist/
3+
bin/
4+

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## AbigenJS
2+
3+
Generate Go bindings from artifacts via abigen.wasm compiled from [Abigen](https://geth.ethereum.org/docs/tools/abigen), without requiring the Go toolchain.
4+
5+
### Installation
6+
7+
```bash
8+
npm install -g abigenjs
9+
```
10+
11+
This package includes:
12+
13+
- Runtime CLI: `abigenjs`
14+
- Programmatic API: `Generator` (CommonJS module at `src/abigen/generator.cjs`)
15+
16+
### CLI Usage
17+
18+
```bash
19+
abigenjs [-o <outDir>] [-v <v1|v2>] [--deployable] [--abigen-path <path>] [--verbose|--quiet] [--clean] <paths to JSONs/dirs...>
20+
```
21+
22+
- **Defaults**: `-o generated-types/bindings`, `-v v2`.
23+
- **Inputs**: JSON files or directories (recursively scanned) containing contract artifacts or ABI-only JSON.
24+
- **Artifacts**: expected fields are `contractName`, `sourceName`, and `abi`. If `--deployable` is set, `bytecode` is also required.
25+
- **ABI-only inputs**: If a JSON file is either (a) a raw ABI array or (b) an object with an `abi` array (and optional `bytecode`), AbigenJS will infer `contractName` from the filename and use an empty `sourceName`. When `--deployable` is passed but `bytecode` is missing, non-deployable bindings will still be generated and a warning will be printed.
26+
- **abigen.wasm**: A packaged `abigen.wasm` is used by default; `--abigen-path` lets you override the path if needed.
27+
- **Quiet mode**: `--quiet` suppresses all non-error output and warnings, and overrides `--verbose`.
28+
29+
Examples:
30+
31+
```bash
32+
# Generate without deployable bindings from a directory of artifacts
33+
abigenjs -o ./gen -v v1 tests/mock_data
34+
35+
# Generate with deployable bindings for a single artifact file
36+
abigenjs --deployable tests/mock_data/ERC20Mock.json
37+
38+
# Use a custom abigen.wasm path (optional)
39+
abigenjs -o ./gen -v v1 --abigen-path ./bin/abigen.wasm tests/mock_data
40+
```
41+
42+
### Programmatic API
43+
44+
```ts
45+
// ESM context
46+
import { createRequire } from "module";
47+
const require = createRequire(import.meta.url);
48+
const Generator = require("abigenjs/dist/src/abigen/generator.cjs");
49+
50+
const gen = new Generator("./gen", "v1");
51+
await gen.clean();
52+
await gen.generate([artifact1, artifact2], /* deployable */ false, /* verbose */ false);
53+
```
54+
55+
### Limitations
56+
57+
- **Environment variables are not forwarded into `abigen.wasm`**: The embedded Go WASM runtime intentionally omits passing host ENV to the binary.

bin/abigen.wasm

11.7 MB
Binary file not shown.

0 commit comments

Comments
 (0)