For AI agents: a documentation index is available at /llms.txt. A markdown version of this page is available at the same URL with .md appended (or via Accept: text/markdown).
Skip to main content

Quickstart

This quickstart guide will help you set up and make calls on the Solana network using the Infura endpoints.

Prerequisites​

Ensure you have an API key with the Solana network enabled.

Make calls​

curl​

Run the following command in your terminal, replacing <YOUR-API-KEY> with your actual Infura API key:

curl https://solana-mainnet.infura.io/v3/<YOUR-API-KEY> \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method": "getSlot", "params": [], "id": 1}'

JavaScript​

  1. Create a project directory, and inside the directory initialize the project:

    npm init -y
  2. In your project directory, install the latest version of the JavaScript SDK.

  3. Create your JavaScript file (index.js in this example) and copy the following code:

    Replace <YOUR-API-KEY> with your actual Infura API key.

    index.js
    import { createSolanaRpc } from '@solana/kit'

    const rpc = createSolanaRpc('https://solana-mainnet.infura.io/v3/<YOUR-API-KEY>')

    async function fetchCurrentSlot() {
    try {
    const slot = await rpc.getSlot().send()
    console.log('Current slot:', slot)
    } catch (error) {
    console.error('Error fetching slot:', error)
    }
    }

    fetchCurrentSlot()
  4. Run the code using the following command:

    node index.js

Rust​

  1. Create a project directory, and inside the directory initialize the project:

    cargo init
  2. In your project directory, install the Rust dependencies.

    cargo add solana-sdk solana-client
  3. In the src/main.rs paste the following code:

    Replace <YOUR-API-KEY> with your actual Infura API key.

    main.rs
    use solana_client::rpc_client::RpcClient;

    fn main() {
    let url = "https://solana-mainnet.infura.io/v3/<YOUR-API-KEY>";
    let client = RpcClient::new(url.to_string());

    match client.get_slot() {
    Ok(slot) => println!("Current slot: {}", slot),
    Err(err) => eprintln!("Error fetching slot: {}", err),
    }
    }
  4. Run the code using the following command:

    cargo run

Next steps​

Now that you have successfully made a call to the Solana network, you can explore more functionalities and APIs provided by Infura. Here are some suggestions:

  • Explore other Solana APIs: Infura supports a wide range of APIs. You can find more information in the JSON-RPC API method documentation.

  • Try out different networks: Infura supports multiple networks including Ethereum, Linea, Polygon, Optimism, and more.

  • Monitor your usage: Monitor your usage on the Infura dashboard to ensure you're not hitting your rate limits.

If you have questions or run into issues, contact Infura.