Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

stellar-contract-bindings

stellar-contract-bindings is a CLI tool designed to generate language bindings for Stellar Soroban smart contracts.

This tool simplifies the process of interacting with Soroban contracts by generating the necessary code to call contract methods directly from your preferred programming language. Currently, it supports Python, Java, Flutter/Dart, PHP, Swift/iOS, and Kotlin Multiplatform. stellar-cli provides support for TypeScript and Rust.

Web Interface

We have a web interface for generating bindings. You can access via https://stellar-contract-bindings.fly.dev/.

Installation

You can install stellar-contract-bindings using pip:

pip install stellar-contract-bindings

Usage

Please check the help message for the most up-to-date usage information:

stellar-contract-bindings --help

The contract id may name any contract instance: one carrying its own Wasm, a Stellar Asset Contract, or a CAP-85 external executable reference, which is resolved through its owner contract automatically.

Examples

Python

stellar-contract-bindings python --contract-id CDOAW6D7NXAPOCO7TFAWZNJHK62E3IYRGNRVX3VOXNKNVOXCLLPJXQCF --rpc-url https://mainnet.sorobanrpc.com --output ./bindings

Java

stellar-contract-bindings java --contract-id CDOAW6D7NXAPOCO7TFAWZNJHK62E3IYRGNRVX3VOXNKNVOXCLLPJXQCF --rpc-url https://mainnet.sorobanrpc.com --output ./bindings --package com.example

Flutter/Dart

stellar-contract-bindings flutter --contract-id CDOAW6D7NXAPOCO7TFAWZNJHK62E3IYRGNRVX3VOXNKNVOXCLLPJXQCF --rpc-url https://mainnet.sorobanrpc.com --output ./lib --class-name MyContract

PHP

stellar-contract-bindings php --contract-id CDOAW6D7NXAPOCO7TFAWZNJHK62E3IYRGNRVX3VOXNKNVOXCLLPJXQCF --rpc-url https://mainnet.sorobanrpc.com --output ./generated --namespace MyApp\\Contracts --class-name MyContractClient

Swift/iOS

stellar-contract-bindings swift --contract-id CDOAW6D7NXAPOCO7TFAWZNJHK62E3IYRGNRVX3VOXNKNVOXCLLPJXQCF --rpc-url https://mainnet.sorobanrpc.com --output ./Sources --class-name MyContract

Kotlin Multiplatform

stellar-contract-bindings kmp --contract-id CDOAW6D7NXAPOCO7TFAWZNJHK62E3IYRGNRVX3VOXNKNVOXCLLPJXQCF --rpc-url https://mainnet.sorobanrpc.com --output ./src/commonMain/kotlin --package com.example.bindings --class-name MyContract

These commands will generate language-specific bindings for the specified contract and save them in the respective directories.

Using the Generated Binding

After generating the binding, you can use it to interact with your Soroban contract. Here's an example:

Python

from stellar_sdk import Network
from bindings import Client  # Import the generated bindings

contract_id = "CDOAW6D7NXAPOCO7TFAWZNJHK62E3IYRGNRVX3VOXNKNVOXCLLPJXQCF"
rpc_url = "https://mainnet.sorobanrpc.com"
network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE

client = Client(contract_id, rpc_url, network_passphrase)
assembled_tx = client.hello(b"world")
print(assembled_tx.result())
# assembled_tx.sign_and_submit()

If the contract declares events in its SEP-48 spec (supported since Protocol 23), the generated Python bindings also include a typed class per event, a topic_filter() builder for getEvents, and a parse_event dispatcher that accepts xdr.ContractEvent, RPC EventInfo, or raw (topics, data) values.

Java

public class Example extends ContractClient {
    public static void main(String[] args) {
        KeyPair kp = KeyPair.fromAccountId("GD5KKP3LHUDXLDCGKP55NLEOEHMS3Z4BS6IDDZFCYU3BDXUZTBWL7JNF");
        Client client = new Client("CDOAW6D7NXAPOCO7TFAWZNJHK62E3IYRGNRVX3VOXNKNVOXCLLPJXQCF", "https://mainnet.sorobanrpc.com", Network.PUBLIC);
        AssembledTransaction<List<byte[]>> tx = client.hello("World".getBytes(), kp.getAccountId(), kp, 100);
    }
}

Flutter/Dart

import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart';
import 'lib/my_contract_client.dart'; // Import the generated bindings

void main() async {
  final sourceKeyPair = KeyPair.fromAccountId("GD5KKP3LHUDXLDCGKP55NLEOEHMS3Z4BS6IDDZFCYU3BDXUZTBWL7JNF");
  // or: final sourceKeyPair = KeyPair.fromSecretSeed("S...");
  
  // Create client instance
  final client = await MyContract.forContractId(
    sourceAccountKeyPair: sourceKeyPair,
    contractId: "CDOAW6D7NXAPOCO7TFAWZNJHK62E3IYRGNRVX3VOXNKNVOXCLLPJXQCF",
    network: Network.PUBLIC,
    rpcUrl: "https://mainnet.sorobanrpc.com",
  );
  
  // Call contract method directly
  try {
    final result = await client.hello(to: "World");
    print("Contract response: $result");
  } catch (e) {
    print("Error calling contract: $e");
  }
  
  // Or build an assembled transaction for more control
  final assembledTx = await client.buildHelloTx(
    to: "World",
    methodOptions: MethodOptions(),
  );
}

PHP

<?php

