Getting started overview

Interacting with the Solana blockchain primarily occurs through its JSON RPC API. This guide outlines the fundamental steps to connect to a Solana RPC endpoint, generate necessary credentials, and execute a basic request to confirm connectivity and functionality. The process involves selecting an RPC endpoint, understanding transaction fees, and constructing JSON-RPC 2.0 compliant requests.

Before making requests, developers should understand the network environments available:

  • Mainnet-beta: The primary Solana production network, where real SOL tokens and applications operate. Transactions incur actual fees in SOL.
  • Devnet: A public testnet for development and testing. It uses a separate token supply from Mainnet-beta and allows developers to experiment without real financial risk. Faucets are available to obtain Devnet SOL for testing transactions.
  • Testnet: Another public test environment, primarily used by the Solana team for testing new features before wider release.
  • Localhost: Running a Solana validator on a local machine provides a private network for isolated development and testing. This is useful for rapid iteration without network latency or dependencies on public infrastructure.

For initial development and testing, Devnet is generally recommended due to its stability and free test SOL availability. Production applications will deploy to Mainnet-beta.

Quick-reference for getting started

Step What to do Where
1. Choose Endpoint Select a Solana RPC endpoint (Devnet for testing). Solana RPC Endpoints documentation
2. Install CLI (Optional but Recommended) Install the Solana Command Line Interface for key generation and basic interactions. Solana CLI installation guide
3. Generate Keypair Create a new Solana keypair to represent an account. Solana CLI: solana-keygen new
4. Fund Account (Devnet) Airdrop Devnet SOL to your new account for testing transactions. Solana CLI: solana airdrop 1 <YOUR_PUBKEY> --url devnet
5. Make First Request Send a basic JSON RPC request (e.g., getHealth or getBalance). Using curl or an HTTP client in your preferred language

Create an account and get keys

While basic queries to the Solana JSON RPC (like getHealth) do not require an account, submitting transactions or querying account-specific data necessitates a Solana keypair. A keypair consists of a public key (your address) and a private key (used for signing transactions).

The simplest way to create a keypair is using the Solana Command Line Interface (CLI). If you haven't already, install the CLI by following the Solana CLI installation instructions. Once installed, use the following command:

solana-keygen new --outfile ~/.config/solana/id.json

This command generates a new keypair and saves it to the specified file (id.json by default in the Solana config directory). The output will display your public key, which serves as your Solana address. Securely back up your id.json file and never share your private key. Losing your private key means losing access to your funds and assets on the blockchain.

To view your public key after creation:

solana-keygen pubkey

For testing on Devnet, you will need some test SOL. You can request an airdrop to your new public key:

solana airdrop 1 <YOUR_PUBKEY> --url devnet

Replace <YOUR_PUBKEY> with the public key you just generated. This command requests 1 SOL from the Devnet faucet. You can check your balance using solana balance <YOUR_PUBKEY> --url devnet.

Your first request

To make your first request, you'll need a Solana JSON RPC endpoint. For development, the official Devnet endpoint is https://api.devnet.solana.com. For production, you would typically use a paid RPC provider or run your own node for reliability and higher rate limits, as public endpoints can be rate-limited.

All requests to the Solana JSON RPC API are HTTP POST requests with a JSON-RPC 2.0 payload. The Content-Type header should be application/json.

Let's start with a simple request to check the health of the RPC node using the getHealth method:

curl -X POST -H "Content-Type: application/json" -d \
  '{ "jsonrpc": "2.0", "id": 1, "method": "getHealth" }' \
  https://api.devnet.solana.com

A successful response indicates the RPC node is healthy:

{
  "jsonrpc": "2.0",
  "result": "ok",
  "id": 1
}

Now, let's retrieve the balance of the account you created earlier. Replace <YOUR_PUBKEY> with your actual public key:

curl -X POST -H "Content-Type: application/json" -d \
  '{ "jsonrpc": "2.0", "id": 1, "method": "getBalance", "params": ["<YOUR_PUBKEY>"] }' \
  https://api.devnet.solana.com

