# Getting Started with the Solana CLI

*A Beginner's Tutorial From A Beginner*

By [Graymans Block](https://paragraph.com/@grayman) · 2024-03-04

solana, blockchain, tutorial

---

Introduction
============

I have started a bit of a journey to discover the Solana blockchain and ecosystem. This here is a beginner's guide I've created from the knowledge I've learned from using the Solana Command Line Interface (CLI). The Solana CLI is a powerful tool that lets you interact with the Solana blockchain, enabling you to manage wallets, send transactions, and more. This tutorial will walk you through the basics to get you started.

A little warning, use of the Solana CLI and interaction with the Solana blockchain involves risks, including but not limited to loss of funds, security vulnerabilities, and regulatory implications. It is essential to know and understand the regulatory environment of your jurisdiction before engaging in blockchain-related activities.

**Step 1: Installing the Solana CLI**
-------------------------------------

First, you need to install the Solana CLI on your system. The process is straightforward and varies slightly depending on your operating system.

### **For macOS and Linux:**

Open your terminal and run the following command:

    sh -c "$(curl -sSfL https://release.solana.com/stable/install)"

### **For Windows Users:**

Windows users should use the Windows Subsystem for Linux (WSL) and then run the same command as macOS and Linux users.

### **Check the Installation:**

After installing, you can check if it was successful by running:

    solana --version

This command will display the version of Solana CLI installed.

**Step 2: Setting Up the Network**
----------------------------------

Solana operates on different networks: Mainnet Beta, Testnet, and Devnet. To set your environment to one of these networks, use the `config set` command:

    solana config set --url <network>

Replace `<network>` with the appropriate URL for your desired network:

*   Mainnet Beta: `https://api.mainnet-beta.solana.com`
    
*   Testnet: `https://api.testnet.solana.com`
    
*   Devnet: `https://api.devnet.solana.com`
    

**Step 3: Creating a Wallet**
-----------------------------

A wallet is essential for holding your SOL tokens and interacting with the Solana blockchain. To create a new wallet:

    solana-keygen new --outfile ~/my-solana-wallet.json

This command creates a new wallet and saves the keypair to the specified file. Keep this file safe, as it contains your private keys.

### **Checking Your Wallet Balance:**

To check the balance of your wallet, use:

    solana balance

This command will show the current balance of your SOL tokens.

**Step 4: Sending SOL**
-----------------------

You can send SOL to another address using the `transfer` command. Here's how:

    solana transfer --from ~/my-solana-wallet.json <RECIPIENT_ADDRESS> <AMOUNT>

Replace `<RECIPIENT_ADDRESS>` with the address of the recipient and `<AMOUNT>` with the amount of SOL you wish to send.

**Step 5: Viewing Transaction History**
---------------------------------------

To view your account's transaction history and details, use the `account` command:

    solana account <YOUR_ADDRESS>

This will provide information about your account, including its transaction history.

More Fun With Solana
====================

The Solana CLI offers a wide array of commands for various operations on the Solana blockchain. Beyond the basics of creating wallets, transferring SOL, and checking balances, here are a few more commands that unlock additional functionalities:

1\. **Airdropping SOL (Devnet/Testnet)**
----------------------------------------

To receive SOL for testing purposes on Devnet or Testnet, you can use the `airdrop` command. This is useful for development and testing without using real funds.

    solana airdrop <AMOUNT> <YOUR_WALLET_ADDRESS> --url <NETWORK_URL>

Replace `<AMOUNT>` with the number of SOL you want to receive, `<YOUR_WALLET_ADDRESS>` with your wallet address, and `<NETWORK_URL>` with the URL of Devnet or Testnet.

2\. **Staking SOL**
-------------------

You can delegate SOL to a validator to participate in staking and earn rewards.

*   **Create a Stake Account:**
    

      solana create-stake-account <STAKE_ACCOUNT_KEYPAIR_FILE> <AMOUNT> --from <FUNDING_SOURCE> --stake-authority <STAKE_AUTHORITY_PUBKEY> --withdraw-authority <WITHDRAW_AUTHORITY_PUBKEY>

This command creates a new stake account with a specified amount of SOL.

*   **Delegate Stake:**
    

      solana delegate-stake --stake-authority <STAKE_AUTHORITY_PUBKEY> <STAKE_ACCOUNT_ADDRESS> <VALIDATOR_VOTE_ACCOUNT_ADDRESS>

Use this command to delegate your stake to a validator by specifying the stake account and the validator's vote account address.

3\. **Creating and Managing Tokens**
------------------------------------

Solana supports the creation of custom tokens through the SPL Token program.

*   **Create a New Token:**
    

      spl-token create-token

This command creates a new token and outputs the token's mint address.

*   **Create a Token Account:**
    

      spl-token create-account <TOKEN_MINT_ADDRESS>

Creates a new account for holding tokens of the specified mint.

*   **Minting Tokens:**
    

      spl-token mint <TOKEN_MINT_ADDRESS> <AMOUNT> <RECIPIENT_ACCOUNT_ADDRESS>

Mint new tokens to a specified account.

4\. **Confirming Transactions**
-------------------------------

To check the status of a transaction:

    solana confirm <TRANSACTION_SIGNATURE>

This command allows you to confirm that a transaction has been successfully processed.

5\. **Deploying Programs (Smart Contracts)**
--------------------------------------------

Deploying a compiled program to the Solana blockchain:

    solana program deploy <PROGRAM_FILEPATH>

This is used for deploying smart contracts (or programs, in Solana terminology) to the network.

These commands represent just a fraction of what's possible with the Solana CLI. Each command has a variety of options and flags to customize its behavior, making the CLI a powerful tool for developers and users alike to interact with the Solana blockchain efficiently.

![](https://paragraph.xyz/editor/callout/information-icon.png)

_Note: By using the information in this post, the reader agrees to the terms of this disclaimer and acknowledges understanding the risks involved in using the Solana blockchain and its associated tools and technologies._

---

*Originally published on [Graymans Block](https://paragraph.com/@grayman/solana-cli-guide)*
