Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
Solana - How to get the balance from my Phantom wallet?

I'm working on a web app that can connect to Phantom Wallet. I've established the connection and have successfully retrieved the wallet's public key. The problem is, I can't seem to find any solution to get the account balance.

For reference, I wanted to display the account balance just like how solanart.io displays it.

Note that I've gone through all related docs (Solana/web3.js, Solana JSON RPC API etc). Please guide me as I'm still new to JSON RPC API.

For a heads up, I'm using vanilla js.

try {
      const resp = window.solana.request({
        method: "getAccountTokenBalance",
        params: [
          id, //wallet's public key
          {
            encoding: "base58",
          },
        ],
      });
      console.log(resp);
    } catch(err) {
      // error message
    }

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

The RPC method that you're using does not exist. You'll want to use getBalance to get the SOL on the wallet: https://docs.solana.com/developing/clients/jsonrpc-api#getbalance

To get all of the non-SOL token balances owned by that wallet, you'll have to use getTokenAccountsByOwner using that wallet id: https://docs.solana.com/developing/clients/jsonrpc-api#gettokenaccountsbyowner

about 4 years ago · Juan Pablo Isaza Relatório

0

This method works for me to get SOL Balance

  const [userSOLBalance, setSOLBalance] = useState<number>()
 if (wallet.publicKey) {
  const SOL = connection.getAccountInfo(wallet.publicKey)
  SOL.then((res) => setSOLBalance(res.lamports / LAMPORTS_PER_SOL))
}
about 4 years ago · Juan Pablo Isaza Relatório

0

import { useWallet } from '@solana/wallet-adapter-react'
import { LAMPORTS_PER_SOL,clusterApiUrl } from '@solana/web3.js'
import * as anchor from '@project-serum/anchor'


const wallet = useWallet()
const SOLANA_HOST = clusterApiUrl("devnet")
const connection = new anchor.web3.Connection(SOLANA_HOST)

let lamportBalance
if (wallet?.publicKey) {
        const balance = await connection.getBalance(wallet.publicKey)
        lamportBalance=(balance / LAMPORTS_PER_SOL)
      }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda