How does one go about creating tokens on the Stellar network?
5 Answers
It's explained in Issuing Assets article in developer's portal.
The process looks like this:
- Create an issuing account (let's call it account A)
- From any other account (let's call it B) create a trust line by sending
change_trust
operation. Theasset
value should have the code of the asset you want to issue (ex.TOKEN
) and issuer should be equal the account A from point 1. - Now any
payment
from A to B sending a custom asset equal to the asset from a trust line from point 2 will create a new asset in the network.
Optionally you can setup another account as the holding or distributor account and have this account make payments and offers involving the asset.
This way the issuer account can be locked away in cold storage so no more tokens can be created without physical access.
-
1
-
Hm, i have question. On #8 what do you mean Create and Fund, can u elaborate more.. thanks Jul 6, 2018 at 14:31
-
In addition to my question sir, when Distributor send payment operation to Wonderer B, Wonderer C. They will both receive a ROCKT asset. But the Distributor account his/her ROCKT will get decremented or remained as is? thanks. Jul 6, 2018 at 15:29
-
@ArmanOrtega sorry missed your comments #8 create and fund was from a side project and not relevant. It was about sending many accounts some portion of the ROCKT. Yes when the Distributor makes a transfer, her account balance will be decremented.– swidnikkJan 17, 2019 at 21:54
https://stellar.army - see second tab. The code is also opensourced, see the github link on top right.
Note that you can do this on the commandline using Lumen. Here's an example to create the HAK
token on the testnet.
# Create accounts for issuer and distributor
$ lumen account new issuer
$ lumen account new distributor
$ lumen friendbot issuer
$ lumen friendbot distributor
# Create a trustline from distributor to the HAK token, issued by issuer.
$ lumen trust create distributor HAK:issuer
# Distribute 1000 HAK tokens
$ lumen pay 1000 HAK:issuer --from issuer --to distributor
# Kill the issuer's account so no more HAK tokens can be created.
$ lumen signer masterweight issuer 0
# The distributor is now free to distribute 1000 HAKs
$ lumen balance distributor HAK:issuer
# Output: 1000.0000000
-
Using this commandline how does the distributor move the asset HAK to another account ? Jul 10, 2018 at 8:37
var assetName = 'testAsset'; var testAsset = new StellarSdk.Asset(assetName, issuerPublicKey);
- changeTrust operation.
//accounts.secret = secretkey of any account other than issuer to get trusted for testAsset var receivingKeys = StellarSdk.Keypair .fromSecret(accounts.secret); server.loadAccount(receivingKeys.publicKey()) .then(function (receiver) { var transaction = new StellarSdk.TransactionBuilder(receiver) // The
changeTrust
operation creates (or alters) a trustline // Thelimit
parameter below is optional .addOperation(StellarSdk.Operation.changeTrust({ asset: testAsset, limit: '1000' })) .build(); transaction.sign(receivingKeys); server.submitTransaction(transaction);
do step (4) for 2 accounts
fund these accounts with testAsset using issuer account
app.get('/transferTestAsset', async function (req, res) { var amt = '100'; var sourceSecretKey = issuerSecretKey; // seed of acc from which tx process var sourcePublicKey = sourceKeypair.publicKey();//pub key of source acc var receiverPublicKey = account5.publicKey;// public key of reciever acc StellarSdk.Network.useTestNetwork(); const account = await server.loadAccount(sourcePublicKey) var transaction = new StellarSdk.TransactionBuilder(account) .addOperation(StellarSdk.Operation.payment({ destination: receiverPublicKey, asset: testAsset,//native asset lumen amount: amt, })) .addMemo(StellarSdk.Memo.text('coins sent testAsset'))//optional .build(); transaction.sign(sourceKeypair); console.log('tx signed'); const temp = await server.submitTransaction(transaction) });
now do step 6 for accounts other than issuer , accounts which trusted the issuers testAsset can recieve the testAsset
go to here and check the transactions