A highly requested tutorial! We are covering from start to finish how to write Solana SPL Token Program to launch your own token on the Solana blockchain.
Note
THE FILES ATTACHED TO THIS REPO ARE FOR EDUCATIONAL PURPOSES ONLY. NOT FINANCIAL ADVICE USE IT AT YOUR OWN RISK, I'M NOT RESPONSIBLE FOR ANY USE, ISSUES.
Note
If you have Windows, please download VMware Workstation Player, install then create a virtual machine. Follow the tutorial video for full guidance.
VMware Workstation Player for Windows: https://www.techspot.com/downloads/downloadnowfile/1969/?evp=4c50cf08866937ea246522b86f4d4286&file=2171
Ubuntu Desktop 22.04 ISO: https://releases.ubuntu.com/jammy/ubuntu-22.04.4-desktop-amd64.iso
sudo apt-get update && sudo apt-get upgrade && sudo apt-get install -y curl pkg-config build-essential libudev-dev libssl-dev
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Press Enter When Prompted.
sh -c "$(curl -sSfL https://release.solana.com/v1.18.14/install)"
nano ~/.bashrc
Add this line to end of file:
export PATH="/root/.local/share/solana/install/active_release/bin:$PATH"
save by : CTRL + X , Press Y, ENTER
Reboot PC.
Open back the terminal then confirm that Solana Cli is active by typing "solana" and press ENTER.
curl -fsSL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt-get install -y nodejs
Verify Installation:
node -v
corepack enable
yarn init -2
Ignore Error: Internal Error: Process git failed to spawn
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
avm install latest
avm use latest
Verify Installation:
anchor --version
solana-keygen new
anchor init spl
D - Replace the lib.rs file located in the programs/spl/src folder with the lib.rs file located in the downloaded SplToken folder
E - Replace the cargo.toml file located in the project programs/spl folder with the cargo.toml file located in the downloaded SplToken folder
F - Go to the Anchor.toml file located at the root of the project folder and change cluster to devnet.
[provider]
cluster = "devnet"
SAVE FILE!
anchor build
anchor deploy
I - Go to target/types/spl.ts and update the address with the program ID obtained after anchor deploy.
export type Spl = {
"address": "ENTERPROGRAMID",
SAVE FILE!
{
"address": "ENTERPROGRAMID",
SAVE FILE!
declare_id!("ENTERPROGRAMID");
SAVE FILE!
Watch @ https://youtu.be/66o6qma2Jdc?t=3m40s
Copy the metadata.json Arweave path.
A - Replace on spl project, the file tests/spl.ts with the spl.ts test file located in the downloaded SplToken folder
B - Edit the spl.ts test file by providing the token metadata with your values and amount to initially mint.
const metadata = {
name: "Net2Dev Rewards SPL",
symbol: "N2DR",
uri: "https://arweave.net/Xjqaj_rYYQGrsiTk9JRqpguA813w6NGPikcRyA1vAHM", //replace with Arweave metadata json path
decimals: 9,
};
const mintAmount = 10; // Amount of tokens to initially mint.
SAVE FILE!
anchor test
A - Copy the file spl-transfer.js from the downloaded SplToken folder and paste into the spl project folder
npm i @solana/spl-token
Watch @ https://youtu.be/66o6qma2Jdc?t=55m30s
const owner = 'REPLACEWITHSTRINGPRIVATEKEY' // private key string previously obtained
const spltoken = new PublicKey("SPLPROGRAMID"); // Program Id of your SPL Token, obtained during "anchor deploy"
const tokens = 2; // set the amount of tokens to transfer.
SAVE FILE!
const destWallet = new PublicKey("NEWWALLETADDRESS");
SAVE FILE!
G - Run the Test and confirm that the ATA got generated and you got tokens on the new destination wallet!
node spl-transfer.js
Expected Result:
create ata txhash: 4uU9xegH7YZ3tTC934PBSzsVQf3pwoA5BWwXnpFpuK7aCTDu9yqK32r2Vjsbqz4vxhMReeL6NkmQ1hZPg3XSAXh8
Tokens transferred Successfully, Receipt: rttSvKXANuiTZkUmx1gj5B1jSH6bNz4NU64YmvqXouLYoWzqejot1NXxGrML7L87FWa2tX8WBDViKw8C5nmEZrC