9 : Read the native token (XLM) using soroban-cli.
Token Playground Chapter 9 : Read the native token (XLM) using soroban-cli
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
1. Introduction
What about when we want to use XLM inside a Soroban smart contract? How do we trigger those transactions? Can we trigger transactions on behalf the user using the require_auth method?
In this chapter we will use our XLM inside Soroban using soroban-cli!
2. The native Stellar Lumens (XLM) contract address
Soroban is great! And in order to use the native XLM tokens, we just need to treat it as another asset that behaves as an Stellar Asset Contract (SAC). It indeed has it's own contract address.
We will call this the native token address
This contract address is unique per network (standalone, futurenet... as well as it will later be with testnet and mainnet), so be sure to call it correctly.
Set up your environment: Basic setup
NETWORK="standalone"
SOROBAN_RPC_HOST="http://stellar:8000"
SOROBAN_RPC_URL="$SOROBAN_RPC_HOST/soroban/rpc"
FRIENDBOT_URL="$SOROBAN_RPC_HOST/friendbot"
SOROBAN_NETWORK_PASSPHRASE="Standalone Network ; February 2017"
echo Adding network
soroban config network add "$NETWORK" \
--rpc-url "$SOROBAN_RPC_URL" \
--network-passphrase "$SOROBAN_NETWORK_PASSPHRASE"In order to wrap any token you'll need to spend some XLM. So you need to call this function from a funded account:
Set your identity:
Wrap the native token: In order to get the XLM "contract address" you first need to "wrap" the native asset it into a token inside Soroban. This can be done only once, but you'll be needing to do it each time you open a new Standalone instance.
However,
If you use only Futurenet, you'll probably never need to do this:
This command will return the address, so no need for the next step. If this commands fails, this means that the token has already been wrapped before :)
Get the native token's contracts address: Once the native token has been wrapped, you can also it's address like this:
and you'll get
and for the case of futurenet you'll get:
3. Native token and Token Interface
So, can we use this address as if it was any other token that complies with the token interface?
Yes! So let's do it.
Implementing the token intrface means that the contract will have the following functions: (please take a look at the link above)
4. Check your balance using soroban-cli and the native token's contract address.
We have the native token's address and the functions names we can call. We just need to call it!
0.- Set your environment. Here we suppose that you are using the soroban-preview:10 image as it was explained in previous chapters:
1.- Create a soroban-cli identity
2.- Fund this identity with the friendbot
3.- Ask your balance to the native token's contract:
You should have an answer like this one:
6. Asking other things:
7. Use our code
If you want to use our code in the Token Playground's Repo, you can just call our script with the soroban-preview-10 docker containter
You can run it by:
Check all the code in the repo!
What is next?
In this chapter we wrapped the native token, read it's address, generated a token WASM and interacted with these using soroban-cli in order to read some information about the native asset (balance, name)!
In the next chapter we'll use this contract address in order to send some XLM!
Are you ready?
This Playground chapter has been written by @esteblock
Last updated