Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
Solana JSON RPC API getBalance method always returns 0

I am trying to get the SOL balance from a phantom wallet. The wallet has > 0 SOL in it, so I know that something is wrong when I make the call. Here is my code:

(async () => {
            const connection = new solanaWeb3.Connection(
                solanaWeb3.clusterApiUrl('devnet'),
                'confirmed',
            );

            if (phantom && phantom.publicKey !== null) {
                const balance = await connection.getBalance(phantom.publicKey)
                console.log(balance);
            }
})();

What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your issue looks like it might be with the assignment to phantom.publicKey itself and not your code. Replacing phantom.public key with a defined public key below works.

const solanaWeb3 = require('@solana/web3.js');

const public_key=new solanaWeb3.PublicKey("your Solana public address with non-0 balance");

(async () => {
            const connection = new solanaWeb3.Connection(
                solanaWeb3.clusterApiUrl('devnet'),
                'confirmed',
            );

            if (public_key !== null) {
                const balance = await connection.getBalance(public_key);
                console.log(balance)
            }
})();

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!