getBalance
https://api.triport.io/v1/solReturns the lamport balance of the account of the provided Solana public key.
getBalance returns the balance, in lamports, of the account identified by
a base-58 public key. One lamport is 0.000000001 SOL (1 SOL = 1,000,000,000
lamports), so divide the returned value by 1e9 to display a SOL amount.
The balance is reported relative to a particular slot, returned in the
context object. Use the optional commitment config to control how finalized
that slot must be, and minContextSlot to require that the node has reached at
least a given slot before serving the request.
This is the canonical way to read a wallet or program-owned account's native
SOL balance. To read SPL token balances instead, use the token-account methods
rather than getBalance.
Parameters
JSON-RPC params is a positional array: [pubkey, config?].
pubkeystring (base-58)required^[1-9A-HJ-NP-Za-km-z]{32,44}$.configobjectoptionalcommitmentstringoptionalprocessed, confirmed, or finalized.minContextSlotintegeroptionalResponse
The example above queries the Wrapped-SOL mint and returns 10000000000
lamports (10 SOL).
resultobjectRpcResponseU64 envelope.result.contextobjectresult.context.slotintegerresult.context.apiVersionstringresult.valueintegerErrors
Errors are returned in the standard JSON-RPC error envelope. See the shared errors reference for the full envelope shape and shared codes.
| Code | Meaning | When it happens |
|---|---|---|
-32602 | Invalid params | pubkey is missing, not a valid base-58 string, or config is malformed. |
401 | Unauthorized | Missing or invalid Authorization: Bearer key. |
429 | Rate limited | More than your tier's RPS for sol_read_rpc (20 / 60 / 200 / 600). |
Examples
JavaScript (fetch)
const res = await fetch("https://api.triport.io/v1/sol", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.TRIPORT_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "getBalance",
params: ["So11111111111111111111111111111111111111112"],
}),
});
const { result } = await res.json();
console.log(`Balance: ${result.value / 1e9} SOL (slot ${result.context.slot})`);TypeScript SDK (@triport/sdk)
import { TriportClient } from "@triport/sdk";
const client = new TriportClient({ apiKey: process.env.TRIPORT_API_KEY });
const { context, value } = await client.solana.getBalance(
"So11111111111111111111111111111111111111112",
{ commitment: "finalized" }
);
console.log(`Balance: ${value / 1e9} SOL (slot ${context.slot})`);Python (triport-sdk)
import os
from triport import TriportClient
client = TriportClient(api_key=os.environ["TRIPORT_API_KEY"])
result = client.solana.get_balance(
"So11111111111111111111111111111111111111112",
commitment="finalized",
)
print(f"Balance: {result['value'] / 1e9} SOL (slot {result['context']['slot']})")Notes
- Lamports, not SOL:
valueis always an integer count of lamports. Divide by1e9for a SOL figure. - Non-existent accounts: an account that has never been funded returns
value: 0. - Commitment defaults: when
commitmentis omitted, the node's default commitment applies. Passfinalizedfor the strongest consistency guarantee. - Related methods: use
getMultipleAccounts/getAccountInfoto read full account data alongside the balance, andgetSlotto inspect the current slot the cluster has reached.