Documentation

Complete guide to using Axios as your Solana RPC client. Learn how to integrate, configure, and build with Axios.

Quick Start

Installation

Install Axios via npm or yarn:

npm install axios
yarn add axios

Basic Usage

Create an instance and start making RPC calls:

import axios from 'axios'

// Create RPC instance
const rpc = axios.create({
  endpoint: 'https://api.mainnet-beta.solana.com'
})

// Get balance
const balance = await rpc.account.getBalance(
  'YourPublicKeyHere...'
)

console.log(balance.data.lamports)

Core Concepts

RPC Instance

Create configurable instances for different Solana networks (mainnet, devnet, testnet) with custom endpoints.

Request Interceptors

Add middleware to inject wallet signatures, authentication tokens, or custom headers before each request.

Error Handling

Structured error responses with detailed information about RPC failures, network issues, and transaction errors.

Transaction Handling

Send and simulate transactions with built-in serialization, signing support, and confirmation tracking.

API Reference

axios.create(config)

Creates a new Axios instance with custom configuration.

const rpc = axios.create({
  endpoint: 'https://api.mainnet-beta.solana.com',
  timeout: 30000,
  headers: {
    'Content-Type': 'application/json'
  }
})

rpc.account.getBalance(pubkey)

Fetches the balance of a Solana account.

const balance = await rpc.account.getBalance(
  'YourPublicKeyHere...'
)
console.log(balance.data.lamports)

rpc.interceptors.request.use(handler)

Adds a request interceptor to modify requests before sending.

rpc.interceptors.request.use(async (config) => {
  config.headers['x-wallet-sign'] = 
    await wallet.sign(config.bodyHash)
  return config
})

rpc.tx.sendSigned(transaction)

Sends a signed transaction to the Solana network.

const result = await rpc.tx.sendSigned({
  signature: '...base58-signed-transaction...'
})
console.log(result.data.txHash)

Examples

Building a Solana Dashboard

Use Axios to fetch account balances, transaction history, and token holdings for a wallet dashboard.

Payment Gateway Integration

Implement a payment gateway that accepts SOL payments with transaction confirmation and webhook notifications.

Trading Bot with RPC

Build automated trading bots that monitor Solana DEX pools and execute trades based on price signals.

Ready to Start Building?

Try Axios in the playground or install the package to start building your Solana applications.