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:
- Node.js and npm installed.
- Stellar SDK for JavaScript installed
- Knowledge about Issuing an Asset on Stellar
- An understanding of the rudimentary, retry-enabled transaction polling function
submitTxwhich we outlined in another guide
Code overview
deployassetcontract.js
Code explanation
Server SetupnetworkRPC: The URL for the Soroban testnet.server: A new instance ofrpc.Serveris created, which will be used to interact with the Soroban testnet.networkPassphrase: sets the network passphrase to the TESTNET
DeployStellarAssetContract function
- 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
JOEBOYand the issuer’s public key. - Transaction Building: A transaction is built using the
TransactionBuilder, which includes thecreateStellarAssetContractoperation 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
submitTxfunction to ensure it has succeeded. Then, it extracts the return value and converts it to a contract ID usingStellarSdk.Address. Finally, it logs the contract ID for the deployed asset.