Skip to main content
This guide will walk you through the process of installing and deploying a smart contract using js-stellar-sdk, the Python SDK, the Go SDK, or the Java SDK. We will cover the setup of a sample Rust contract, creating a Node.js project to manage the deployment, and finally, installing the Wasm of the contract and deploying it to the network

Prerequisites

Before you begin, ensure you have the following installed:
  1. Rust and Cargo (for compiling smart contracts)
  2. Node.js and npm (for running JavaScript deployment scripts), Python 3.10 or later (for running Python deployment scripts), Go 1.25 or later (for running Go deployment scripts), or Java 17 or later and Maven (for running Java deployment scripts)
  3. Stellar CLI

Initialize a sample Rust Contract

This sequence of commands creates a new directory for your project, initializes a new Soroban smart contract within that directory, and builds the contract. The build generates .wasm file in the path hello-world/target/wasm32v1-none/release/hello_world.wasm

Create a Node Project

  1. Create a new directory for your Node.js project and navigate into it:
  1. Initialize a new Node.js project and install necessary dependencies:
For Python, skip the Node.js project and install the SDK instead:
For Go, create a Go module in the same directory and add the SDK:
For Java, create a Maven project and add the SDK to the <dependencies> section of its pom.xml:

Set Up Deployment Scripts

Imports

Import necessary modules in your script. In JavaScript, save the file as deploy.mjs to enable ES module imports. In Go, save it as main.go. In Java, save it as src/main/java/DeployContract.java:

Installing the Wasm on the network

Create a function to upload the compiled Wasm file:
This function reads the compiled Wasm file, retrieves account details from the network, and installs the bytecode using uploadContractWasm Stellar operation, which when wrapped in a transaction is sent to the network.

Deploy contract

Deploy the contract by referencing the Wasm hash:
This function uses the Wasm hash to deploy the contract using the createCustomContract stellar operation, which when wrapped in a transaction is sent to the network, generating a contract address. scValToNative converts each return value to a JavaScript value: the Wasm hash bytes after the upload, and the contract address string after the deploy. In Python, append_create_contract_op adds the same operation, and scval.to_native converts the return values: the Wasm hash to bytes, and the contract address to an Address. In Go, the code builds the same CreateContractV2 host function by hand, reads the Wasm hash with GetBytes, and encodes the contract ID as a C... address with strkey. In Java, createContractOperationBuilder builds the same operation, Scv.fromBytes reads the Wasm hash, and Address.fromSCVal turns the return value into a C... address.

Building, Signing and Sending the Transaction

Handle the building, signing, and sending of transactions:
This function constructs a transaction, signs it, and submits it to the network. It checks the sendTransaction status first: TRY_AGAIN_LATER and ERROR mean the network did not accept the transaction, so the function stops with an error. Then server.pollTransaction waits for the result and stops after 30 attempts, so the script never hangs. If the attempts run out, the status is still NOT_FOUND. That means the result is unknown, not that the transaction failed, so check again before you resend it. Submit a transaction and wait shows the full handling. For the SDK’s own flow, read its Invoke a Contract guide. The Python version also defines get_return_value. The Python SDK’s response has no return value field, so the helper reads it from the transaction meta in result_meta_xdr. The Go version does the same with getReturnValue and ResultMetaXDR. The Go SDK has no prepareTransaction, so the Go version defines one: it simulates the transaction, then adds the simulated resources, resource fee, and authorization entries. The Java SDK has prepareTransaction, but its response has no return value field either, so the Java version reads it from the transaction meta with getReturnValue.

Running the Script

Execute the deployment script:
Replace “Your_Secret_Key” with your actual secret key. This script initiates the upload of the Wasm file and deploys the contract, resulting in a contract address where the contract is deployed. Run the Go version with go run main.go. In Java, the fields, methods, and main above go in one class, as the complete script below shows. This is just demo code, so ensure that you handle secrets and private keys securely in production environments and never expose them in your code repositories. This guide should provide you with a clear path to installing and deploying your smart contracts using JavaScript, Python, Go, or Java code.

Complete Script

Here are all the snippets stacked together in a single file for convenience: