Get Balances β Solana API
Use this endpoint to fetch the SOL balance and all SPL token balances (both spl-token and spl-token-2022) for a wallet in a single request.
A small fee is charged from the privateKey.
Endpointβ
POST https://api.pumpapi.io
Request Bodyβ
| Field | Required | Description |
|---|---|---|
action | Yes | Must be "getBalances" |
privateKey | Yes | Private key of the wallet that pays the fee. |
publicKey | No | Wallet address whose balances you want to fetch. Defaults to the address derived from privateKey. |
π¦ Code Examplesβ
- Python
- JavaScript
- Rust
- Go
import requests
url = "https://api.pumpapi.io"
data = {
"action": "getBalances",
"privateKey": "base58_private_key",
# "publicKey": "optional_other_wallet_address",
}
response = requests.post(url, json=data)
print(response.json())
import axios from "axios";
const url = "https://api.pumpapi.io";
const data = {
action: "getBalances",
privateKey: "base58_private_key",
// publicKey: "optional_other_wallet_address",
};
axios
.post(url, data)
.then((res) => console.log(res.data))
.catch((err) => console.error(err));
use reqwest::Client;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let res = client
.post("https://api.pumpapi.io")
.json(&json!({
"action": "getBalances",
"privateKey": "base58_private_key",
// "publicKey": "optional_other_wallet_address"
}))
.send()
.await?
.text()
.await?;
println!("{}", res);
Ok(())
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
url := "https://api.pumpapi.io"
data := map[string]any{
"action": "getBalances",
"privateKey": "base58_private_key",
// "publicKey": "optional_other_wallet_address",
}
jsonData, _ := json.Marshal(data)
resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonData))
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result any
_ = json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("%v\n", result)
}
Example Responseβ
solBalance is a plain number in SOL. Each entry under tokenBalances is keyed by the token mint address, and balance. Tokens sitting in non-ATA accounts are skipped.
{
"solBalance": 0.4231,
"tokenBalances": {
"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v": {
"balance": 12.5,
"tokenProgram": "spl-token"
},
"H74CYmXgMkYHYuSRsZt6RJb4NYp2u72Vw8BS5huApump": {
"balance": 1000,
"tokenProgram": "spl-token-2022"
// "frozen": true // appears only if you hit a scam token that froze your account (you can still burn such tokens)
}
}
}
Need help? Join our Telegram group.