Skip to content

Add ABI JSON generation tool (SDK functions + CLI) from on-chain state#859

Open
gregnazario wants to merge 3 commits intomainfrom
cursor/on-chain-abi-json-tool-9960
Open

Add ABI JSON generation tool (SDK functions + CLI) from on-chain state#859
gregnazario wants to merge 3 commits intomainfrom
cursor/on-chain-abi-json-tool-9960

Conversation

@gregnazario
Copy link
Collaborator

@gregnazario gregnazario commented Mar 20, 2026

Description

Adds SDK functions for generating JSON-serializable ABI definitions from on-chain Move modules, plus a standalone CLI package (@aptos-labs/generate-abi-json) that can be run via npx without writing any code.

This enables users to pre-generate ABI JSON at build time, store it, and use it at runtime without remote ABI fetching overhead.

SDK Functions (library API in @aptos-labs/ts-sdk)

Function Purpose
generateModuleAbiJSON Fetch all entry/view function ABIs for a module as JSON
generateEntryFunctionAbiJSON Fetch a single entry function ABI as JSON
generateViewFunctionAbiJSON Fetch a single view function ABI as JSON
parseEntryFunctionAbiJSON Hydrate JSON back into EntryFunctionABI with TypeTag objects
parseViewFunctionAbiJSON Hydrate JSON back into ViewFunctionABI with TypeTag objects

New types: EntryFunctionAbiJSON, ViewFunctionAbiJSON, ModuleAbiJSON

CLI Package (@aptos-labs/generate-abi-json)

A standalone package at packages/generate-abi-json/ that can be run without writing any code:

# All entry/view ABIs for the coin module on mainnet
npx @aptos-labs/generate-abi-json --address 0x1 --module coin --pretty

# Single function
npx @aptos-labs/generate-abi-json --address 0x1 --module coin --function transfer --pretty

# Write to file
npx @aptos-labs/generate-abi-json --address 0x1 --module coin --output coin-abi.json

# Custom network
npx @aptos-labs/generate-abi-json --network testnet --address 0x1 --module coin
npx @aptos-labs/generate-abi-json --node-url http://localhost:8080/v1 --address 0x1 --module coin

Using the output with the SDK:

import { parseEntryFunctionAbiJSON } from "@aptos-labs/ts-sdk";
import coinAbi from "./coin-abi.json";

const transferAbi = parseEntryFunctionAbiJSON(coinAbi.entryFunctions.transfer);
const txn = await aptos.transaction.build.simple({
  sender: alice.accountAddress,
  data: {
    function: "0x1::coin::transfer",
    typeArguments: ["0x1::aptos_coin::AptosCoin"],
    functionArguments: [bob.accountAddress, 100],
    abi: transferAbi,
  },
});

Test Plan

  • Unit tests (tests/unit/abiJson.test.ts): 12 test cases covering parseEntryFunctionAbiJSON and parseViewFunctionAbiJSON with various parameter types, constraints, empty params, and JSON round-trip serialization.
  • E2E tests (tests/e2e/api/abiJson.test.ts): 13 test cases against a local Aptos testnet covering generation, error cases, round-trip serialization, and transaction building with parsed ABIs.
  • CLI manual testing: Verified all CLI modes (--help, full module, single entry/view function, --output, error cases) against a local testnet from the standalone package.

All 25 automated tests pass.

Related Links

N/A

Checklist

  • Have you ran pnpm fmt?
  • Have you updated the CHANGELOG.md?
Open in Web Open in Cursor 

@cursor cursor bot force-pushed the cursor/on-chain-abi-json-tool-9960 branch from f13430b to 60aa787 Compare March 20, 2026 21:26
@cursor cursor bot changed the title Add ABI JSON generation tool for entry and view functions from on-chain state Add ABI JSON generation tool (SDK functions + CLI) from on-chain state Mar 20, 2026
@gregnazario gregnazario force-pushed the cursor/on-chain-abi-json-tool-9960 branch from 60aa787 to 339d244 Compare March 21, 2026 01:21
@gregnazario gregnazario marked this pull request as ready for review March 24, 2026 03:51
@gregnazario gregnazario requested a review from a team as a code owner March 24, 2026 03:51
cursoragent and others added 3 commits March 23, 2026 23:51
Adds utility functions to fetch on-chain module ABIs and produce
JSON-serializable representations of entry/view function ABIs:

- generateModuleAbiJSON: fetches all entry/view ABIs for a module
- generateEntryFunctionAbiJSON: fetches a single entry function ABI
- generateViewFunctionAbiJSON: fetches a single view function ABI
- parseEntryFunctionAbiJSON: hydrates JSON back to EntryFunctionABI
- parseViewFunctionAbiJSON: hydrates JSON back to ViewFunctionABI

This allows users to pre-generate ABI JSON, store it, and use it
at runtime without remote ABI fetching overhead.

Includes unit tests (12 cases) and e2e tests (13 cases) covering
generation, parsing, round-trip serialization, and transaction building.

Co-authored-by: Greg Nazario <greg@gnazar.io>
Adds a standalone CLI entry point at src/cli/generate-abi-json.ts that
can be invoked via 'npx generate-abi-json' (after installing the SDK)
or 'node dist/common/cli/generate-abi-json.js' (after building).

Supports:
  --network (mainnet/testnet/devnet/local)
  --node-url (custom fullnode endpoint)
  --address / --module (required)
  --function (optional, to target a single function)
  --output (write to file instead of stdout)
  --pretty (pretty-print JSON)

Registered as a bin entry in package.json and added to tsup config.

Co-authored-by: Greg Nazario <greg@gnazar.io>
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>
@gregnazario gregnazario force-pushed the cursor/on-chain-abi-json-tool-9960 branch from 1c2bc71 to 73ce06a Compare March 24, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants