Mint a custom SPL token on Solana devnet, deploy the Bonfida vesting program, and create a token vesting schedule with timed release using Chainstack.
TLDR:
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.
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:
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.
Set up the Solana tools suite with the Chainstack node
In your project directory, run:
solana config set --url YOUR_CHAINSTACK_ENDPOINT
where YOUR_CHAINSTACK_ENDPOINT is your Solana node endpoint. See View node access and credentials.You are now on the devnet, interacting with the network through your Chainstack node.
where ~/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.
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:
solana config set --keypair ~/wallet/keypair1.json
where ~/wallet/keypair1.json is the path to one of your wallets that you created earlier.Check that the default account is set:
solana address
Create a token:
spl-token create-token
The 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.
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.
where TOKEN_ADDRESS is the address of the token you created.Remember to switch between your accounts with the solana config set --keypair WALLET_PATH command.
Make sure you are on the account that created the token by running solana address.Mint the token:
spl-token mint TOKEN_ADDRESS 1000
where TOKEN_ADDRESS is the address of the token you created.This will mint 1,000 tokens to your account.Congratulations!At this point, you have the following:
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.
What you are going to do next is:
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.
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 the program/ directory and run:
cargo build-sbf
This will build the program bytecode that you can deploy to a Solana network. See also Solana documentation: Program overview.Deploy the program:
solana deploy PROGRAM_BYTECODE
This will run the deployment and return the address of the vesting program on the Solana devnet.
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.
If the tokens have an unreleased amount at a timestamp in the past, they will be released to the destination account.Check the token balance of a derived token account:
This tutorial guided you through the basics of creating a token using the default token program, deploying your own program, and interacting with the program on the Solana network.You also learned what programs and derived token accounts are.This tutorial uses the devnet, however, the exact same instructions and sequence will work on the mainnet as well.