🧪
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 8 : Use the native Stellar Lumens (XLM) the classic way.
  • 1. Introduction
  • 2. Check your XLM's own balance using the classic way
  • 3. Use our code
  • What is next?
Edit on GitHub
  1. Index

8 : Use the native Stellar Lumens (XLM) the classic way.

Previous7 : Mint from a wrapped token in Soroban.Next9 : Read the native token (XLM) using soroban-cli.

Last updated 1 year ago

Token Playground Chapter 8 : Use the native Stellar Lumens (XLM) the classic way.

  • Check this guide in

  • Edit this guide in it's repo:

  • Contribute to this guide in the 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 start using XLM, asking for our balance the classic way (without Soroban). In the next chapter we will use Soroban!

2. Check your XLM's own balance using the classic way

Let's do our first experiment with the native XLM contract. We will create a new account, fund it with friendbot and check our balance in the classic way.

0.- Run the quickstart.sh script and enter into the soroban-preview container. Read chapter 1 and 2.

bash quickstart.sh
bash run.sh

1.- Create a new account:

soroban config identity generate my-account
MY_ACCOUNT_ADDRESS="$(soroban config identity address my-account)"

2.- Fund it with friendbot. Here I'll assume you are inside the soroban-preview containter

SOROBAN_RPC_HOST="http://stellar:8000"
FRIENDBOT_URL="$SOROBAN_RPC_HOST/friendbot"
curl  -X POST "$FRIENDBOT_URL?addr=$MY_ACCOUNT_ADDRESS"

3.- Check your balance with the classic way Using javascript and node, and assuming that MY_ACCOUNT_ADDRESS="GC6IYOXRAGMVSUDCAHBGBP2ZCAMZVNIF7CZCBY6545EQMIDNQQZCOY5G"

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

server.loadAccount(user_address)
  .then(account => {
    // Find the XLM balance
    const xlmBalance = account.balances.find(balance => balance.asset_type === 'native');

    console.log(`Your XLM balance: ${xlmBalance.balance}`);
  })
  .catch(error => {
    console.error('Error loading account:', error);
  });

You'll get a result like this:

Your XLM balance: 10000.0000000

3. Use our code

You can run it by:

bash src/chapter8/use_XLM_native.sh 

Check all the code in the repo!

What is next?

In this chapter we created a new Stellar account and we fund it with 10000 XLM and we managed to check it's balance in the classic way. In the next chapter we will check its balance using smart contracts in Soroban!

Are you ready?


If you want to use our code in the , you can just call our script with the soroban-preview-10 docker containter

This Playground chapter has been written by

https://token-playground.gitbook.io/
https://github.com/esteblock/token-playground/
./docs folder
Token Playground's Repo
@esteblock