getBalance
The getBalance RPC method provides a simple and efficient way to retrieve the native SOL balance of any account on the Solana blockchain. The balance is returned in lamports.
🎯 Primary Use Case
🛠 Parameters
const fetch = require('node-fetch');
async function getBalance(rpcUrl) {
try {
const response = await fetch(rpcUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getBalance',
"params": [
"4UJuvGZ7Ge8H3je63Nsb9ZRNVBAd3CG2ajibnRaVSbw5"
]
}),
});
const data = await response.json();
// Print the exact full response
console.log('Full RPC Response:');
console.log(JSON.stringify(data, null, 2));
return data;
} catch (error) {
console.error('Error getting health:', error.message);
return null;
}
}
// Example usage
const RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key';
getBalance(RPC_URL);🧠 Developer Tips (with CoinVera)
Last updated