use Soneso\StellarSDK\Crypto\KeyPair;
use Soneso\StellarSDK\Network;
use Soneso\StellarSDK\Soroban\Contract\ClientOptions;
use Soneso\StellarSDK\Soroban\Contract\MethodOptions;
use MyApp\Contracts\MyContractClient; // Import the generated bindings

// Initialize
$sourceKeyPair = KeyPair::fromAccountId("GD5KKP3LHUDXLDCGKP55NLEOEHMS3Z4BS6IDDZFCYU3BDXUZTBWL7JNF");
// or: $sourceKeyPair = KeyPair::fromSeed("S...")

// Create client instance
$options = new ClientOptions(
    sourceAccountKeyPair: $sourceKeyPair,
    contractId: "CDOAW6D7NXAPOCO7TFAWZNJHK62E3IYRGNRVX3VOXNKNVOXCLLPJXQCF",
    network: Network::public(),
    rpcUrl: "https://mainnet.sorobanrpc.com"
);

$client = MyContractClient::forClientOptions($options);

// Call contract method directly
try {
    $result = $client->hello("World");
    echo "Contract response: " . $result . "\n";
} catch (Exception $e) {
    echo "Error calling contract: " . $e->getMessage() . "\n";
}

// Or build an assembled transaction for more control
$methodOptions = new MethodOptions();
$assembledTx = $client->buildHelloTx("World", $methodOptions);

Swift/iOS

import stellarsdk
import Foundation

// Import the generated bindings
// Assuming the generated file is named MyContract.swift

// Initialize
let sourceKeyPair = try! KeyPair.init(accountId: "GD5KKP3LHUDXLDCGKP55NLEOEHMS3Z4BS6IDDZFCYU3BDXUZTBWL7JNF")
// or: let sourceKeyPair = try! KeyPair.init(secretSeed: "S...")

// Create client instance
let options = ClientOptions(
    sourceAccountKeyPair: sourceKeyPair,
    contractId: "CDOAW6D7NXAPOCO7TFAWZNJHK62E3IYRGNRVX3VOXNKNVOXCLLPJXQCF",
    network: .public,
    rpcUrl: "https://mainnet.sorobanrpc.com"
)

Task {
    do {
        let client = try await MyContract.forClientOptions(options: options)
        
        // Call contract method directly
        let result = try await client.hello(
            to: "World",
            methodOptions: nil,
            force: false
        )
        print("Contract response: \(result)")
        
        // Or build an assembled transaction for more control
        let methodOptions = MethodOptions()
        let assembledTx = try await client.buildHelloTx(
            to: "World",
            methodOptions: methodOptions
        )
        
    } catch {
        print("Error calling contract: \(error)")
    }
}

Kotlin Multiplatform

import com.soneso.stellar.sdk.KeyPair
import com.soneso.stellar.sdk.Network
import com.example.bindings.MyContract // Import the generated bindings

suspend fun example() {
    val sourceKeyPair = KeyPair.fromAccountId("GD5KKP3LHUDXLDCGKP55NLEOEHMS3Z4BS6IDDZFCYU3BDXUZTBWL7JNF")
    // or: val sourceKeyPair = KeyPair.fromSecretSeed("S...")

    // Create a client instance (no network round-trip; the binding encodes and decodes
    // arguments directly, so the contract spec is not fetched)
    val client = MyContract.forContract(
        contractId = "CDOAW6D7NXAPOCO7TFAWZNJHK62E3IYRGNRVX3VOXNKNVOXCLLPJXQCF",
        rpcUrl = "https://mainnet.sorobanrpc.com",
        network = Network.PUBLIC,
    )

    // Call a contract method directly (read-only calls pass signer = null)
    val result = client.hello(
        to = "World",
        source = sourceKeyPair.getAccountId(),
        signer = null,
    )
    println("Contract response: $result")

    // Or build an assembled transaction for more control before signing and submitting
    val assembledTx = client.buildHelloTx(
        to = "World",
        source = sourceKeyPair.getAccountId(),
        signer = sourceKeyPair,
    )
    assembledTx.signAndSubmit(sourceKeyPair)
}

License

This project is licensed under the Apache-2.0 License. See the LICENSE file for details.

Contributing

Contributions are welcome! The project is designed to be easy to add support for other languages, please open an issue or submit a pull request for any improvements or bug fixes.

Metadata

Release files for stellar-contract-bindings 0.6.0b0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stellar-contract-bindings 0.6.0b0
File Size Uploaded Provenance
stellar_contract_bindings-0.6.0b0.tar.gz 148.5 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for stellar-contract-bindings 0.6.0b0
File Interpreter ABI Platform
stellar_contract_bindings-0.6.0b0-py3-none-any.whl Python 3 none any Details

Total release size: 226.6 kB

Release files / stellar_contract_bindings-0.6.0b0.tar.gz

Download URL stellar_contract_bindings-0.6.0b0.tar.gz
Size 148.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fec770392c1316ee379efaba298dd4cf5ea15876ad3f4b1d646ebea7ebfaadf2
BLAKE2b-256 checksum
How to use checksums
67106935d9c301f768ff8bf093e1e376cc760e66bee4260b7662ed1b7b44d539
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / stellar_contract_bindings-0.6.0b0-py3-none-any.whl

Download URL stellar_contract_bindings-0.6.0b0-py3-none-any.whl
Size 78.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef49fd55c81d0523b44b7806f43a42bcff36a0a193d0f4dfe8901c2637feb27e
BLAKE2b-256 checksum
How to use checksums
1629d90ca403b25ddd979743738beaee6d3c69317d0e14d5db4c47286a00f564
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Security for stellar-contract-bindings 0.6.0b0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for stellar_contract_bindings-0.6.0b0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page