A successful response will look similar to this, showing your balance in lamports (1 SOL = 1,000,000,000 lamports):

{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "apiVersion": "1.17.15",
      "slot": 250000000
    },
    "value": 1000000000
  },
  "id": 1
}

These examples demonstrate direct interaction via curl. For more complex applications, you would typically use one of the official Solana SDKs (e.g., @solana/web3.js for JavaScript/TypeScript, or solana-sdk for Rust) which abstract away the raw JSON RPC calls.

Common next steps

After successfully making your first requests, consider these common next steps to deepen your understanding and capabilities with Solana JSON RPC:

  1. Explore more RPC methods: The Solana JSON RPC offers a wide range of methods for querying account information, transaction details, block data, and more. Refer to the Solana RPC API reference for a complete list and their parameters.
  2. Use an SDK: For building applications, using a Solana SDK is generally more efficient than crafting raw JSON RPC requests. SDKs provide type-safe wrappers and convenience functions for common operations. Popular choices include @solana/web3.js for JavaScript/TypeScript and solana-sdk for Rust.
  3. Understand transaction lifecycle: Learn about how transactions are signed, serialized, sent to the network, and confirmed. This involves understanding concepts like recent blockhashes, transaction fees, and commitment levels.
  4. Implement WebSocket subscriptions: For real-time updates (e.g., tracking account balance changes or new blocks), utilize the Solana JSON RPC's WebSocket interface. This allows for push notifications rather than constant polling.
  5. Choose a dedicated RPC provider: For production applications, relying solely on public Solana endpoints is often insufficient due to rate limits and potential instability. Services like QuickNode, Alchemy, or Triton One offer dedicated RPC endpoints with higher performance and reliability.
  6. Develop a simple DApp: Build a basic decentralized application (DApp) that interacts with a smart contract (program) on Solana. This will involve deploying a program and then writing client-side code to interact with it via the RPC.
  7. Review security best practices: Understand how to secure your private keys, protect against common attacks, and validate data received from RPC endpoints. The Mozilla Web Security documentation provides general secure coding practices applicable to API interactions.

Troubleshooting the first call

Encountering issues during your first Solana JSON RPC call is common. Here are some troubleshooting steps:

  • Check the endpoint URL: Ensure the URL you are using (e.g., https://api.devnet.solana.com) is correct and matches the network you intend to interact with (Devnet, Mainnet-beta, etc.).
  • Verify JSON-RPC 2.0 format: Double-check your request payload. It must strictly adhere to the JSON-RPC 2.0 specification, including jsonrpc: "2.0", id, method, and correctly formatted params array if applicable. A missing comma or misplaced brace can cause errors.
  • Content-Type header: Ensure your HTTP request includes the header Content-Type: application/json. Without it, the server may not correctly parse your request body.
  • Network connectivity: Confirm your internet connection is active and that no firewalls or proxies are blocking access to the RPC endpoint. You can test basic connectivity with a simple ping api.devnet.solana.com.
  • Rate limits: Public RPC endpoints often have strict rate limits. If you make too many requests too quickly, you might receive HTTP 429 (Too Many Requests) errors. Wait a moment and try again, or consider using a dedicated RPC provider.
  • Method parameters: For methods like getBalance, ensure the public key provided in the params array is a valid Solana address and belongs to the correct network (e.g., a Devnet public key on the Devnet RPC).
  • Error messages: Carefully read any error messages returned in the JSON response. They often contain specific clues about what went wrong (e.g., "Invalid param", "Method not found").
  • Consult Solana documentation: The Solana HTTP RPC API documentation is the authoritative source for method signatures and expected parameters. Cross-reference your request against the documented requirements.
  • Check Solana status: Occasionally, the Solana network itself or public RPC nodes might experience temporary outages or degradation. Check the Solana Status page for any ongoing issues.