Sandbox is not supported on mobile, try on a computer
Solana is a high-performance blockchain platform that is renowned for its incredibly quick transaction times and inexpensive transaction costs, making it a great option for many different decentralized apps and projects.
In this exercise, we will start from basics and follow step-by-step explanations/instructions to do the following activities:
Solana CLI: Solana Command Line Interface utility allows users to interact with Solana networks. It can be used to perform various options like creating/managing keypairs, checking balance, transferring SOL, deploying smart contracts, and much more.
Solana Test Validator Docker Image: Docker image that runs a local Solana network on your local machine or in our sandbox . The validator node validates and processes transactions, maintains consensus, and secures the network. A public network is required to have thousands of validators. However, in a private network few nodes are sufficient. And, in a test network like ours, even one is enough.
Keypair: A keypair consists of a public key and a private key. The public key (or the account address) is used to receive funds, while the private key is used to sign transactions. Hence, while the public key is not confidential information (ignoring the privacy aspect), the private key needs to be protected. We will generate two key pairs in this exercise.
Relevant Resources:
Here are some more relevant resources for your reference:
Step 1: We will deploy a local Solana network and then use Solana CLI to interact with it.
Step 2: Solana CLI is already installed in the lab and you can easily install it on your machine by using the commands provided in the Solana documentation.
Step 3: Check the version of Solana utility to ensure it is installed.
Step 4: Generate a new keypair and save it in id.json file. A keypair consists of a public key and a private key. The public key is used to receive funds, while the private key is used to sign transactions. So, keep this file secure.
Step 5: Run Solana test validator Docker image to start the local Solana network. We are naming it 'solana-validator' and binding ports 8899,8900 and 8901 to local machine. We are also mounting current directory inside it so it can read the keypair.
Step 6: Check if the 'solana-validator' container is running.
Step 7: [Optional] Open a new terminal tab and check the logs of the Solana Validator node. There will be a lot of logs though.
Step 8: Move back to first terminal tab and configure solana CLI to use local port 8899 to communicate with this local Solana network.
Step 9: Check the configuration to ensure the changes have taken effect.
Step 10: Get the public key of local node. We will need this in the upcoming steps and refer to this as ADDRESS.
Step 11: We are going to use this ADDRESS multiple times, so let's store it in a variable. Remember to replace [node_address] with the account address of the local node that you received in previous step.
Step 12: We can now use the variable, instead of copy-pasting the actual address. Check balance SOLs of the local node address. We can check balance of any account using its account address or public key. The local node has 500000000 SOL.
Step 13: Let's generate another keypair to get another account/address. We will use this account for SOL transfer and refer to this as ADDRESS_2
Step 14: Like before, we are going to store ADDRESS_2 in a variable. Remember to replace [newly_generated_address] with the account address of the local node that you received in previous step.
Step 15: Transfers 1 SOL from Node account ADDRESS to newly generated address ADDRESS_2 (created in last step).
Step 16: Check balance SOLs of the local node address ADDRESS. We will see that after transferring 1 SOL and paying for network fees (0.000005 SOL), remaining amount is there.
Step 17: Check balance SOLs of newly created address ADDRESS_2. We can see 1 SOL.
Step 18: Another way of getting some SOL from the node faucet is to use airdrop. Let's request for airdrop of 2 SOL. This will get us additional 2 SOL. We can verify the same by running 'solana balance $ADDRESS_2' command again.
Step 19: Check the transaction history for ADDRESS and signature associated with each transaction. We can see that there are 2 transactions. Both of these transactions are of transferring SOL from ADDRESS to ADDRESS_2.
Step 20: We have successfully learned how to create our test Private Blockchain Network with Solana and interact with it.