Skip to main content

Issue an Asset Tutorial

In this tutorial, we will walk through the steps to issue an asset on the Stellar test network.

Prerequisites

You must ensure you have the required amount of XLM to create your issuing and distribution accounts and cover the minimum balance and transaction fees. If you’re issuing an asset on the testnet, you can fund your account by getting test XLM from friendbot. If you’re issuing an asset in production, you will need to acquire XLM from another wallet or exchange.

If you’d like to avoid your users having to deal with transaction fees, consider using fee-bump transactions. Read more in our Fee-Bump Transaction Encyclopedia Entry.

Learn about the testnet and pubnet in our Testnet and Pubnet section.

Learn more about fees in our Fees, Surge Pricing, and Fee Strategies section.

1. Create issuing account and an object to represent the new asset

const issuerKeypair = StellarSdk.Keypair.random()const astroDollar = new StellarSdk.Asset(‘AstroDollar’, issuerKeypair.publicKey()

2. Create distribution account

Although it is not required to create a distribution account, it is best practice, so we will do so in this example. Read more in our Issuing and Distribution Accounts section.

// This generates a random keypairconst distributorKeypair = StellarSdk.Keypair.random()// This loads a keypair from a secret key you already haveconst distributorKeypair = StellarSdk.Keypair.fromSecret(SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4

3. Establish trustline between the two

An account must establish a trustline with the issuing account to hold that account’s asset. This is true for all assets except for Stellar’s native token, XLM.

Read more about trustlines in the Trustlines section.

If you’d like to avoid your users having to deal with trustlines or XLM, consider using sponsored reserves. Read more in our Sponsored Reserves Encyclopedia Entry.

const server = new StellarSdk.Server("https://horizon-testnet.stellar.org");const account = await server.loadAccount(distributorKeypair.publicKey());const transaction = new StellarSdk.TransactionBuilder(account, {  fee: StellarSdk.BASE_FEE,  networkPassphrase: StellarSdk.Networks.TESTNET,})  // The `changeTrust` operation creates (or alters) a trustline  // The `limit` parameter below is optional  .addOperation(    StellarSdk.Operation.changeTrust({      asset: astroDollar,      limit: "1000",      source: distributorKeypair.publicKey(),    }),  );

4. Make a payment from issuing to distribution account, issuing the asset

The payment operation is what actually issues (or mints) the asset.

const transaction = new StellarSdk.TransactionBuilder(...)  // The `payment` operation sends the `amount` of the specified  // `asset` to our distributor account  .addOperation(StellarSdk.Operation.payment({    destination: distributorKeypair.publicKey(),    asset: astroDollar,    amount: '1000',    source: issuerKeypair.publicKey()  }))

5. Optionally , lock the issuing account down so the asset’s supply is permanently fixed

Warning! This section details how to lock your account with the purpose of limiting the supply of your issued asset. However, locking your account means you’ll never be able to do anything with it ever again- whether that’s adjusting signers, changing the home domain, claiming any held XLM, or any other operation. Your account will be completely frozen.

Learn more about asset supply in our section on Limiting the Supply of an Asset

const transaction = new StellarSdk.TransactionBuilder(...)  // This (optional) `setOptions` operation locks the issuer account  // so there can never be any more of the asset minted  .addOperation(StellarSdk.Operation.setOptions({    masterWeight: 0,    source: issuerKeypair.publicKey()  }))

Note that you’ll want to make sure you publish information about your asset to establish trust with your users. Learn how to do so with our Publish Information About Your Asset section.

Full Code Sample

var StellarSdk = require("stellar-sdk");var server = new StellarSdk.Server("https://horizon-testnet.stellar.org");// Keys for accounts to issue and receive the new assetvar issuingKeys = StellarSdk.Keypair.fromSecret(  "SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4",);var receivingKeys = StellarSdk.Keypair.fromSecret(  "SDSAVCRE5JRAI7UFAVLE5IMIZRD6N6WOJUWKY4GFN34LOBEEUS4W2T2D",);// Create an object to represent the new assetvar astroDollar = new StellarSdk.Asset("AstroDollar", issuingKeys.publicKey());// First, the receiving account must trust the assetserver  .loadAccount(receivingKeys.publicKey())  .then(function (receiver) {    var transaction = new StellarSdk.TransactionBuilder(receiver, {      fee: 100,      networkPassphrase: StellarSdk.Networks.TESTNET,    })      // The `changeTrust` operation creates (or alters) a trustline      // The `limit` parameter below is optional      .addOperation(        StellarSdk.Operation.changeTrust({          asset: astroDollar,          limit: "1000",        }),      )      // setTimeout is required for a transaction      .setTimeout(100)      .build();    transaction.sign(receivingKeys);    return server.submitTransaction(transaction);  })  .then(console.log)  // Second, the issuing account actually sends a payment using the asset  .then(function () {    return server.loadAccount(issuingKeys.publicKey());  })  .then(function (issuer) {    var transaction = new StellarSdk.TransactionBuilder(issuer, {      fee: 100,      networkPassphrase: StellarSdk.Networks.TESTNET,    })      .addOperation(        StellarSdk.Operation.payment({          destination: receivingKeys.publicKey(),          asset: astroDollar,          amount: "10",        }),      )      // setTimeout is required for a transaction      .setTimeout(100)      .build();    transaction.sign(issuingKeys);    return server.submitTransaction(transaction);  })  .then(console.log)  .catch(function (error) {    console.error("Error!", error);  });