Skip to main content
added 1 character in body
Source Link
Jonas H.
  • 7.2k
  • 1
  • 7
  • 26

If I understood you right, your code works, but you need to get the TokenAccount address from the wallet right?

What you can do itis: call getTokenAccountsByOwner(pubKey) and then check all the token accounts TokenAccountInfo mint if its the mint of your specific token.

Then you can call getTokenAccountBalance on that account like you already do.

To make it more performant you can directly specify the mint in the getTokenAccountsByOwner function. Then you can save the token account in the client and only call getTokenAccountBalance form then on.

If I understood you right, your code works, but you need to get the TokenAccount address from the wallet right?

What you can do it call getTokenAccountsByOwner(pubKey) and then check all the token accounts TokenAccountInfo mint if its the mint of your specific token.

Then you can call getTokenAccountBalance like you already do.

To make it more performant you can directly specify the mint in the getTokenAccountsByOwner function. Then you can save the token account in the client and only call getTokenAccountBalance form then on.

If I understood you right, your code works, but you need to get the TokenAccount address from the wallet right?

What you can do is: call getTokenAccountsByOwner(pubKey) and then check all the token accounts TokenAccountInfo mint if its the mint of your specific token.

Then you can call getTokenAccountBalance on that account like you already do.

To make it more performant you can directly specify the mint in the getTokenAccountsByOwner function. Then you can save the token account in the client and only call getTokenAccountBalance form then on.

Source Link
Jonas H.
  • 7.2k
  • 1
  • 7
  • 26

If I understood you right, your code works, but you need to get the TokenAccount address from the wallet right?

What you can do it call getTokenAccountsByOwner(pubKey) and then check all the token accounts TokenAccountInfo mint if its the mint of your specific token.

Then you can call getTokenAccountBalance like you already do.

To make it more performant you can directly specify the mint in the getTokenAccountsByOwner function. Then you can save the token account in the client and only call getTokenAccountBalance form then on.