Skip to content

feat: generate TypeScript contract bindings from Soroban WASM (#174)#189

Open
DammyAji wants to merge 1 commit into
BCPathway:mainfrom
DammyAji:feature/174-ts-codegen-from-wasm
Open

feat: generate TypeScript contract bindings from Soroban WASM (#174)#189
DammyAji wants to merge 1 commit into
BCPathway:mainfrom
DammyAji:feature/174-ts-codegen-from-wasm

Conversation

@DammyAji
Copy link
Copy Markdown

@DammyAji DammyAji commented May 30, 2026

Closes #174


Summary

Implements issue #174 — a code generation tool that reads a compiled Soroban contract's ABI from the WASM and generates type-safe TypeScript client code.

Changes

sdk/codegen/ (new)

  • src/parse-abi.ts — reads the contractspecv0 custom section from a .wasm file via contract.Client.fromWasm, extracts all functions, structs, unions, enums, and error cases
  • src/generate.ts — maps all ScSpecType variants to TypeScript types; generates interfaces, union types, enums, error enum, and a typed client interface
  • src/index.ts — CLI entry point: bc-forge-codegen <wasm-path> [output-path] [--name <Name>]

sdk/src/generated-client.ts (new)

Output from running codegen against bc_forge_token.wasm: 37 typed method signatures, 4 struct interfaces, 5 union types, BcForgeTokenError enum with 6 error codes.

sdk/package.json

Added codegen:build and codegen scripts.

.github/workflows/ci.yml

Added codegen job that builds the WASM, runs the codegen tool, and uploads generated-client.ts as a CI artifact.

Contract fixes

Fixed pre-existing compile errors in contracts/admin/src/lib.rs (spurious action_type field) and contracts/token/src/lib.rs (duplicate enum variant and garbled merge conflict blocks).

Checklist

  • sdk/codegen/ directory created
  • Parses Soroban contract metadata from WASM
  • Generates TypeScript interfaces for all types
  • Generates typed method signatures
  • Outputs sdk/src/generated-client.ts
  • Codegen integrated into CI

…way#174)

- Add sdk/codegen/ tool that reads contractspecv0 section from WASM
- Parse all funcs, structs, unions, enums, and error cases
- Generate typed interfaces and client interface in generated-client.ts
- Add codegen:build and codegen scripts to sdk/package.json
- Add codegen CI job that builds WASM, runs codegen, uploads artifact
- Fix pre-existing compile errors in token and admin contracts
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@DammyAji Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Generate TypeScript contract bindings from Soroban contract WASM/ABI

1 participant