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:

Code overview

deployassetcontract.js

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.
  • 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.
  • 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.