Skip to main content

Overview

In this guide, you’ll learn how to deploy a Stellar Asset Contract (SAC) for a Stellar asset using the Stellar SDK. The Stellar SDK is a set of tools and libraries designed to help developers build applications that interact with the Stellar blockchain network.

Prerequisites:

  • For JavaScript: Node.js and npm installed, and the Stellar SDK for JavaScript installed
  • For Python: the Stellar SDK for Python installed
  • For Go: Go 1.25 or later, and the Stellar SDK for Go installed
  • For Java: Java 17 or later, and the Stellar SDK for Java (network.lightsail:stellar-sdk:6.0.0) installed
  • Knowledge about Issuing an Asset on Stellar
  • An understanding of the rudimentary, retry-enabled transaction polling function submitTx (submit_tx in Python) which we outlined in another guide

Code overview

Code explanation

Server Setup
  • networkRPC: The URL for the Soroban testnet.
  • server: A new instance of rpc.Server is created, which will be used to interact with the Soroban testnet.
  • networkPassphrase: sets the network passphrase to the TESTNET
DeployStellarAssetContract function
This function is designed to deploy a Stellar Asset Contract (SAC) on the Soroban testnet.
  • Secret Key: It starts by defining the secret key for the source account (sourceSecrets), which you must replace with your own.
  • Keypair and Account: Generates the keypair from the secret key and fetches the account details from the Soroban server.
  • Custom Asset: Defines a custom asset with the code JOEBOY and the issuer’s public key.
  • Fee: Bids the 90th percentile of recent Soroban inclusion fees (from getFeeStats()), capped at MAX_FEE. Do not bid BASE_FEE: it is the network minimum and gets outbid when the network is busy.
  • Transaction Building: A transaction is built using the TransactionBuilder, which includes the createStellarAssetContract operation for the custom asset. The transaction is then prepared and signed. 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 and createStellarAssetContractOperationBuilder, so the Java version needs no helper for this step.
  • Send Transaction: The signed transaction is sent to the network using server.sendTransaction.
  • Feedback Handling: It waits for the transaction feedback using the submitTx function to ensure it has succeeded. Then, it extracts the return value and converts it to a contract ID using StellarSdk.Address. Finally, it logs the contract ID for the deployed asset. The Java SDK’s response has no return value field, so the Java version reads it from the transaction meta with getReturnValue and converts it with Address.fromSCVal.