- This tutorial walks you through creating a token on Solana’s devnet, deploying an audited vesting program (Bonfida), and vesting your token.
- You’ll mint a custom SPL token, derive token accounts, deploy the vesting program with Rust, create a vesting schedule (amounts plus release times), and finally unlock tokens once they vest.
- Tools used include the Solana CLI, SPL token CLI, and cargo commands for building and deploying the vesting program.
- The exact procedure also applies to mainnet – just switch endpoints and make sure you have enough SOL for fees.
Main article
This tutorial guides you through creating a token, deploying a vesting program, and vesting the created token in the program instance on the Solana network. In short, you will do the following:- Create a token using the default token program.
- Deploy an audited vesting program.
- Vest the created token using the deployed vesting program.
Prerequisites
- Chainstack account to deploy a Solana node.
- Rust to work with the vesting program.
- Solana tool suite to create accounts and interact with the network.
- SPL token CLI to interact with the default token program.
Overview
To get from zero to your own instance of vested tokens on the devnet, do the following:- With Chainstack, create a public chain project.
- With Chainstack, join Solana devnet.
- With Chainstack, access your Solana node credentials.
- Set up the Solana tool suite to work through your Chainstack-managed devnet node.
- With the Solana tool suite, generate two accounts—the account that will deploy the program and vest the tokens and the account that will receive the tokens.
- Fund the generated accounts with devnet SOL through a faucet .
- Create a token.
- Derive token accounts for the two created accounts.
- Mint the token.
- Deploy a vesting program.
- Create a vesting instance.
- Check the vesting instance state.
- Release the vested tokens.
Step-by-step
Create a public chain project
See Create a project.Join the devnet
See Join a public network.Get your Solana node access and credentials
See View node access and credentials.Set up the Solana tools suite with the Chainstack node
In your project directory, run:Generate two accounts
In your project directory, run:~/wallet/keypair.json
is any directory and name to store your wallet as a password-protected JSON file.
Make sure you generate two accounts: one account will create and hold the tokens, the other account will be the destination for the vested tokens.
Fund the accounts
Both accounts need to pay fees to run transactions on the network. Fund each of the created accounts with the faucet.Create a token
At this point, you have two funded accounts, but none of the accounts is set as the default signer for operations. Set one of the accounts as the default signer:~/wallet/keypair1.json
is the path to one of your wallets that you created earlier.
Check that the default account is set:
create-token
command will call the default token program on the devnet through your Chainstack node and return the address of your new token.
The token has the default 9 decimals.
Derive token accounts for the token
Before you operate with the created token, and even before you can mint it, you must derive a token account for each of the accounts for the created token. In brief:- At this point, you have two accounts. You funded the accounts with the devnet SOL. Each of the accounts can only hold SOL.
- To be able to hold the tokens, each of the accounts must derive the token account from the main account address and the token address.
solana config set --keypair WALLET_PATH
command.
Mint the token
Make sure you are on the account that created the token by runningsolana address
.
Mint the token:
- A token created through the default token program on the Solana devnet
- Two main accounts funded with SOL
- Two token accounts mapped to the two main accounts and associated with your created token
- One of the token accounts holds 1,000 9-decimal units of your created token and the other token account holds nil.
- Deploy a custom vesting program on the devnet.
- Use the deployed program to create a vesting instance.
- Via the vesting instance, you will transfer an amount of tokens from the token account that holds 1,000 tokens to the token account that holds no tokens.
Deploy the vesting program
You are going to deploy the audited Bonfida vesting program—the go-to vesting program for many projects on Solana. Note that you are going to deploy the program for tutorial purposes as, similar to the token program, you would normally need just the address of the deployed program to create your own instance of the program. In other words, you do not need to deploy a program every time you need a separate instance of it with your program parameters. In your project directory, clone the token vesting repository. Change to theprogram/
directory and run:
Create a vesting instance
You need to build the CLI tools to interact with the program and create a vesting instance. Change to thecli/
directory and run:
- YOUR_CHAINSTACK_ENDPOINT — your Solana node endpoint. See View node access and credentials.
- PROGRAM_ADDRESS — the address of the vesting program that you deployed on the devnet.
- TOKEN_ADDRESS — the address of the token that you created.
- SOURCE_WALLET_PATH — path to the wallet file of the account that holds the tokens.
- SOURCE_ACCOUNT_TOKEN_ADDRESS — the derived token account that holds the tokens.
- DESTINATION_ACCOUNT_TOKEN_ADDRESS — the derived token account to which the tokens will be released.
- AMOUNT — the amount of tokens to release in base form. For example, 1 unit of the default 9-decimal token is
1000000000
. - TIME — the timestamp in Unix format when the vested amount becomes releasable.
C1Swjv4cQ2nEujJ4QeYDBsWSuSVPRXX4QkrtmF6UtdJK
to become releasable:
- 1 unit on January 31, 2022, 00:00:00 UTC.
- 2 units on February 28, 2022, 00:00:00 UTC.
Check the vesting instance
You can check the state of the vesting instance to see the predefined release times and the amounts remaining to be released. Check the vesting state:- YOUR_CHAINSTACK_ENDPOINT — your Solana node endpoint. See View node access and credentials.
- PROGRAM_ADDRESS — the address of the vesting program that you deployed on the devnet.
- SEED — the seed of the vesting instance that you received earlier.
Release the vested tokens
Anyone on the network willing to pay the release transaction fee can call the release of the tokens. Call the release of tokens:- ENDPOINT — your Solana node endpoint. See View node access and credentials.
- PROGRAM_ADDRESS — the address of the vesting program that you deployed on the devnet.
- WALLET_PATH — path to any wallet that you have unlocked locally. Anyone can call the release of tokens.
- YOUR_CHAINSTACK_ENDPOINT — your Solana node endpoint
AcFTnytDRgQhdKK5QSxjAByjcwz5jaUnkTQG6FK5F7bP
— the derived token account that can hold the tokens