Complete guide to using Axios as your Solana RPC client. Learn how to integrate, configure, and build with Axios.
Install Axios via npm or yarn:
npm install axiosyarn add axiosCreate 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)Create configurable instances for different Solana networks (mainnet, devnet, testnet) with custom endpoints.
Add middleware to inject wallet signatures, authentication tokens, or custom headers before each request.
Structured error responses with detailed information about RPC failures, network issues, and transaction errors.
Send and simulate transactions with built-in serialization, signing support, and confirmation tracking.
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'
}
})Fetches the balance of a Solana account.
const balance = await rpc.account.getBalance(
'YourPublicKeyHere...'
)
console.log(balance.data.lamports)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
})Sends a signed transaction to the Solana network.
const result = await rpc.tx.sendSigned({
signature: '...base58-signed-transaction...'
})
console.log(result.data.txHash)