Add ABI JSON generation tool (SDK functions + CLI) from on-chain state#859
Open
gregnazario wants to merge 3 commits intomainfrom
Open
Add ABI JSON generation tool (SDK functions + CLI) from on-chain state#859gregnazario wants to merge 3 commits intomainfrom
gregnazario wants to merge 3 commits intomainfrom
Conversation
f13430b to
60aa787
Compare
60aa787 to
339d244
Compare
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>
1c2bc71 to
73ce06a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 vianpxwithout 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)generateModuleAbiJSONgenerateEntryFunctionAbiJSONgenerateViewFunctionAbiJSONparseEntryFunctionAbiJSONEntryFunctionABIwithTypeTagobjectsparseViewFunctionAbiJSONViewFunctionABIwithTypeTagobjectsNew types:
EntryFunctionAbiJSON,ViewFunctionAbiJSON,ModuleAbiJSONCLI Package (
@aptos-labs/generate-abi-json)A standalone package at
packages/generate-abi-json/that can be run without writing any code:Using the output with the SDK:
Test Plan
tests/unit/abiJson.test.ts): 12 test cases coveringparseEntryFunctionAbiJSONandparseViewFunctionAbiJSONwith various parameter types, constraints, empty params, and JSON round-trip serialization.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.--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
pnpm fmt?CHANGELOG.md?