Skip to content

Commit 1c2bc71

Browse files
Move CLI to standalone @aptos-labs/generate-abi-json package
Extracts the generate-abi-json CLI into a separate package at packages/generate-abi-json/ so it can be run independently via: npx @aptos-labs/generate-abi-json --address 0x1 --module coin --pretty The package has its own package.json, tsup build config, and depends on @aptos-labs/ts-sdk as a regular dependency. Removes the bin entry, tsup entry, and script from the main SDK package.json. Co-authored-by: Greg Nazario <greg@gnazar.io>
1 parent 339d244 commit 1c2bc71

File tree

9 files changed

+1046
-19
lines changed

9 files changed

+1046
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ All notable changes to the Aptos TypeScript SDK will be captured in this file. T
1818

1919
- Add e2e tests for external signer flow (build → getSigningMessage → sign externally → submit) to verify the flow works correctly with the latest SDK version
2020
- Add ABI JSON generation tool: `generateModuleAbiJSON`, `generateEntryFunctionAbiJSON`, `generateViewFunctionAbiJSON` to fetch on-chain module ABIs and produce JSON-serializable output; `parseEntryFunctionAbiJSON` and `parseViewFunctionAbiJSON` to hydrate them back into SDK-native `EntryFunctionABI`/`ViewFunctionABI` types
21-
- Add `generate-abi-json` CLI tool (available via `npx generate-abi-json`) to generate ABI JSON from on-chain state without writing code
21+
- Add `@aptos-labs/generate-abi-json` standalone CLI package (available via `npx @aptos-labs/generate-abi-json`) to generate ABI JSON from on-chain state without writing code
2222
- Add MultiKey (K-of-N mixed key types) transfer example (`examples/typescript/multikey_transfer.ts`)
2323
- Add MultiEd25519 (K-of-N Ed25519) transfer example (`examples/typescript/multi_ed25519_transfer.ts`)
2424

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
"url": "https://github.com/aptos-labs/aptos-ts-sdk/issues/new/choose"
1111
},
1212
"homepage": "https://aptos-labs.github.io/aptos-ts-sdk/",
13-
"bin": {
14-
"generate-abi-json": "dist/common/cli/generate-abi-json.js"
15-
},
1613
"main": "dist/common/index.js",
1714
"module": "dist/esm/index.mjs",
1815
"exports": {
@@ -50,7 +47,6 @@
5047
"doc": "scripts/generateDocs.sh",
5148
"check-version": "scripts/checkVersion.sh",
5249
"update-version": "scripts/updateVersion.sh && pnpm doc",
53-
"generate-abi-json": "node dist/common/cli/generate-abi-json.js",
5450
"spec": "pnpm build && pnpm _spec",
5551
"_spec": "cucumber-js -p default"
5652
},
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# @aptos-labs/generate-abi-json
2+
3+
CLI tool to generate JSON-serializable entry/view function ABIs from on-chain Aptos Move modules. The generated JSON can be embedded in application source code and used with the Aptos TypeScript SDK to skip remote ABI fetching at runtime.
4+
5+
## Usage
6+
7+
```bash
8+
npx @aptos-labs/generate-abi-json --address 0x1 --module coin --pretty
9+
```
10+
11+
### Options
12+
13+
| Flag | Description |
14+
|------|-------------|
15+
| `--network <network>` | Network to connect to: `mainnet`, `testnet`, `devnet`, `local` (default: `mainnet`) |
16+
| `--node-url <url>` | Custom fullnode URL (overrides `--network`; include `/v1`) |
17+
| `--address <address>` | Account address of the module (required) |
18+
| `--module <name>` | Module name (required) |
19+
| `--function <name>` | Specific function name (omit to output all functions) |
20+
| `--output <file>` | Write JSON to a file instead of stdout |
21+
| `--pretty` | Pretty-print JSON with 2-space indentation |
22+
| `--help` | Show help message |
23+
24+
### Examples
25+
26+
```bash
27+
# All entry/view ABIs for the coin module on mainnet
28+
npx @aptos-labs/generate-abi-json --address 0x1 --module coin --pretty
29+
30+
# Single entry function, written to a file
31+
npx @aptos-labs/generate-abi-json --address 0x1 --module coin --function transfer --output coin_transfer.json
32+
33+
# Use testnet
34+
npx @aptos-labs/generate-abi-json --network testnet --address 0x1 --module coin
35+
36+
# Use a custom node URL
37+
npx @aptos-labs/generate-abi-json --node-url http://localhost:8080/v1 --address 0x1 --module coin
38+
```
39+
40+
## Using the output with the SDK
41+
42+
```typescript
43+
import { parseEntryFunctionAbiJSON } from "@aptos-labs/ts-sdk";
44+
import coinAbi from "./coin-abi.json";
45+
46+
// Parse the JSON back into an SDK-native EntryFunctionABI
47+
const transferAbi = parseEntryFunctionAbiJSON(coinAbi.entryFunctions.transfer);
48+
49+
// Use it to build transactions without remote ABI fetching
50+
const txn = await aptos.transaction.build.simple({
51+
sender: alice.accountAddress,
52+
data: {
53+
function: "0x1::coin::transfer",
54+
typeArguments: ["0x1::aptos_coin::AptosCoin"],
55+
functionArguments: [bob.accountAddress, 100],
56+
abi: transferAbi,
57+
},
58+
});
59+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@aptos-labs/generate-abi-json",
3+
"version": "0.1.0",
4+
"description": "CLI tool to generate JSON-serializable entry/view function ABIs from on-chain Aptos Move modules",
5+
"license": "Apache-2.0",
6+
"packageManager": "pnpm@10.30.3",
7+
"engines": {
8+
"node": ">=20.0.0"
9+
},
10+
"bin": {
11+
"generate-abi-json": "dist/index.js"
12+
},
13+
"files": [
14+
"dist"
15+
],
16+
"scripts": {
17+
"build:clean": "rm -rf dist",
18+
"build": "pnpm build:clean && tsup"
19+
},
20+
"dependencies": {
21+
"@aptos-labs/ts-sdk": ">=6.2.0"
22+
},
23+
"devDependencies": {
24+
"tsup": "^8.5.1",
25+
"typescript": "^5.9.3"
26+
}
27+
}

0 commit comments

Comments
 (0)