Chainlink Solana Starter Kit

repository·main·Indexed 41 days ago

https://github.com/smartcontractkit/solana-starter-kit

An Anchor-based program and client for interacting with Chainlink Price Feeds and the Cross-Chain Interoperability Protocol (CCIP) on Solana Devnet. Includes a Rust program for on-chain data handling and SDKs for EVM and SVM (Solana Virtual Machine) to send cross-chain messages, calculate fees, and manage account data.

Tokens
29.2K
Snippets
79
Records
119
Agent score
52%

What's inside Chainlink Solana Starter Kit

  1. What is Chainlink CCIP and its features

    main

    Chainlink Cross-Chain Interoperability Protocol (CCIP) enables communication between Solana and EVM-compatible blockchains (such as Ethereum, Base, Optimism, BSC, and Arbitrum).

    Key features include:

    • Token Transfers: Moving tokens between EVM chains and Solana.
    • Arbitrary Messaging: Sending custom data between chains.
    • CCIP Receivers: Deploying and managing programs designed to receive cross-chain messages.

    Note: The setup for Cross-chain token (CCT) pools (including burn-mint pools, admin registry, and ALT management) is handled in the ccip-solana-bs58-generator repository, not this one.

  2. How the CCIP Solana SDK architecture works

    main

    The SDK is built with a modular architecture to separate concerns:

    Core Components

    • CCIPClient: The primary entry point for fee calculation and message sending.
    • CCIPAccountReader: Used for fetching and decoding on-chain CCIP accounts.
    • Models: Shared type definitions.

    Bindings

    • Accounts: Auto-generated Anchor bindings for on-chain account structs.
    • Instructions: Auto-generated Anchor bindings for on-chain instructions.
    • Types: Core CCIP protocol data structures.

    Utilities

    • SolanaAccountManager: Manages Solana account write permissions and bitmap calculations.
    • PDAs: Utilities for deriving Program Derived Addresses.
    • Logger: Structured logging.
    • Conversion & Error Handling: Helpers for data types and standardized error management.
  3. Derive CCIP Program Derived Addresses (PDAs)

    main

    The SDK provides utilities for deriving all necessary PDAs.

    Token Pool Signer PDAs

    Crucial: There are two types of signers. For token transfers, you must use a dynamic derivation because the actual PDA depends on both a seed and the specific pool program ID (found in the token admin registry).

    • For fee payments (e.g., SOL): Use findFeeBillingSignerPDA(programId).
    • For token transfers (e.g., LINK): Use findDynamicTokenPoolsSignerPDA(mint, routerProgramId, connection) or findTokenPoolsSignerWithAccountReader(...).

    Other Common PDAs

    • findConfigPDA(programId): Router configuration.
    • findTokenAdminRegistryPDA(mint, programId): Token admin registry.
    • findDestChainStatePDA(chainSelector, programId): Destination chain state.
    • findNoncePDA(chainSelector, authority, programId): Nonce PDA.
    // For fee token delegation (e.g., SOL)
    const [feeBillingSigner] = findFeeBillingSignerPDA(routerProgramId);
    
    // For token transfer delegation (e.g., BnM, LINK)
    const [tokenPoolsSigner] = await findDynamicTokenPoolsSignerPDA(
      tokenMint,
      routerProgramId,
      connection
    );
  4. Install and prepare the CCIP scripts environment

    main

    General Requirements

    • Node.js v20+ (v23.11.0 recommended)
    • Yarn package manager
    • Git

    Solana (SVM) Specifics

    • Solana CLI tools
    • Wallet with SOL on Devnet
    • Default keypair at ~/.config/solana/id.json (or optional test keypair at ~/.config/solana/keytest.json)

    Ethereum (EVM) Specifics

    • Web3 wallet (e.g., MetaMask)
    • Test ETH on supported networks
    • Private key configuration for scripts

    Installation Commands

    # Install all dependencies
    yarn install
    
    # Verify TypeScript compilation
    yarn type-check
  5. Send tokens from Ethereum to Solana using CCIP

    main

    To transfer tokens from an EVM chain to Solana, use the provided scripts to estimate fees, acquire test tokens, and execute the transfer. The transfer command requires a token address and an amount.

    # Estimate fees (read-only, no private key required)
    yarn evm:check-fee
    
    # Get test tokens
    yarn evm:token:drip
    
    # Send BnM tokens to Solana
    yarn evm:transfer --token 0x779877A7B0D9E8603169DdbD7836e478b4624789 --amount 1000000000000000000
  6. Requirements for running the Solana Starter Kit

    main

    To run the demo on Devnet, ensure your environment meets the following specifications:

    • Node.js: v20+ (v23.11.0 recommended)
    • Rust: version 1.87 and above recommended
    • Solana CLI: v0.31.1 recommended
    • Anchor: v2.1.21 and above recommended
    • C Compiler: e.g., GCC
  7. Set up environment for EVM CCIP scripts

    main

    To use the EVM CCIP scripts, you must configure environment variables in a .env file located in the project root. You need an EVM private key and at least one RPC URL for your target network.

    Required Variables:

    • EVM_PRIVATE_KEY: Your EVM wallet private key.

    Network-specific RPC URLs (at least one required):

    • EVM_RPC_URL (e.g., Ethereum Sepolia)
    • BASE_SEPOLIA_RPC_URL (e.g., Base Sepolia)
    • OPTIMISM_SEPOLIA_RPC_URL (e.g., Optimism Sepolia)
    • BSC_TESTNET_RPC_URL (e.g., BSC Testnet)
    • ARBITRUM_SEPOLIA_RPC_URL (e.g., Arbitrum Sepolia)
    # Example .env file
    EVM_PRIVATE_KEY=your_private_key_here
    EVM_RPC_URL=https://your-ethereum-sepolia-rpc
  8. Quick Start for Solana (SVM) CCIP Development

    main

    To develop with CCIP on Solana (SVM), follow these steps to prepare your environment and execute cross-chain operations:

    1. Setup: Install dependencies and ensure your wallet is funded with SOL.
    2. CCIP Preparation: You must prepare your tokens before sending messages. Run these commands in order:
      • yarn svm:token:wrap (Wrap SOL to wSOL for CCIP fees)
      • yarn svm:token:delegate (Delegate token authority to the CCIP router)
      • yarn svm:token:check (Verify delegations and balances)
    3. Send Messages: Once prepared, use one of the following to interact with the router:
      • yarn svm:token-transfer (Transfer tokens between chains)
      • yarn svm:arbitrary-messaging (Send arbitrary data)
      • yarn svm:data-and-tokens (Send both data and tokens)

    Note: Cross-chain token (CCT) pool setup is handled by the ccip-solana-bs58-generator repository.

    # 1. Setup
    yarn install
    
    # 2. CCIP Preparation
    yarn svm:token:wrap
    yarn svm:token:delegate
    yarn svm:token:check
    
    # 3. Send messages
    yarn svm:token-transfer