Introduction to Solana and the spl-token command line
This article is an introduction to the Solana ecosystem, the Solana Tool Suite and the spl-token command-line utility. It was made by following the Moralis course: Solana Programming 101
- Create your own key with the command line
- Create your own key with Phantom
- Operation on token with the cli
If you want to explore Solana more, I have written 2 other articles: Solana Core Concept & Solana Programs - Basic Security with Anchor
[TOC]
Installation
You can install Solana in your OS by following the official installation guide: https://docs.solana.com/cli/install-solana-cli-tools
Key generation
The first thing to do is to create a pair of public/private keys.
When you use the spl-token command line, this generated key will be used
- Key generation
solana-keygen new --force
My result: Wrote new keypair to /home/
My public key is BgAoyQvL1ejQNrj4BewgJxfTHZ2cLjgxq8tza5oTcxyK
- Getting the public key of a wallet
solana-keygen pubkey
Install spl-token-cli
The spl-token command-line utility can be used to experiment with SPL tokens.
You can find the documentation here: https://spl.solana.com/token
- Install the cli tools
cargo install spl-token-cli
During the installation, it is possible you have some errors with libudev. You can find more information with this link: stackoverflow.com - libudev-development-package-not-found
the solution for me was to install libudev with this command:
sudo apt-get install libudev-dev
Airdrop
To perform operations, you need to have some SOL in your wallet. It is possible to have some SOL on devnet with the command airdrop
- Command
solana airdrop 1 --url devnet
- Checking the balance
solana balance --url devnet
- Screenshot
There is a limitation on the number of SOL you can obtain. It is currently one by call
On the screenshot below, you can see the balance is unchanged.
Spl-token
Creating a token
spl-token create-token -url devnet
The address of the token is: H3goZSZ99PjQCBmFqy93jX683G3hgSE1BSnyY5DBEvws
Solana explorer
Information about the token on Solana explorer:
Create an account
Account in a wallet holds a token. Accounts must be created within wallets
Reminder: In Solana, everything is an account
spl-token create-account <TOKEN_ADDRESS> --url devnet
The returned id is the token account address
There is one account by token. An error is generated if you try to create a second account
Solana explorer
Mint
spl-token mint <TOKEN_ADDRESS> <NUMBER> --url devnet
- Check the balance
spl-token balance H3goZSZ99PjQCBmFqy93jX683G3hgSE1BSnyY5DBEvws --url devnet
- Check the supply
spl-token supply H3goZSZ99PjQCBmFqy93jX683G3hgSE1BSnyY5DBEvws --url devnet
Solana explorer
Check on Solana explorer
Link: explorer.solana.com - tx
Disable authorization
- Renouncing the ability to mint tokens:
spl-token authorize <TOKEN_ADDRESS> mint --disable --url devnet
- Check the result:
Burn token
Only our own tokens can be burned
spl-token burn <ACCOUNT_ADDRESS> <number> --url devnet
Send token to another account
You can create a second account with phantom wallet to test this command
spl-token transfer <SOURCE_TOKEN_ADDRESS> <AMOUNT> <TARGET_TOKEN_ADDRESS> --url devnet --fund-recipient
Without the fund-recipient flag, you’d not be able to add balance to an unfunded address
Transfer token to a phantom wallet
For the next test, I created a new token with an account because I had revoked the authorizations for the previous one (not very smart haha)
Token address: EHNLcqxdBLGGMwqVSR3tf1PsSo6HxNgxftD4j3wnHNQL
Account: 2dWvomUHStpCZbdVfLvxKC4neJmUYNEaozpru65kfHyH
- Add the token to Phantom
- Transfer some tokens to the phantom wallet
We transfer some tokens
Solana explorer
See on Solana explorer: explorer.solana - tx
References
Main references are:
- SOLANA-LABS, 2022a. Token Program. Solana Program Library. Online. 2022. [Accessed 3 August 2022]. Retrieved from: https://spl.solana.com/token
- SOLANA-LABS, 2022b. Install the Solana Tool Suite. Solana Documentation. Online. 2022. [Accessed 3 August 2022]. Retrieved from: https://docs.solana.com/cli/install-solana-cli-tools
- ZSOLT NAGY, no date. Solana Programming 101. Moralis academy. Online. [Accessed 3 August 2022]. Retrieved from: https://academy.moralis.io/courses/solana-programming-101