2 years ago

#71890

test-img

1977

getTokenAccountsByOwner - odd result?

I have created a token using SPL. And I have minted some supply into a wallet address on testnet

Token address: 668JcT5AiLYNi8XVaDNntTaLWzuQ8EnbBzA9zSmKbipW (https://explorer.solana.com/address/668JcT5AiLYNi8XVaDNntTaLWzuQ8EnbBzA9zSmKbipW?cluster=testnet)

Recipient wallet address: A9CCmocX2jNXMFuqqHg6uxT4sptFTTws3qXn5tTo5sy9 (https://explorer.solana.com/address/A9CCmocX2jNXMFuqqHg6uxT4sptFTTws3qXn5tTo5sy9/tokens?cluster=testnet)

In the token holdings section of the recipient I can see a balance of .026203001

Meanwhile back in my React frontend I am trying to display the balances for various SPL tokens held by the recipient address

import * as solanaWeb3 from '@solana/web3.js';
..
..

const solanaWeb3Connection = new solanaWeb3.Connection(solanaWeb3.clusterApiUrl('testnet'))

const balance = await solanaWeb3Connection.getBalance( new solanaWeb3.PublicKey(metadata.publicAddress)) //SOL balance I guess

const tokenAccounts = await solanaWeb3Connection.getTokenAccountsByOwner(new solanaWeb3.PublicKey(<recipient address>), 
    { mint : new solanaWeb3.PublicKey(<spl token address>) }, "finalized")

but I get an odd response showing a lamports value of 2039280 (see below). What is the correct way retrieve the .026203001 value

{
  "context": {
    "slot": 113853707
  },
  "value": [
    {
      "account": {
        "data": {
          "type": "Buffer",
          "data": [
            '.....'
          ]
        },
        "executable": false,
        "lamports": 2039280,
        "owner": {
          "_bn": "06ddf6e1d765a193d9cbe146ceeb79ac1cb485ed5f5b37913a8cf5857eff00a9"
        },
        "rentEpoch": 276
      },
      "pubkey": {
        "_bn": "f3b25516176b4d976c2808080643441ded068758cf33244fad11d6e388d54f55"
      }
    }
  ]
}

solana-web3js

solana-program-library

0 Answers

Your Answer

Accepted video resources