Solana
Pronto para usar isso em produção?
O plano gratuito cobre projetos pessoais. O pay-as-you-go escala sem cartão de crédito.
Solana
O plano gratuito cobre projetos pessoais. O pay-as-you-go escala sem cartão de crédito.
Tokens on Solana follow the SPL Token model, which keeps the definition of a token and the ownership of it in separate accounts. A mint account defines the token itself — its supply, its number of decimals, and its mint authority — while every holder owns a distinct token account that records how much of that mint they hold. So a wallet does not store balances inline; it points at one token account per mint it touches. Alongside the original SPL Token program there is now Token-2022, a second token program that adds optional features like transfer fees and confidential transfers. Token-2022 mints and accounts live under a different program id, so reads that should cover everything a wallet holds must query both programs.
getTokenAccountsByOwner requires exactly one filter: either a single mint (to find that wallet's account for one token) or a programId (to list every account under a token program). Passing both, or neither, is an error.jsonParsed encoding returns human-readable fields like tokenAmount.uiAmountString instead of a raw byte blob you have to decode yourself.amount is an integer in the mint's smallest unit. To get a human figure you must scale it by the mint's decimals — e.g. an amount of 1500000 on a 6-decimal mint is 1.5 tokens.getTokenAccountsByOwner against the Token-2022 program id to see those holdings.mint or a programId to getTokenAccountsByOwner — never both and never neither, or the call fails.tokenAmount.uiAmountString rather than the floating-point uiAmount. The string keeps full precision, while the float can round large balances.getTokenAccountBalance — not the owner wallet and not the mint. Those other addresses will not return the balance you expect.decimals rarely change, so fetch them once and cache them instead of re-reading the mint on every balance you scale.