### Install the Solana Toolkit and Verify Version Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/en/toolkit/getting-started.mdx This command installs the latest version of the Solana Toolkit, which includes the Solana CLI, Rust, and Anchor. The second command verifies the installed `mucho` CLI version, confirming successful installation. ```shell npx -y mucho@latest install mucho --version ``` -------------------------------- ### Display Mucho CLI Help Information Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/en/toolkit/getting-started.mdx After installation, this command can be used to display the help documentation for the `mucho` CLI, listing all available commands and options for Solana program development. ```shell mucho --help ``` -------------------------------- ### Run Initial dApp Setup and Development Server Source: https://github.com/solana-foundation/solana-com/blob/main/content/guides/dapps/journal.mdx These commands perform the initial setup and launch for the newly created Solana dApp. First, navigate into the project directory, then install all required Node.js dependencies, and finally, start the local development server to verify the project's functionality and access the UI. ```shell cd my-journal-dapp npm install npm run dev ``` -------------------------------- ### Create Environment File from Example (Bash) Source: https://github.com/solana-foundation/solana-com/blob/main/content/guides/getstarted/intro-to-ai.mdx Command to copy the `.env.example` file to create a new `.env` file. This is a standard practice for setting up local environment variables without exposing sensitive information in version control. ```bash cp .env.example .env ``` -------------------------------- ### Example package.json for Solana AI Agent Project Source: https://github.com/solana-foundation/solana-com/blob/main/content/guides/getstarted/intro-to-ai.mdx Illustrates the required dependencies structure within a `package.json` file for a project utilizing SendAI's Solana Agent Kit and Langchain libraries. ```json { "dependencies": { "@langchain/core": "^0.3.33", "@langchain/langgraph": "^0.2.41", "@langchain/openai": "^0.3.17", "bs58": "^6.0.0", "dotenv": "^16.4.7", "solana-agent-kit": "^1.4.3" } } ``` -------------------------------- ### Install Dependencies and Build Eliza (Bash) Source: https://github.com/solana-foundation/solana-com/blob/main/content/guides/getstarted/intro-to-ai.mdx Commands to install project dependencies using pnpm and then build the Eliza framework. The `--no-frozen-lockfile` flag is used to allow dependency updates. ```bash pnpm install --no-frozen-lockfile pnpm build ``` -------------------------------- ### Install SendAI Kit and Langchain Dependencies Source: https://github.com/solana-foundation/solana-com/blob/main/content/guides/getstarted/intro-to-ai.mdx Commands to install the `solana-agent-kit` and various `@langchain` packages, `dotenv`, and `bs58` using pnpm. These are essential dependencies for building a Solana AI agent. ```bash pnpm install solana-agent-kit pnpm add @langchain/core @langchain/openai @langchain/langgraph dotenv bs58 ``` -------------------------------- ### Lab Setup: Initialize Project and Install Dependencies Source: https://github.com/solana-foundation/solana-com/blob/main/content/courses/intro-to-solana/intro-to-cryptography.mdx Commands to set up a new project directory, initialize npm, and install necessary packages including TypeScript, `@solana/web3.js`, `esrun`, and `@solana-developers/helpers` for the lab exercises. ```bash mkdir generate-keypair cd generate-keypair npm init -y npm install typescript @solana/web3.js@1 esrun @solana-developers/helpers@2 ``` -------------------------------- ### Install Project Dependencies with Yarn Source: https://github.com/solana-foundation/solana-com/blob/main/README.md Navigates into the cloned repository directory and installs all required project dependencies using Yarn, preparing the environment for development. ```Shell yarn ``` -------------------------------- ### Run Solana.com Development Server Source: https://github.com/solana-foundation/solana-com/blob/main/README.md Starts the local development server for the solana.com website, allowing you to view and test changes in real-time in your browser. ```Shell yarn dev ``` -------------------------------- ### Lab Setup: Clone and Prepare Solana Token Extensions Starter Code Source: https://github.com/solana-foundation/solana-com/blob/main/content/courses/token-extensions/token-extensions-in-the-client.mdx These `bash` commands provide the necessary steps to set up the development environment for the lab. They instruct the user to clone the specified GitHub repository, navigate into the project directory, switch to the `starter` branch, and install all required Node.js dependencies using `npm install`. ```bash git clone https://github.com/Unboxed-Software/solana-lab-token22-in-the-client.git cd solana-lab-token22-in-the-client git checkout starter ``` ```bash npm install ``` -------------------------------- ### Start a Local Solana Validator with Mucho Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/en/toolkit/getting-started.mdx This command starts a local Solana blockchain validator using the `mucho` CLI. A running local validator is required to test Solana programs and transactions locally without interacting with a public network. ```shell mucho validator ``` -------------------------------- ### Solana Token-2022 Setup: Accounts, Mint, and ATAs (Rust Async) Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/tr/tokens/basics/transfer-tokens.mdx Initiates a Solana client connection, generates keypairs, airdrops SOL, calculates rent, and creates instructions for a new Token-2022 mint account and associated token accounts (ATAs) for both sender and recipient. This snippet is a partial example of a larger setup process. ```Rust use anyhow::Result; use solana_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{ commitment_config::CommitmentConfig, program_pack::Pack, signature::{Keypair, Signer}, system_instruction::create_account, transaction::Transaction, }; use spl_associated_token_account::{ get_associated_token_address_with_program_id, instruction::create_associated_token_account, }; use spl_token_2022::{ id as token_2022_program_id, instruction::{initialize_mint, mint_to, transfer_checked}, state::Mint, }; #[tokio::main] async fn main() -> Result<()> { // Create connection to local validator let client = RpcClient::new_with_commitment( String::from("http://127.0.0.1:8899"), CommitmentConfig::confirmed(), ); let recent_blockhash = client.get_latest_blockhash().await?; // Generate a new keypair for the fee payer let fee_payer = Keypair::new(); // Generate a second keypair for the token recipient let recipient = Keypair::new(); // Airdrop 1 SOL to fee payer let airdrop_signature = client .request_airdrop(&fee_payer.pubkey(), 1_000_000_000) .await?; client.confirm_transaction(&airdrop_signature).await?; loop { let confirmed = client.confirm_transaction(&airdrop_signature).await?; if confirmed { break; } } // Airdrop 1 SOL to recipient for rent exemption let recipient_airdrop_signature = client .request_airdrop(&recipient.pubkey(), 1_000_000_000) .await?; client .confirm_transaction(&recipient_airdrop_signature) .await?; loop { let confirmed = client .confirm_transaction(&recipient_airdrop_signature) .await?; if confirmed { break; } } // Generate keypair to use as address of mint let mint = Keypair::new(); // Get default mint account size (in bytes), no extensions enabled let mint_space = Mint::LEN; let mint_rent = client .get_minimum_balance_for_rent_exemption(mint_space) .await?; // Instruction to create new account for mint (token 2022 program) let create_account_instruction = create_account( &fee_payer.pubkey(), // payer &mint.pubkey(), // new account (mint) mint_rent, // lamports mint_space as u64, // space &token_2022_program_id(), // program id ); // Instruction to initialize mint account data let initialize_mint_instruction = initialize_mint( &token_2022_program_id(), &mint.pubkey(), // mint &fee_payer.pubkey(), // mint authority Some(&fee_payer.pubkey()), // freeze authority 2, // decimals )?; // Calculate the associated token account address for fee_payer let source_token_address = get_associated_token_address_with_program_id( &fee_payer.pubkey(), // owner &mint.pubkey(), // mint &token_2022_program_id(), // program_id ); // Instruction to create associated token account for fee_payer let create_source_ata_instruction = create_associated_token_account( &fee_payer.pubkey(), // funding address &fee_payer.pubkey(), // wallet address &mint.pubkey(), // mint address &token_2022_program_id(), // program id ); // Calculate the associated token account address for recipient let destination_token_address = get_associated_token_address_with_program_id( &recipient.pubkey(), // owner &mint.pubkey(), // mint &token_2022_program_id(), // program_id ); // Instruction to create associated token account for recipient let create_destination_ata_instruction = create_associated_token_account( ``` -------------------------------- ### Verify spl-token-cli Installation Source: https://github.com/solana-foundation/solana-com/blob/main/content/courses/token-extensions/intro-to-token-extensions-program.mdx Command to check the installed version of the `spl-token-cli` tool after following the setup guide. ```bash spl-token --version ``` -------------------------------- ### Verify Installed Solana Development Tools Versions Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/en/intro/installation.mdx This code block displays an example of the expected output after a successful installation, listing the versions of Rust, Solana CLI, Anchor CLI, Node.js, and Yarn, which are key components of the Solana development environment. ```text Installed Versions: Rust: rustc 1.86.0 (05f9846f8 2025-03-31) Solana CLI: solana-cli 2.2.12 (src:0315eb6a; feat:1522022101, client:Agave) Anchor CLI: anchor-cli 0.31.1 Node.js: v23.11.0 Yarn: 1.22.1 ``` -------------------------------- ### Solana Program Setup and Testing Commands Source: https://github.com/solana-foundation/solana-com/blob/main/content/courses/connecting-to-offchain-data/verifiable-randomness-functions.mdx Initial setup commands for cloning, building, configuring, and testing the Solana escrow program. This includes cloning the repository, navigating into it, building with Anchor, listing program keys, configuring the Solana wallet path, installing JavaScript dependencies, and running program tests. ```Shell git clone https://github.com/solana-developers/burry-escrow cd burry-escrow anchor build anchor keys list solana config get yarn install anchor test ``` -------------------------------- ### Combine Multiple Token Extensions in Solana CLI Source: https://github.com/solana-foundation/solana-com/blob/main/content/guides/token-extensions/getting-started.mdx This example illustrates how to combine multiple token extensions when creating a new token using the `spl-token` CLI. It shows the simultaneous application of `--interest-rate 5` and `--enable-metadata` flags, demonstrating the flexibility to mix and match desired functionalities for a single token mint. ```shell spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb \ create-token --interest-rate 5 --enable-metadata ``` -------------------------------- ### Check and Install Node.js 23 with NVM Source: https://github.com/solana-foundation/solana-com/blob/main/content/guides/getstarted/intro-to-ai.mdx Instructions to verify the current Node.js version and install or switch to version 23 using nvm (Node Version Manager), which is a prerequisite for the project. ```shell node --version nvm install 23 nvm use 23 ``` -------------------------------- ### Test Solana Agent Basic Functionality (Bash) Source: https://github.com/solana-foundation/solana-com/blob/main/content/guides/getstarted/intro-to-ai.mdx This `bash` command provides an example prompt to the Solana agent. It instructs the agent to display the user's wallet address and request devnet SOL, demonstrating basic interaction and blockchain query capabilities. ```bash Please show me my wallet address and request some devnet sol ``` -------------------------------- ### Combine Instructions and Send Setup Transaction (Rust) Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/el/tokens/extensions/confidential-transfer/withdraw-tokens.mdx Aggregates all the setup instructions (create, reallocate, configure) into a single transaction. This transaction is then signed and sent to the Solana cluster to initialize the confidential transfer account. ```Rust // Combine all instructions let mut instructions = vec![ create_associated_token_account_instruction, reallocate_instruction, ]; instructions.extend(configure_account_instructions); // Create and send the transaction let recent_blockhash = rpc_client.get_latest_blockhash().await?; let transaction = Transaction::new_signed_with_payer( &instructions, Some(&payer.pubkey()), &[&*payer], recent_blockhash, ); let setup_signature = rpc_client .send_and_confirm_transaction(&transaction) .await?; println!( "Token Account Setup Transaction Signature: {}", setup_signature ); ``` -------------------------------- ### Solana RPC Client Setup and Initial Airdrop Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/ko/tokens/basics/create-token-account.mdx This Rust example demonstrates how to set up `RpcClient` and `ProgramRpcClient` connections to a Solana validator (e.g., localnet) and perform an initial SOL airdrop to a payer account. It includes necessary `use` statements and the `#[tokio::main]` attribute for an asynchronous entry point. The snippet shows the initial setup steps for a Solana program. ```Rust use anyhow::Result; use solana_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{ commitment_config::CommitmentConfig, signature::{Keypair, Signer}, }; use spl_token_2022::id as token_2022_program_id; use spl_token_client::{ client::{ProgramRpcClient, ProgramRpcClientSendTransaction}, token::{ExtensionInitializationParams, Token}, }; use std::sync::Arc; #[tokio::main] async fn main() -> Result<()> { // Create connection to local validator let rpc_client = RpcClient::new_with_commitment( String::from("http://127.0.0.1:8899"), CommitmentConfig::confirmed(), ); // Generate a new keypair for the fee payer let payer = Keypair::new(); // Airdrop 1 SOL to fee payer let airdrop_signature = rpc_client .request_airdrop(&payer.pubkey(), 1_000_000_000) .await?; rpc_client.confirm_transaction(&airdrop_signature).await?; loop { let confirmed = rpc_client.confirm_transaction(&airdrop_signature).await?; if confirmed { break; } } // Generate keypair to use as address of mint let mint = Keypair::new(); // Create a new program client let program_client = ProgramRpcClient::new( Arc::new(RpcClient::new_with_commitment( String::from("http://127.0.0.1:8899"), CommitmentConfig::confirmed(), )), ProgramRpcClientSendTransaction, ); ``` -------------------------------- ### Initialize Solana Token Client Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/vi/tokens/basics/mint-tokens.mdx This snippet shows the initial setup for creating a connection to a local Solana validator using `RpcClient` and importing necessary modules for token operations with `spl-token-client`. It serves as a starting point for more complex token interactions. ```rust use anyhow::Result; use solana_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{ commitment_config::CommitmentConfig, signature::{Keypair, Signer}, }; use spl_token_2022::id as token_2022_program_id; use spl_token_client::{ client::{ProgramRpcClient, ProgramRpcClientSendTransaction}, token::{ExtensionInitializationParams, Token}, }; use std::sync::Arc; #[tokio::main] async fn main() -> Result<()> { // Create connection to local validator let rpc_client = RpcClient::new_with_commitment( ``` -------------------------------- ### Install Dependencies and Start Vite Development Server Source: https://github.com/solana-foundation/solana-com/blob/main/content/guides/getstarted/full-stack-solana-development.mdx Commands to navigate into the newly created frontend project directory, install all required dependencies using Yarn, and then start the Vite development server. This makes the React application accessible locally for development and testing. ```shell cd front-end yarn yarn dev ``` -------------------------------- ### Solana Token 2022: Asynchronous Setup and Account Initialization Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/ar/tokens/basics/transfer-tokens.mdx This Rust example provides the foundational setup for interacting with the Solana Token 2022 program asynchronously. It covers connecting to a local validator, generating keypairs for a fee payer and recipient, airdropping SOL, determining rent exemption for a mint account, creating and initializing a new token mint, and calculating associated token account (ATA) addresses for both the sender and recipient. The snippet ends before the full creation of the recipient's ATA and token minting. ```Rust use anyhow::Result; use solana_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{ commitment_config::CommitmentConfig, program_pack::Pack, signature::{Keypair, Signer}, system_instruction::create_account, transaction::Transaction, }; use spl_associated_token_account::{ get_associated_token_address_with_program_id, instruction::create_associated_token_account, }; use spl_token_2022::{ id as token_2022_program_id, instruction::{initialize_mint, mint_to, transfer_checked}, state::Mint, }; #[tokio::main] async fn main() -> Result<()> { // Create connection to local validator let client = RpcClient::new_with_commitment( String::from("http://127.0.0.1:8899"), CommitmentConfig::confirmed(), ); let recent_blockhash = client.get_latest_blockhash().await?; // Generate a new keypair for the fee payer let fee_payer = Keypair::new(); // Generate a second keypair for the token recipient let recipient = Keypair::new(); // Airdrop 1 SOL to fee payer let airdrop_signature = client .request_airdrop(&fee_payer.pubkey(), 1_000_000_000) .await?; client.confirm_transaction(&airdrop_signature).await?; loop { let confirmed = client.confirm_transaction(&airdrop_signature).await?; if confirmed { break; } } // Airdrop 1 SOL to recipient for rent exemption let recipient_airdrop_signature = client .request_airdrop(&recipient.pubkey(), 1_000_000_000) .await?; client .confirm_transaction(&recipient_airdrop_signature) .await?; loop { let confirmed = client .confirm_transaction(&recipient_airdrop_signature) .await?; if confirmed { break; } } // Generate keypair to use as address of mint let mint = Keypair::new(); // Get default mint account size (in bytes), no extensions enabled let mint_space = Mint::LEN; let mint_rent = client .get_minimum_balance_for_rent_exemption(mint_space) .await?; // Instruction to create new account for mint (token 2022 program) let create_account_instruction = create_account( &fee_payer.pubkey(), // payer &mint.pubkey(), // new account (mint) mint_rent, // lamports mint_space as u64, // space &token_2022_program_id(), // program id ); // Instruction to initialize mint account data let initialize_mint_instruction = initialize_mint( &token_2022_program_id(), &mint.pubkey(), // mint &fee_payer.pubkey(), // mint authority Some(&fee_payer.pubkey()), // freeze authority 2, // decimals )?; // Calculate the associated token account address for fee_payer let source_token_address = get_associated_token_address_with_program_id( &fee_payer.pubkey(), // owner &mint.pubkey(), // mint &token_2022_program_id(), // program_id ); // Instruction to create associated token account for fee_payer let create_source_ata_instruction = create_associated_token_account( &fee_payer.pubkey(), // funding address &fee_payer.pubkey(), // wallet address &mint.pubkey(), // mint address &token_2022_program_id(), // program id ); // Calculate the associated token account address for recipient let destination_token_address = get_associated_token_address_with_program_id( &recipient.pubkey(), // owner &mint.pubkey(), // mint &token_2022_program_id(), // program_id ); // Instruction to create associated token account for recipient ``` -------------------------------- ### Shell: Setup and Run NextJS/JavaScript Client Source: https://github.com/solana-foundation/solana-com/blob/main/content/guides/token-extensions/dynamic-meta-data-nft.mdx These commands are used to set up and run the NextJS/JavaScript client for the Solana game. It involves navigating to the `app` directory, installing Node.js dependencies with `yarn install`, and starting the development server with `yarn dev`. This client can interact with the Solana program on devnet or a local validator. ```shell cd app yarn install yarn dev ``` -------------------------------- ### Request Solana Airdrop for Local Development Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/en/toolkit/getting-started.mdx This command requests an airdrop of 10 SOL to the current keypair from a local Solana validator. This is essential for obtaining test SOL to fund transactions and programs during local development. ```shell solana airdrop 10 --url localhost ``` -------------------------------- ### Install Solana CLI Tools Source: https://github.com/solana-foundation/solana-com/blob/main/content/guides/getstarted/solana-test-validator.mdx Installs the Solana command-line interface tools, including the test validator, from the specified release channel (e.g., stable). This command uses `curl` to download and execute an installation script. ```shell sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)" ``` -------------------------------- ### Generate a New Solana Keypair Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/en/toolkit/getting-started.mdx This command generates a new cryptographic keypair for the Solana CLI. The keypair is stored at the default path (`~/.config/solana/id.json`) and its public key is printed to the console. ```shell solana-keygen new ``` -------------------------------- ### Legacy Solana Token Minting and Account Setup Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/ko/tokens/basics/transfer-tokens.mdx This legacy example illustrates the foundational steps for setting up a new SPL token mint and associated token accounts on Solana. It includes connecting to a local validator, generating keypairs for fee payers and recipients, requesting SOL airdrops for rent exemption, and creating instructions for mint initialization and associated token account creation. This snippet prepares the necessary accounts and mint for subsequent token operations. ```typescript import { Connection, Keypair, sendAndConfirmTransaction, SystemProgram, Transaction, LAMPORTS_PER_SOL } from "@solana/web3.js"; import { createInitializeMintInstruction, MINT_SIZE, getMinimumBalanceForRentExemptMint, TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync, createAssociatedTokenAccountInstruction, ASSOCIATED_TOKEN_PROGRAM_ID, createMintToInstruction, createTransferInstruction } from "@solana/spl-token"; // Create connection to local validator const connection = new Connection("http://127.0.0.1:8899", "confirmed"); const recentBlockhash = await connection.getLatestBlockhash(); // Generate a new keypair for the fee payer const feePayer = Keypair.generate(); // Generate a new keypair for the recipient const recipient = Keypair.generate(); // Airdrop 1 SOL to fee payer const airdropSignature = await connection.requestAirdrop( feePayer.publicKey, LAMPORTS_PER_SOL ); await connection.confirmTransaction({ blockhash: recentBlockhash.blockhash, lastValidBlockHeight: recentBlockhash.lastValidBlockHeight, signature: airdropSignature }); // Airdrop 0.1 SOL to recipient for rent exemption const recipientAirdropSignature = await connection.requestAirdrop( recipient.publicKey, LAMPORTS_PER_SOL / 10 ); await connection.confirmTransaction({ blockhash: recentBlockhash.blockhash, lastValidBlockHeight: recentBlockhash.lastValidBlockHeight, signature: recipientAirdropSignature }); // Generate keypair to use as address of mint const mint = Keypair.generate(); // Get minimum balance for rent exemption const mintRent = await getMinimumBalanceForRentExemptMint(connection); // Get the associated token account address for the fee payer const feePayerATA = getAssociatedTokenAddressSync( mint.publicKey, feePayer.publicKey, false, // allowOwnerOffCurve TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID ); // Get the associated token account address for the recipient const recipientATA = getAssociatedTokenAddressSync( mint.publicKey, recipient.publicKey, false, // allowOwnerOffCurve TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID ); // Create account instruction const createAccountInstruction = SystemProgram.createAccount({ fromPubkey: feePayer.publicKey, newAccountPubkey: mint.publicKey, space: MINT_SIZE, lamports: mintRent, programId: TOKEN_2022_PROGRAM_ID }); // Initialize mint instruction const initializeMintInstruction = createInitializeMintInstruction( mint.publicKey, // mint pubkey 2, // decimals feePayer.publicKey, // mint authority feePayer.publicKey, // freeze authority TOKEN_2022_PROGRAM_ID ); // Create associated token account instruction for fee payer const createSenderATA = createAssociatedTokenAccountInstruction( feePayer.publicKey, // payer feePayerATA, // associated token account address feePayer.publicKey, // owner mint.publicKey, // mint TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID ); // Create recipient's associated token account const createRecipientATA = createAssociatedTokenAccountInstruction( feePayer.publicKey, // payer recipientATA, // associated token account address recipient.publicKey, // owner mint.publicKey, // mint TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID ); // Create a separate transaction for minting tokens // Create mint to instruction (mint 100 tokens = 1.00 with 2 decimals) const mintAmount = 100; const mintToInstruction = createMintToInstruction( mint.publicKey, // mint feePayerATA, // destination feePayer.publicKey, // authority mintAmount, // amount [], // multiSigners TOKEN_2022_PROGRAM_ID // programId ); ``` -------------------------------- ### Start Local Solana Test Validator for Token Extensions Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/en/tokens/extensions/confidential-transfer/withdraw-tokens.mdx This command initializes a local Solana test validator, specifically cloning the mainnet Token Extension Program. This setup is crucial for running examples involving confidential transfers, as the default local validator does not have this feature enabled. Ensure Solana CLI is installed before execution. ```terminal $ solana-test-validator --clone-upgradeable-program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb --url https://api.mainnet-beta.solana.com -r ``` -------------------------------- ### Start Solana Local Validator for Confidential Transfers Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/ko/tokens/extensions/confidential-transfer/create-token-account.mdx This command starts a local Solana test validator and clones the Token Extensions Program from the mainnet-beta. This setup is crucial because the confidential transfer feature is not enabled by default in the standard local validator, making it a prerequisite for running the provided confidential transfer examples. ```terminal $ solana-test-validator --clone-upgradeable-program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb --url https://api.mainnet-beta.solana.com -r ``` -------------------------------- ### Check Current Solana CLI Network Configuration Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/en/toolkit/getting-started.mdx This command displays the current network configuration settings for the Solana CLI, including the RPC URL and WebSocket URL. It helps verify which cluster the CLI is connected to. ```shell solana config get ``` -------------------------------- ### Create Token 2022 Mint with Solana Kit Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/ru/tokens/basics/create-mint.mdx This TypeScript example demonstrates creating a new Token 2022 mint using the modern `@solana/kit` library. It covers connection setup, fee payer funding, mint keypair generation, account creation, mint initialization, transaction building with `pipe`, signing, and confirmation. The process involves creating system and token program instructions, then assembling and sending the transaction. ```TypeScript import { airdropFactory, appendTransactionMessageInstructions, createSolanaRpc, createSolanaRpcSubscriptions, createTransactionMessage, generateKeyPairSigner, getSignatureFromTransaction, lamports, pipe, sendAndConfirmTransactionFactory, setTransactionMessageFeePayerSigner, setTransactionMessageLifetimeUsingBlockhash, signTransactionMessageWithSigners } from "@solana/kit"; import { getCreateAccountInstruction } from "@solana-program/system"; import { getInitializeMintInstruction, getMintSize, TOKEN_2022_PROGRAM_ADDRESS } from "@solana-program/token-2022"; // Create Connection, local validator in this example const rpc = createSolanaRpc("http://127.0.0.1:8899"); const rpcSubscriptions = createSolanaRpcSubscriptions("ws://localhost:8900"); // Generate keypairs for fee payer const feePayer = await generateKeyPairSigner(); // Fund fee payer await airdropFactory({ rpc, rpcSubscriptions }) ({ recipientAddress: feePayer.address, lamports: lamports(1_000_000_000n), commitment: "confirmed" }); // Generate keypair to use as address of mint const mint = await generateKeyPairSigner(); // Get default mint account size (in bytes), no extensions enabled const space = BigInt(getMintSize()); // Get minimum balance for rent exemption const rent = await rpc.getMinimumBalanceForRentExemption(space).send(); // Instruction to create new account for mint (token 2022 program) // Invokes the system program const createAccountInstruction = getCreateAccountInstruction({ payer: feePayer, newAccount: mint, lamports: rent, space, programAddress: TOKEN_2022_PROGRAM_ADDRESS }); // Instruction to initialize mint account data // Invokes the token 2022 program const initializeMintInstruction = getInitializeMintInstruction({ mint: mint.address, decimals: 9, mintAuthority: feePayer.address }); const instructions = [createAccountInstruction, initializeMintInstruction]; // Get latest blockhash to include in transaction const { value: latestBlockhash } = await rpc.getLatestBlockhash().send(); // Create transaction message const transactionMessage = pipe( createTransactionMessage({ version: 0 }), // Create transaction message (tx) => setTransactionMessageFeePayerSigner(feePayer, tx), // Set fee payer (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx), // Set transaction blockhash (tx) => appendTransactionMessageInstructions(instructions, tx) // Append instructions ); // Sign transaction message with required signers (fee payer and mint keypair) const signedTransaction = await signTransactionMessageWithSigners(transactionMessage); // Send and confirm transaction await sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions })( signedTransaction, { commitment: "confirmed" } ); // Get transaction signature const transactionSignature = getSignatureFromTransaction(signedTransaction); console.log("Mint Address:", mint.address); console.log("Transaction Signature:", transactionSignature); ``` -------------------------------- ### Clone Eliza Framework Repository (Bash) Source: https://github.com/solana-foundation/solana-com/blob/main/content/guides/getstarted/intro-to-ai.mdx Command to clone the Eliza framework's Git repository from GitHub, which is the first step to setting up the development environment for building AI agents. ```bash git clone https://github.com/elizaOS/eliza.git ``` -------------------------------- ### Create Rust Client Example Files Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/en/programs/rust/index.mdx Initializes the project structure by creating an `examples` directory and an empty `client.rs` file within it, preparing for the Rust client implementation. ```shell mkdir -p examples touch examples/client.rs ``` -------------------------------- ### Install Node.js 23 with NVM (Shell) Source: https://github.com/solana-foundation/solana-com/blob/main/content/guides/getstarted/intro-to-ai.mdx Command to install Node.js version 23 using Node Version Manager (nvm). This ensures the correct Node.js environment for the Eliza framework. ```shell nvm install 23 ``` -------------------------------- ### Create and Mint Tokens with Solana Token 2022 (Rust Async) Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/fr/tokens/basics/mint-tokens.mdx This Rust example demonstrates how to interact with the Solana Token 2022 program using an asynchronous RPC client. It covers creating a new token mint, initializing it, creating an associated token account (ATA) for a fee payer, and then minting tokens to that ATA. This snippet is a partial example, showing the initial setup. ```Rust use anyhow::Result; use solana_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{ commitment_config::CommitmentConfig, program_pack::Pack, signature::{Keypair, Signer}, system_instruction::create_account, transaction::Transaction, }; use spl_associated_token_account::{ ``` -------------------------------- ### Legacy SPL Token Minting and Transfer Setup Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/ru/tokens/basics/transfer-tokens.mdx This comprehensive legacy example illustrates the setup for SPL token operations using `@solana/web3.js` and `@solana/spl-token`. It includes establishing a connection, airdropping SOL to fee payers and recipients, generating keypairs for mint and accounts, calculating rent exemption, creating a token mint, initializing the mint, and setting up associated token accounts for both sender and recipient. It also shows the instruction for minting tokens to an associated token account. ```typescript import { Connection, Keypair, sendAndConfirmTransaction, SystemProgram, Transaction, LAMPORTS_PER_SOL } from "@solana/web3.js"; import { createInitializeMintInstruction, MINT_SIZE, getMinimumBalanceForRentExemptMint, TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync, createAssociatedTokenAccountInstruction, ASSOCIATED_TOKEN_PROGRAM_ID, createMintToInstruction, createTransferInstruction } from "@solana/spl-token"; // Create connection to local validator const connection = new Connection("http://127.0.0.1:8899", "confirmed"); const recentBlockhash = await connection.getLatestBlockhash(); // Generate a new keypair for the fee payer const feePayer = Keypair.generate(); // Generate a new keypair for the recipient const recipient = Keypair.generate(); // Airdrop 1 SOL to fee payer const airdropSignature = await connection.requestAirdrop( feePayer.publicKey, LAMPORTS_PER_SOL ); await connection.confirmTransaction({ blockhash: recentBlockhash.blockhash, lastValidBlockHeight: recentBlockhash.lastValidBlockHeight, signature: airdropSignature }); // Airdrop 0.1 SOL to recipient for rent exemption const recipientAirdropSignature = await connection.requestAirdrop( recipient.publicKey, LAMPORTS_PER_SOL / 10 ); await connection.confirmTransaction({ blockhash: recentBlockhash.blockhash, lastValidBlockHeight: recentBlockhash.lastValidBlockHeight, signature: recipientAirdropSignature }); // Generate keypair to use as address of mint const mint = Keypair.generate(); // Get minimum balance for rent exemption const mintRent = await getMinimumBalanceForRentExemptMint(connection); // Get the associated token account address for the fee payer const feePayerATA = getAssociatedTokenAddressSync( mint.publicKey, feePayer.publicKey, false, // allowOwnerOffCurve TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID ); // Get the associated token account address for the recipient const recipientATA = getAssociatedTokenAddressSync( mint.publicKey, recipient.publicKey, false, // allowOwnerOffCurve TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID ); // Create account instruction const createAccountInstruction = SystemProgram.createAccount({ fromPubkey: feePayer.publicKey, newAccountPubkey: mint.publicKey, space: MINT_SIZE, lamports: mintRent, programId: TOKEN_2022_PROGRAM_ID }); // Initialize mint instruction const initializeMintInstruction = createInitializeMintInstruction( mint.publicKey, // mint pubkey 2, // decimals feePayer.publicKey, // mint authority feePayer.publicKey, // freeze authority TOKEN_2022_PROGRAM_ID ); // Create associated token account instruction for fee payer const createSenderATA = createAssociatedTokenAccountInstruction( feePayer.publicKey, // payer feePayerATA, // associated token account address feePayer.publicKey, // owner mint.publicKey, // mint TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID ); // Create recipient's associated token account const createRecipientATA = createAssociatedTokenAccountInstruction( feePayer.publicKey, // payer recipientATA, // associated token account address recipient.publicKey, // owner mint.publicKey, // mint TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID ); // Create a separate transaction for minting tokens // Create mint to instruction (mint 100 tokens = 1.00 with 2 decimals) const mintAmount = 100; const mintToInstruction = createMintToInstruction( mint.publicKey, // mint feePayerATA, // destination feePayer.publicKey, // authority mintAmount, // amount [], // multiSigners TOKEN_2022_PROGRAM_ID // programId ); ``` -------------------------------- ### Import Solana Program Crate Components Source: https://github.com/solana-foundation/solana-com/blob/main/content/courses/native-onchain-development/hello-world-program.mdx This code block imports essential components from the `solana_program` crate. These include `AccountInfo` for account data, `entrypoint` for program entry point definition, `ProgramResult` for return types, `Pubkey` for public keys, and `msg` for logging. ```Rust use solana_program::{ account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, pubkey::Pubkey, msg }; ``` -------------------------------- ### Legacy Solana Token Minting and Transfer Setup (SPL-Token) Source: https://github.com/solana-foundation/solana-com/blob/main/content/docs/tr/tokens/basics/transfer-tokens.mdx This legacy snippet demonstrates the setup for minting and transferring SPL tokens using `@solana/web3.js` and `@solana/spl-token`. It includes steps for establishing a connection, generating keypairs, airdropping SOL for rent exemption, creating a new mint, and setting up associated token accounts for both sender and recipient. It also shows how to create instructions for account creation, mint initialization, and minting tokens. ```typescript import { Connection, Keypair, sendAndConfirmTransaction, SystemProgram, Transaction, LAMPORTS_PER_SOL } from "@solana/web3.js"; import { createInitializeMintInstruction, MINT_SIZE, getMinimumBalanceForRentExemptMint, TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync, createAssociatedTokenAccountInstruction, ASSOCIATED_TOKEN_PROGRAM_ID, createMintToInstruction, createTransferInstruction } from "@solana/spl-token"; // Create connection to local validator const connection = new Connection("http://127.0.0.1:8899", "confirmed"); const recentBlockhash = await connection.getLatestBlockhash(); // Generate a new keypair for the fee payer const feePayer = Keypair.generate(); // Generate a new keypair for the recipient const recipient = Keypair.generate(); // Airdrop 1 SOL to fee payer const airdropSignature = await connection.requestAirdrop( feePayer.publicKey, LAMPORTS_PER_SOL ); await connection.confirmTransaction({ blockhash: recentBlockhash.blockhash, lastValidBlockHeight: recentBlockhash.lastValidBlockHeight, signature: airdropSignature }); // Airdrop 0.1 SOL to recipient for rent exemption const recipientAirdropSignature = await connection.requestAirdrop( recipient.publicKey, LAMPORTS_PER_SOL / 10 ); await connection.confirmTransaction({ blockhash: recentBlockhash.blockhash, lastValidBlockHeight: recentBlockhash.lastValidBlockHeight, signature: recipientAirdropSignature }); // Generate keypair to use as address of mint const mint = Keypair.generate(); // Get minimum balance for rent exemption const mintRent = await getMinimumBalanceForRentExemptMint(connection); // Get the associated token account address for the fee payer const feePayerATA = getAssociatedTokenAddressSync( mint.publicKey, feePayer.publicKey, false, // allowOwnerOffCurve TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID ); // Get the associated token account address for the recipient const recipientATA = getAssociatedTokenAddressSync( mint.publicKey, recipient.publicKey, false, // allowOwnerOffCurve TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID ); // Create account instruction const createAccountInstruction = SystemProgram.createAccount({ fromPubkey: feePayer.publicKey, newAccountPubkey: mint.publicKey, space: MINT_SIZE, lamports: mintRent, programId: TOKEN_2022_PROGRAM_ID }); // Initialize mint instruction const initializeMintInstruction = createInitializeMintInstruction( mint.publicKey, // mint pubkey 2, // decimals feePayer.publicKey, // mint authority feePayer.publicKey, // freeze authority TOKEN_2022_PROGRAM_ID ); // Create associated token account instruction for fee payer const createSenderATA = createAssociatedTokenAccountInstruction( feePayer.publicKey, // payer feePayerATA, // associated token account address feePayer.publicKey, // owner mint.publicKey, // mint TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID ); // Create recipient's associated token account const createRecipientATA = createAssociatedTokenAccountInstruction( feePayer.publicKey, // payer recipientATA, // associated token account address recipient.publicKey, // owner mint.publicKey, // mint TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID ); // Create a separate transaction for minting tokens // Create mint to instruction (mint 100 tokens = 1.00 with 2 decimals) const mintAmount = 100; const mintToInstruction = createMintToInstruction( mint.publicKey, // mint feePayerATA, // destination feePayer.publicKey, // authority mintAmount, // amount [], // multiSigners TOKEN_2022_PROGRAM_ID // programId ); ``` -------------------------------- ### Set up a new Solana game project with create-solana-game Source: https://github.com/solana-foundation/solana-com/blob/main/content/guides/games/game-examples.mdx This command-line tool simplifies the setup of a new Solana game project, integrating a Unity client, Anchor program, and Next.js frontend. It supports features like Wallet adapter, NFT/compressed NFT, and session keys for auto-approving transactions. ```Bash npx create-solana-game your-game-name ``` -------------------------------- ### Check Node.js Version (Shell) Source: https://github.com/solana-foundation/solana-com/blob/main/content/guides/getstarted/intro-to-ai.mdx A shell command to display the currently installed Node.js version on the system, useful for verifying environment prerequisites. ```shell node --version ```