Categories
Main Category

Learn Basic Operation of Solana-CLI

If 2020 is considered to be the year of Ethereum Defi. Then the Solana ecosystem’s year is 2022. The official website for Solana states that 400 projects have just been launched there. This is undoubtedly challenging for a blockchain that has recently launched its mainnet in April 2020. This article will first cover some fundamental Solana-CLI procedures, such as how to make a wallet and send money around.

Setup

Examples used in this piece were run on Ubuntu 20.04.

The CLI tools for Solana must first be downloaded from the company’s main website. You may download it by using the command below:

sh -c “$(curl -sSfL https://release.solana.com/v1.8.0/install)”

Restart your computer when the download is finished, and then verify that it was installed correctly:

$ solana –version 

solana-cli 1.8.0 (src:4a8ff62a; feat:1813598585)

Then, we must download Rust, the primary language Solana uses:

$ curl https://sh.rustup.rs -sSf | sh

$ source $HOME/.cargo/env

$ rustup component add rustfmt

Like other blockchains, Solana requires a wallet for storing, sending, and doing other operations with your tokens.

If you are unfamiliar with blockchain technology, a wallet is a set of public and private keys. Public Key may be compared to your account number. For instance, if your friend wants to send you some tokens, he must choose your public key as the recipient. The private key may be thought of as your account’s signature, which is used to verify that the transfer information was transmitted from and was authorized by your account. Your private key must be stored securely and adequately as a result. Otherwise, if it is lost, you won’t be able to spend any of your money; if it is leaked, anybody can move it at any time.

According to the company’s documentation, Solana Wallet may be set up in three modes: Paper Wallet, Hardware Wallet, and File System Wallet. The major focus of this article is on explaining how to establish a File System Wallet and utilize it for various tasks.

You can establish a new wallet account by following these steps if you need to:

$ solana-keygen new

The above command will produce a pair of public and private keys and store them in the following predefined locations:

/root/.config/solana/id.json

Additionally, you may choose where to store the freshly generated public and private keys:

$ mkdir solana

$ solana-keygen new –outfile /root/solana/my_wallet.json

After that, you must confirm that you are the wallet’s private key owner to the Solana network. You must first get this wallet’s public key:

$ solana-keygen pubkey ~/solana/my_wallet.json FEBxPgsTXTdWkifpiGUSjfzS7ztBFJKPnaHT8A7iUdFc

After that, pair the wallet file with this public key:

solana-keygen verify FEBxPgsTXTdWkifpiGUSjfzS7ztBFJKPnaHT8A7iUdFc /root/solana/my_wallet.json

To examine the current configuration, we may use the command:

$ solana config get Config File: /root/.config/solana/cli/config.yml

RPC URL: http://api.devnet.solana.com

WebSocket URL: ws://api.devnet.solana.com/ (computed)

Keypair Path: /root/.config/solana/id.json

Commitment: confirmed

Let’s now go over the setup information mentioned above:

Config File: The configuration file’s location;

RPC URL: The URL of the Cluster to which you are currently logged in. The network is referred to as a Cluster in Solana. You can now connect to several Clusters in Solana, including Testnet, Mainnet-Beta, and Mainnet. On your localhost, you may quickly build your own Solana Cluster. The setting above displays Solana’s Testnet at http://api.devnet.solana.com;

WebSocket URL: The Solana Cluster’s Websocket URL that you connected to. It is produced automatically from the RPC URL;

Keypair: The location of the wallet’s active wallet

We must change the wallet location to /root/solana/my wallet.json as the wallet display location is the Solana CLI’s default location:

$ solana config set –keypair /root/solana/my_wallet.json

This command can be used to switch between wallets on the same workstation.

As previously noted, Solana offers a variety of Clusters. In this article, Testnet will be used for all activities. The Mainnet and Testnet configurations are very similar. The main distinction is that on the testnet, all tokens and transactions are fake. Therefore, anyone may freely experiment with anything on the Testnet.

Solana-default CLI’s setup should point to Testnet after it has been downloaded. If not, you may establish using the command below:

$ solana config set –url https://api.devnet.solana.com

Additionally, you may get Sol coins via Airdrop on the Testnet. You may get 2 Sol coins by following these steps after finishing the above configuration:

$ solana airdrop 2

Let’s now create a new wallet with the name my wallet2.json. The directions remain the same as before:

$ solana-keygen new –outfile /root/solana/my_wallet2.json

Extracting its public key now

$ solana-keygen pubkey ~/solana/my_wallet2.json Ec2x4xwfxgLuZBwvuv1HmhFgujWNJ16Lkf92Zu81hv56

And verify your wallet:

solana-keygen verify Ec2x4xwfxgLuZBwvuv1HmhFgujWNJ16Lkf92Zu81hv56 /root/solana/my_wallet2.json

Solana’s Testnet has two wallets stored in the files /root/solana/my wallet.json and /root/solana/my wallet2.json, respectively. I received two Sols through airdrop in my wallet, located at /root/solana/my wallet.json. Let’s try sending one of these to /root/solana/my wallet2.json wallet now.

To check the setup right now, use the following command first:

$ solana config get Config File: /root/.config/solana/cli/config.yml

RPC URL: http://api.devnet.solana.com

WebSocket URL: ws://api.devnet.solana.com/ (computed)

Keypair Path: /root/solana/my_wallet.json

Commitment: confirmed

As shown earlier, our wallet is located at /root/solana/my wallet.json. Then, to send 1 Sol to this account, we enter the public key of the receiving account:

$ solana transfer Ec2x4xwfxgLuZBwvuv1HmhFgujWNJ16Lkf92Zu81hv56 1 Error: The recipient address (Ec2x4xwfxgLuZBwvuv1HmhFgujWNJ16Lkf92Zu81hv56) is not funded. Add `–allow-unfunded-recipient` to complete the transfer

You will discover a mistake in the initial transfer. The major cause is that the receiving account has no balance; hence the instruction should be altered to:

$ solana transfer Ec2x4xwfxgLuZBwvuv1HmhFgujWNJ16Lkf92Zu81hv56 1 -allow-unfunded-recipient

After success, execute the following command to check the recipient account’s balance:

$ solana balance Ec2x4xwfxgLuZBwvuv1HmhFgujWNJ16Lkf92Zu81hv56

1 SOL

We can also check the balance of the original account:

$ solana balance FEBxPgsTXTdWkifpiGUSjfzS7ztBFJKPnaHT8A7iUdFc

0.9985234 SOL

After transferring 1Sol from your first account, the remaining amount will be 0.9985234Sol rather than 1Sol. Because Solana transactions are the same as those of other blockchains, each transaction needs payment to the network’s Validator. As a result, the missing component is the transaction’s processing charge.