Skip to content

Port Binding Generation#1287

Merged
Ryang-21 merged 62 commits intomasterfrom
binding-gen
Jan 22, 2026
Merged

Port Binding Generation#1287
Ryang-21 merged 62 commits intomasterfrom
binding-gen

Conversation

@Ryang-21
Copy link
Copy Markdown
Contributor

@Ryang-21 Ryang-21 commented Nov 20, 2025

CLI Usage Examples

From a local WASM file

npx @stellar/stellar-sdk generate \
  --wasm ./path/to/wasm_file/my_contract.wasm \
  --output-dir ./my-contract-client \
  --contract-name my-contract

From a WASM hash on the network

npx @stellar/stellar-sdk generate \
  --wasm-hash <hex-encoded-hash> \
  --rpc-url https://soroban-testnet.stellar.org \
  --network testnet \
  --output-dir ./my-contract-client \
  --contract-name my-contract

From a deployed contract ID

npx @stellar/stellar-sdk generate \
  --contract-id CABC...XYZ \
  --rpc-url https://soroban-testnet.stellar.org \
  --network testnet \
  --output-dir ./my-contract-client

@github-project-automation github-project-automation bot moved this to Backlog (Not Ready) in DevX Nov 20, 2025
@socket-security
Copy link
Copy Markdown

socket-security bot commented Nov 20, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedcommander@​14.0.29810010084100

View full report

Comment thread bin/stellar-js
Copy link
Copy Markdown
Contributor

@Shaptic Shaptic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome so far! Mostly minor comments below, gonna try it out right now too.

Comment thread src/bindings/client.ts Outdated
Comment thread scripts/download-sac-spec.sh Outdated
Comment thread src/bindings/config.ts
* Generate .gitignore
*/
private generateGitignore(): string {
const gitignore = [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just fetch and write the official one, instead?

Comment thread src/bindings/client.ts Outdated
Comment thread src/bindings/sac-spec.ts
Comment thread src/bindings/types.ts Outdated
Comment thread src/bindings/types.ts Outdated
Comment thread src/cli/util.ts Outdated
Comment thread src/cli/util.ts Outdated
Comment thread src/cli/util.ts Outdated
Copy link
Copy Markdown
Contributor

@Shaptic Shaptic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple more thoughts after running it on a side-project of mine

Comment thread src/bindings/client.ts Outdated
Comment thread src/bindings/client.ts Outdated
Comment thread src/bindings/client.ts Outdated
Comment thread src/bindings/client.ts Outdated
Comment thread src/bindings/generator.ts Outdated
@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 25, 2025

Size Change: +2.24 MB (+5.26%) 🔍

Total Size: 44.8 MB

Filename Size Change
dist/stellar-sdk-minimal.js 5.93 MB +360 kB (+6.46%) 🔍
dist/stellar-sdk-minimal.min.js 5.05 MB +200 kB (+4.13%)
dist/stellar-sdk-no-axios.js 5.93 MB +360 kB (+6.46%) 🔍
dist/stellar-sdk-no-axios.min.js 5.05 MB +200 kB (+4.13%)
dist/stellar-sdk-no-eventsource.js 6.18 MB +360 kB (+6.18%) 🔍
dist/stellar-sdk-no-eventsource.min.js 5.26 MB +200 kB (+3.96%)
dist/stellar-sdk.js 6.18 MB +360 kB (+6.18%) 🔍
dist/stellar-sdk.min.js 5.26 MB +200 kB (+3.96%)

compressed-size-action

@Ryang-21
Copy link
Copy Markdown
Contributor Author

Feedback should be addressed. The sdk now generates the same bindings as the cli besides one difference in how ScOptions are handled. The cli typed it as T | undefined but that is incorrect as the Spec decodes it as null this is problematic if users are strict equality checking the result against undefined. cc. @mootz12 @leighmcculloch

Copilot AI review requested due to automatic review settings January 14, 2026 22:07
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements contract binding generation functionality, porting it from stellar-cli to the JavaScript SDK. It adds a CLI tool and programmatic API to generate fully-typed TypeScript client code from Stellar smart contract specifications.

Changes:

  • Adds BindingGenerator class for generating TypeScript bindings from contract specs
  • Implements CLI with generate command supporting local WASM, network hash, and contract ID sources
  • Includes comprehensive unit, integration, and e2e tests with snapshot testing

Reviewed changes

Copilot reviewed 24 out of 27 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/bindings/generator.ts Core binding generator with factory methods for creating from WASM/network sources
src/bindings/client.ts Generates typed Client class with contract methods
src/bindings/types.ts Generates TypeScript interfaces for contract structs, enums, and unions
src/bindings/utils.ts Utility functions for type mapping, identifier sanitization, and import generation
src/bindings/wasm_fetcher.ts Fetches contract WASM from network via RPC
src/cli/index.ts CLI implementation with network configuration and option parsing
src/cli/util.ts CLI utility functions for file I/O and contract name derivation
test/integration/bindings.test.ts Unit tests for binding generation
test/e2e/src/bindings.test.ts E2e tests for generated bindings compilation and runtime
test/e2e/src/cli.test.ts E2e tests for CLI functionality

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/integration/bindings.test.ts Outdated
Comment thread src/bindings/generator.ts
Comment thread README.md
Comment thread README.md Outdated
Comment thread scripts/download-sac-spec.js Outdated

// URLs and paths
const REPO_URL =
"https://raw.githubusercontent.com/stellar/stellar-asset-contract-spec/main/stellar-asset-spec.xdr";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a specific commit SHA?

Comment thread scripts/download-sac-spec.js Outdated
Comment thread src/bindings/wasm_fetcher.ts Outdated
Comment thread src/bindings/wasm_fetcher.ts Outdated
Comment thread src/bindings/wasm_fetcher.ts Outdated
Comment thread src/bindings/wasm_fetcher.ts Outdated
@Ryang-21 Ryang-21 merged commit d3c1426 into master Jan 22, 2026
10 checks passed
@Ryang-21 Ryang-21 deleted the binding-gen branch January 22, 2026 17:32
@github-project-automation github-project-automation bot moved this from Backlog (Not Ready) to Done in DevX Jan 22, 2026
@janewang
Copy link
Copy Markdown
Contributor

Herculean effort 💪

Thank you @Ryang-21 👏👏👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants