Ler blog em Português

Creating custom assets with Stellar

Read in 5 minutes


If you’re watching the crypto space, you probably know about Stellar. Stellar is an open network for storing and moving money. You can easily create, send and trade digital representations of all forms of money by using a feature called assets.

Assets are, essentially, custom tokens. Any person can create an asset in just a few steps, and in this article we’ll create one called ACME. Let’s get this started!

Understanding assets

Assets are identified by a code and a Stellar account public key. This identifier is what you use to look up or interact with it on the Stellar network. An asset identifier must be unique (i.e. both code and public key must be unique); you can have multiple assets representing US dollars or Bitcoins using the same code (USD and BTC), but not the same code plus public key.

Let’s say both Binance and Coinbase want to issue Bitcoin assets on the Stellar network; Binance’s asset could be something like BTC:GAAA...BINANCE, and Coinbase’s asset could be BTC:GAAA...COINBASE.

Ultimately, is up to the user to decide which representation is more trustworthy, but a product/service can also make a decision for users based on partnerships; Vibrant uses Stablex’s ARST for Argentine Pesos and Circle’s USDC for US Dollar.

An asset is often used to represent something outside Stellar’s network like fiat currency, bonds, gold, etc, but it can be used to represent pretty much anything, like other crypto currencies, reward points or karma (like in Reddit).

Creating your custom asset

The process of creating a custom asset is fairly simple.

  1. You need two accounts; one to issue the asset, one to distribute the asset.
  2. To receive the asset, accounts must add a trustline, which is a way of saying “I want to receive/hold this asset”. So, your distribution account must have this trustline established as well.
  3. The issuer account sends a payment with the info that defines the asset to the distribution account.
  4. The distribution account distributes the asset to any account that have a trustline.
  5. That’s it!

As you can see, the process is fairly straightforward. One thing most people don’t understand is that, in practice, there’s no “create asset” step. Basically, anyone can send custom assets to anyone as long as the receiving account have a trustline established.

Technically speaking, we don’t really need to have two separate accounts (issuer and distribution), but that’s a good rule to live by. Sometimes, it’s also a requirement; maybe you want to issue a limited number of assets and, in this case, you’ll need to set the issuer’s signature weight to zero, locking the account and preventing any additional issuance.

The easiest way of issuing a new asset is by using Stellar’s Laboratory. For the purpose of this article, we’ll create the asset on the Testnet, so you don’t need to have any Stellar Lumens (XLM). To create an asset on the public network, the process is virtually the same; just grab some Stellar Lumens (XLM) required to create the accounts and establish the trustlines.

Setting up accounts

First, let’s create the issuer account (i.e. the account that “owns” the asset). Visit https://laboratory.stellar.org and make sure you have the Testnet selected. Under “Create Account”, hit the “Generate keypair” button to create a new Stellar account. It’s your responsibility to keep your private key safe, so use something like a password manager.

Copy the public key and paste it under the Friendbot section, then hit the “Get test network lumens” button. This step will effectively create your account on the Stellar network.

Create the issuer account

If you visit https://horizon-testnet.stellar.org/accounts/GAGGA4J6MH6JUBUVAUELGVNR7HNH3BWSN7GJHYJUFZPS655TNOCXDIST, you can see that the account now exists on the network. Alternatively, you can use the “Explore Endpoints” tab of the Laboratory.

Notice that the testnet is reset from time to time, so you may receive a page not found back if you visit any of the urls mentioned in this article.

Repeat the same process, now for your distribution account.

Create the distribution account

Again, you can check that the account exists on the network by visiting https://horizon-testnet.stellar.org/accounts/GBNXJNCPQQZPWRRSMUEXGNTIOZU7FBDVT62WHA6WM6VOFW3YE56ISSUE.

Now that both accounts have been created, we need to make sure the distribution account is ready to receive ACME:GBNXJNCPQQZPWRRSMUEXGNTIOZU7FBDVT62WHA6WM6VOFW3YE56ISSUE. This is done by establishing a trustline.

Understanding Trustlines

Trustline is simply a mechanism to say that an account can receive an asset. By default, all Stellar accounts can only receive Stellar Lumens (XLM), the native asset. Any other asset will require a trustline. Given that trustlines are opt-in, Stellar accounts won’t be filled with spam transactions for assets that won’t ever be used.

Each trustline increases the required account balance by one base reserve, currently set to 0.5 XLM. This means that any account will need two base reserves (required to create the account on the network) plus 0.5 XLM for each trustline. There are other things that may increase the minimum balance required for an account, so make sure you read the Minimum Balance documentation.

Establishing trustlines

To receive the asset ACME:GBNXJNCPQQZPWRRSMUEXGNTIOZU7FBDVT62WHA6WM6VOFW3YE56ISSUE, users will need a trustline. Go to Laboratory’s Build Transaction and paste the account’s public key. In this case, we’re going to set up the distribution account GAGGA4J6MH6JUBUVAUELGVNR7HNH3BWSN7GJHYJUFZPS655TNOCXDIST.

Adding trustline to distribution account

You’ll be redirected to the Transaction Signer. Paste your private key (the one that starts with a S) and click “Submit in Transaction Submitter”.

Signing trustline transaction for distribution account

Now, you’ll be able to review the transaction. To submit it, click “Submit Transaction”.

Submit trustline transaction from distribution account

The distribution account is all set up to receive ACME:GBNXJNCPQQZPWRRSMUEXGNTIOZU7FBDVT62WHA6WM6VOFW3YE56ISSUE. Now, all we need to do is sending some ACMEs from the issuer account to the distribution account.

Go to the tab “Build Transaction” and paste the issuer account’s public key (GBNXJNCPQQZPWRRSMUEXGNTIOZU7FBDVT62WHA6WM6VOFW3YE56ISSUE), then click “Fetch next sequence number for account starting with…”. Click “Sign in Transaction Signer”.

Send payment from issuer to distribution account

Paste the issuer’s private key, then click “Submit in Transaction Submitter”.

Sign payment transaction from issuer to distribution account

Finally, submit the transaction.

Submit payment transaction from issuer to distribution account

That’s it! If you visit https://horizon-testnet.stellar.org/accounts/GAGGA4J6MH6JUBUVAUELGVNR7HNH3BWSN7GJHYJUFZPS655TNOCXDIST you can see that the account now have an entry under “balances” with 1,000,000 ACME.

Distribution account with 1,000,000 ACME

Anyone willing to receive this asset would have to go through this process and establish a trustline. Some wallets like LOBSTR abstracts this process, making it very user friendly.

Exercise: Create another account, and send some tokens from the distribution account to it. Remember, the account needs to establish a trustline to ACME:GBNXJNCPQQZPWRRSMUEXGNTIOZU7FBDVT62WHA6WM6VOFW3YE56ISSUE.

Wrapping up

As you can see, creating new assets on the Stellar network is a very simple process. Obviously, there are other aspects you need to consider, like how users will redeem their assets in the real world, but that’s more of an operational process, and even more important than issuing the assets on the Stellar network.

Stellar is one of the most developer-friendly blockchains out there. It’s fast, and very cheap, especially when compared to networks like Ethereum or Bitcoin.

Make sure you check out the official documentation, where you can find more info about the Stellar network and its features.