🧪
The Soroban's Token Playground
  • README
  • Index
    • 1: Introduction & Motivation.
    • 2 : Basic Concepts
    • 3 : Environment preparation
    • 4 : Issue and Mint Asset in Stellar.
    • 5: Get info about a token in Classic.
    • 6 : Wrap a token from Stellar Classic to Soroban.
    • 7 : Mint from a wrapped token in Soroban.
    • 8 : Use the native Stellar Lumens (XLM) the classic way.
    • 9 : Read the native token (XLM) using soroban-cli.
    • 10 : Write the native token (XLM) using soroban-cli.
    • 11 : Use the native token (XLM) inside a smart contract.
    • 12 : Identify a Stellar Classic Asset using stellar-sdk.
    • 13 : Wrap an asset using stellar-sdk.
Powered by GitBook
On this page
  • Token Playground Chapter 4 : Issue and Mint Asset in Stellar.
  • Introduction:
  • 1.- Trust Operation
  • 2. Issue Asset
  • 3. Use our code
  • 4. Next
Edit on GitHub
  1. Index

4 : Issue and Mint Asset in Stellar.

Previous3 : Environment preparationNext5: Get info about a token in Classic.

Last updated 1 year ago

Token Playground Chapter 4 : Issue and Mint Asset in Stellar.

  • Check this guide in

  • Edit this guide in it's repo:

  • Contribute to this guide in the of the repo

Introduction:

In this chapter we will show you how to issue (create) a Stellar Asset (classic) and mint the the first supply of it.

To issue and mint an asset you need to build and submit two transactions. The first one will to create a trustline for the asset between receiver and issuer address, this is a requirement. The second one will send a payment of the asset from issuer to receiver that effectivaly **will create and mint the asset by sending it+*.

Remember to follow the code in the . Also, you can clone the code by doing

git clone https://github.com/esteblock/token-playground/

1.- Trust Operation

Previous to the creation of the asset, the destination address is required to submit a transaction to the network that creates a trustline with the asset. In Stellar, this is a requirement to establish a trustline before receiving an asset that has not been received before.

Read more about trustlines in the

The transaction that will creates the trustline need to contains an operation Change Trust where the fields asset (asset code and issuer address) is required and the field trust limit is optional.

You can check the full code of this playground, on how to build build and submit this trust operation

Here we show you a fragment of this code, using the javascript StellarSdk package:


  var transaction = new StellarSdk.TransactionBuilder(receiver, {
        fee: 100,
        networkPassphrase: networkPassphrase,
    })
        // The `changeTrust` operation creates (or alters) a trustline
        // The `limit` parameter below is optional
        .addOperation(
        StellarSdk.Operation.changeTrust({
            asset: asset,
            limit: limit,
        }),
        )
        // setTimeout is required for a transaction
        .setTimeout(100)
        .build();
    console.log("trustAsset: Transaction built")
    transaction.sign(receivingKeys);
    console.log("trustAsset: Transaction signed, now will submit transaction")
    var submitResult = server.submitTransaction(transaction);
    console.log("trustAsset: Tx is being submitted, result: ", submitResult)
    return submitResult

2. Issue Asset

Once the destination address trust the asset, the issuer can create it. Issuing the asset consist in building and submit a transaction that contains a payment operation. The payment operation requires to set up the asset code,the issuer adress and the amount. This payment will create the token and mint the amount that the issuer sends to destination address.

Here we show you a fragment of this code, using the javascript StellarSdk package:

Here a fragment of this code:

var transaction = new StellarSdk.TransactionBuilder(issuer, {
    fee: 100,
    networkPassphrase: networkPassphrase,
  })
    .addOperation(
      StellarSdk.Operation.payment({
        destination: destination,
        asset: asset,
        amount: amount,
      }),
    )
    // setTimeout is required for a transaction
    .setTimeout(100)
    .build();
  console.log("sendPaymentFromIssuer: Signing the transaction")
  transaction.sign(issuingKeys);
  var submitResult = server.submitTransaction(transaction);
  console.log("sendPaymentFromIssuer: Tx is being submitted, result: ", submitResult)
  return submitResult

In the case the issuer addres is not locked, new amount of the asset can be minted. To mint the asset is as easy as create a new transanction with a payment operation. This operation will mint the asset incrementing the total supply of the asset.

3. Use our code

You can run it by:

  docker exec soroban-preview-10 node src/issueAsset.js

Also you can run it with a different asset code than the one in settings.json by passing it the ASSET_CODE argument.

  docker exec soroban-preview-10 node src/issueAsset.js ASSET_CODE
import settings from "../settings.json"  assert { type: "json" };

const args = process.argv;
const asset_code = args[2] || settings.assetCode;

...

var networkPassphrase = settings.networkPassphrase
var issuingKeys = StellarSdk.Keypair.fromSecret(settings.issuerSecret);
var receivingKeys = StellarSdk.Keypair.fromSecret(settings.receiverSecret);

...

As we have showed above you can pass the asset code as an argument when invoking the script.

4. Next


You can check the full code of this playground, on how to build build and submit the transaction with a payment operation

If you want to use our code, we prepared the script that can be called by the soroban-preview-10 docker container:

This script will send two transactions to the stellar futurenet or standalone chains, depend on your selection when launching .

This script will take the asset, issuer adress, receiver address, amount, network passphrase and limit amount allowed to be received by receiver address from the file.

In the we will use this docker containers in order to get info about the asset created in the current chapter

This Playground has been developed by in collaboration with from

https://token-playground.gitbook.io/
https://github.com/esteblock/token-playground/
./docs folder
Token Playground's Repo
Stellar's Trustlines section
in our trustAsset.js script
in our sendPaymentFromIssuer.js script
Token Playground's Repo
src/issueAsset.js
quicktart.sh
seetings.json
next chapter
@esteblock
@marcos74
@Dogstarcoin