🧪
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 5: Get info about a token in Classic.
  • Introduction:
  • 1. Get info about a token from stellar
  • 2. Use our code
  • 3. Next
Edit on GitHub
  1. Index

5: Get info about a token in Classic.

Previous4 : Issue and Mint Asset in Stellar.Next6 : Wrap a token from Stellar Classic to Soroban.

Last updated 1 year ago

Token Playground Chapter 5: Get info about a token in Classic.

  • 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 get info about the asset that we have created and minted in the .

The Horizon sever provides an HTTP API to request data in the stellar network, providing several endpoints. One of them allow us to request assets info. Our code uses the Stellar SDK sends request to these endpoints.

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

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

1. Get info about a token from stellar

Asset information are stored in stellar ledgers. In order to facitilate the access to the data, stellar provides the Horizon API with several endpoints. Here we show you the endpoint URL with the query string to request an asset info.

https://horizon-testnet.stellar.org/assets?asset_code=ASSET_CODE&asset_issuer=ISSUER_ADDRESS

The query string includes two parameters, one is the asset_code and one is the asset_issuer. This request will return the info of a single asset as reponse.

An answer looks like this:

Futurenet Classic Info: 
{
  _links: { toml: { href: '' } },
  asset_type: 'credit_alphanum12',
  asset_code: 'MYASSETCODE',
  asset_issuer: 'GAM5XOXRUWPMKENBGOEAKMLRQ4ENHLHDSU2L2J7TVJ34ZI7S6PHMYIGI',
  paging_token: 'MYASSETCODE_GAM5XOXRUWPMKENBGOEAKMLRQ4ENHLHDSU2L2J7TVJ34ZI7S6PHMYIGI_credit_alphanum12',
  num_accounts: 1,
  num_claimable_balances: 0,
  num_liquidity_pools: 0,
  amount: '5.0000000',
  accounts: {
    authorized: 1,
    authorized_to_maintain_liabilities: 0,
    unauthorized: 0
  },
  claimable_balances_amount: '0.0000000',
  liquidity_pools_amount: '0.0000000',
  balances: {
    authorized: '5.0000000',
    authorized_to_maintain_liabilities: '0.0000000',
    unauthorized: '0.0000000'
  },
  flags: {
    auth_required: false,
    auth_revocable: false,
    auth_immutable: false,
    auth_clawback_enabled: false
  },
  toml: [Function (anonymous)]
}

In the response you'll find relevant info about the asset as:

-asset code MYASSETCODE

-asset issuer GAM5XOXRUWPMKENBGOEAKMLRQ4ENHLHDSU2L2J7TVJ34ZI7S6PHMYIGI

-amount issued 5.0000000

2. Use our code

You can run it by:

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

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

 docker exec soroban-preview-10 node src/getInfo.js ASSET_CODE

Here, you'll find a fragmet of the code that exemplifies how stellar sdk access to horizon asset endpoint.


import StellarSdk from "stellar-sdk";

....

var server = new StellarSdk.Server(settings.horizonUrl, {allowHttp: true});

console.log("Futurenet Classic Info: ")
console.log((await server.assets().forCode(asset_code).call()).records[0])

3. Next


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

This script uses the stellar sdk to request to horizon api about asset info. is a javascript library from stellar that offers a layer API for Horizon endpoints and facilities building, signing and submiting transactions.

In the we will wrap this asset from the classic Stellar blockchain into a Soroban smart contract. Are you ready?!

This Playground has been developed by in collaboration with from

https://token-playground.gitbook.io/
https://github.com/esteblock/token-playground/
./docs folder
previous chapter
Token Playground's Repo
Token Playground's Repo
src/getInfo.js
Stellar sdk
next chapter
@esteblock
@marcos74
@Dogstarcoin