5: Get info about a token in Classic.
Token Playground Chapter 5: Get info about a token in Classic.
Check this guide in https://token-playground.gitbook.io/
Edit this guide in it's repo: https://github.com/esteblock/token-playground/
Contribute to this guide in the ./docs folder 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 previous chapter.
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 Token Playground's Repo. Also, you can clone the code by doing
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.
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:
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
If you want to use our Token Playground's Repo code, we prepared the src/getInfo.js script that can be called by the soroban-preview-10
docker container:
You can run it by:
Also you can run it with a different asset code than the one in settings.json by passing it as argument:
This script uses the stellar sdk to request to horizon api about asset info. Stellar sdk is a javascript library from stellar that offers a layer API for Horizon endpoints and facilities building, signing and submiting transactions.
Here, you'll find a fragmet of the code that exemplifies how stellar sdk access to horizon asset endpoint.
3. Next
In the next chapter we will wrap this asset from the classic Stellar blockchain into a Soroban smart contract. Are you ready?!
This Playground has been developed by @esteblock in collaboration with @marcos74 from @Dogstarcoin
Last updated