Skip to content

feat: Enhance contract ABI binding generator (#336) - #710

Merged
Nanle-code merged 1 commit into
Nanle-code:masterfrom
cyber-excel10:feature/binding-generator-336
Jul 30, 2026
Merged

feat: Enhance contract ABI binding generator (#336)#710
Nanle-code merged 1 commit into
Nanle-code:masterfrom
cyber-excel10:feature/binding-generator-336

Conversation

@cyber-excel10

Copy link
Copy Markdown
Contributor

Closes #336

feat: Enhance contract ABI binding generator with type-safe interfaces and event support (#336)

What i changed?

Updated the contract binding generator so it actually emits fully type-safe interfaces across all supported client languages, along with complete event type definitions extracted directly from contract metadata.

Before this, a lot of parameter types were falling back to overly generic traits like impl ToString, which made client-side integration error-prone and clunky. Complex types (nested Options, Results, Vectors, Maps) are now serialized properly without manual casting hacks on the caller side.


Key Changes

  • Event type generation: Reads contract metadata at codegen time and emits corresponding typed event structs/interfaces for each language.
  • Strict type annotations: Replaced loose string-coercion parameter bindings with real concrete types.
  • Complex type serialization: Cleaned up encoding/decoding logic for Option<T>, Result<T, E>, Vec<T>, and HashMap<K, V>.
  • Multi-language generator updates: Refactored the core codegen drivers for Rust, TypeScript, Python, and Go.
  • Test suite: Added bindings_tests.rs covering edge-case types, malformed metadata handling, and multi-language snapshot comparisons.

Feature Overview

  • Full type safety across Rust, TypeScript, Python, and Go
  • Automatic event payload definitions from ABI metadata
  • Proper nested/complex type serialization
  • Extensive end-to-end unit and snapshot test coverage
  • 100% Backward Compatible — existing CLI flags and generated code entrypoints remain unchanged

How it was tested

  • Created bindings_tests.rs to exercise the ABI parsing pipeline against real .wasm binaries.
  • Verified generated output builds and compiles cleanly across all four target environments:
    • Rust (cargo check passes on output client.rs)
    • TypeScript (tsc --noEmit clean on client.ts)
    • Python (mypy static verification on client.py)
    • Go (go build check on client.go)
  • Handled invalid WASM input gracefully with proper error messages instead of standard panics.

Usage Examples

Generate bindings using the standard CLI workflow:

# Rust
starforge contract generate-bindings ./contract.wasm --lang rust > client.rs

# TypeScript
starforge contract generate-bindings ./contract.wasm --lang ts > client.ts

# Python
starforge contract generate-bindings ./contract.wasm --lang python > client.py

# Go
starforge contract generate-bindings ./contract.wasm --lang go > client.go

- Add event type definitions from contract metadata
- Improve type-safe interfaces with proper type annotations
- Enhance serialization/deserialization for complex types
- Add comprehensive binding tests
- Support all languages: Rust, TypeScript, Python, Go
@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@cyber-excel10 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

@Nanle-code
Nanle-code merged commit a16a53e into Nanle-code:master Jul 30, 2026
6 of 16 checks passed
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.

D-20: Implement Contract ABI Binding Generator

2 participants