An open API service indexing awesome lists of open source software.

https://github.com/net2devcrypto/solana-spl-program-tutorial

How to write Solana SPL Token Programs to launch your own token on the Solana blockchain.
https://github.com/net2devcrypto/solana-spl-program-tutorial

anchor anchor-lang blockchain solana spl spl-token spl-token-2022

Last synced: 6 months ago
JSON representation

How to write Solana SPL Token Programs to launch your own token on the Solana blockchain.

Awesome Lists containing this project

README

          

# Solana-SPL-Program-Tutorial

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.

Video 1

Video 2

Setup Anchor Development Environment Instructions

The steps below are compatible with Ubuntu 22.04

> [!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
>

Step 1 Dependencies

```shell
sudo apt-get update && sudo apt-get upgrade && sudo apt-get install -y curl pkg-config build-essential libudev-dev libssl-dev
```

Step 2 Install Rust

```shell
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```
Press Enter When Prompted.

Step 3 Install Solana CLI

```shell
sh -c "$(curl -sSfL https://release.solana.com/v1.18.14/install)"
```

Step 4 Update PATH (UBUNTU ONLY)

```shell
nano ~/.bashrc
```

Add this line to end of file:

```shell
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.

Step 5 Install NodeJS

```shell
curl -fsSL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh
```

```shell
sudo -E bash nodesource_setup.sh
```

```shell
sudo apt-get install -y nodejs
```

Verify Installation:

```shell
node -v
```

Step 6 Install Yarn

```shell
corepack enable
yarn init -2
```

Ignore Error: Internal Error: Process git failed to spawn

Step 7 Install Anchor

```shell
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
```

```shell
avm install latest
avm use latest
```

Verify Installation:

```shell
anchor --version
```

Step 8 Generate Dev Solana Wallet

```shell
solana-keygen new
```

Video 3

Deploy SPL Token Program

## Step 1 Build and Deploy SPL Program

A - Download Repo Folder SplToken

B - Create a new Anchor project named "spl"

```shell
anchor init spl
```

C - Open the spl project folder in VS Code

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.

```shell
[provider]
cluster = "devnet"
```

SAVE FILE!

G - Open terminal and proceed to build project then deploy.

```shell
anchor build
```

```shell
anchor deploy
```

H - Copy the program ID obtained once the deployment has completed.

I - Go to target/types/spl.ts and update the address with the program ID obtained after anchor deploy.

```shell
export type Spl = {
"address": "ENTERPROGRAMID",
```

SAVE FILE!

J - Go to target/idl/spl.json and update the address with the program ID obtained as well

```shell
{
"address": "ENTERPROGRAMID",
```

SAVE FILE!

K - Go to programs/src/lib.rs and update declareid with the program ID obtained as well

```shell
declare_id!("ENTERPROGRAMID");
```

SAVE FILE!

## Step 2 Create and Store Metadata in Arweave

Watch @ https://youtu.be/66o6qma2Jdc?t=3m40s

Copy the metadata.json Arweave path.

## Step 3 Initiate SPL Token and Mint

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.

```shell
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!

C - Open terminal and proceed to run test.

```shell
anchor test
```

## Step 4 Transfer Tokens to new Wallet from Owner Wallet

A - Copy the file spl-transfer.js from the downloaded SplToken folder and paste into the spl project folder

B - Open terminal and install solana/spl-token sdk

```shell
npm i @solana/spl-token
```

C - Obtain the private key of the program owner as string, copy the value

Watch @ https://youtu.be/66o6qma2Jdc?t=55m30s

D - Edit the spl-transfer.js with the following values

```shell
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!

E - Create new solana wallet (Phantom Wallet for example) and copy address

F - Add the new wallet address obtained previously to the spl-transfer.js as destination wallet

```shell
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!

```shell
node spl-transfer.js
```

Expected Result:

```shell
create ata txhash: 4uU9xegH7YZ3tTC934PBSzsVQf3pwoA5BWwXnpFpuK7aCTDu9yqK32r2Vjsbqz4vxhMReeL6NkmQ1hZPg3XSAXh8
Tokens transferred Successfully, Receipt: rttSvKXANuiTZkUmx1gj5B1jSH6bNz4NU64YmvqXouLYoWzqejot1NXxGrML7L87FWa2tX8WBDViKw8C5nmEZrC
```