Home > Back-end >  How to get list of Tokens in a Solana Wallet
How to get list of Tokens in a Solana Wallet

Time:12-12

I'm trying to get list of owned tokens from a wallet address. In the solana web3 documentation, there is a property of Connecton called getTokenAccountsByOwner, but I'm getting type error: mintAddress.toBase58 is not a function.

Here's the code I use:

const solanaWeb3 = require('@solana/web3.js');
const { Connection, programs } = require('@metaplex/js');
const axios = require('axios');

..

console.log(solanaConnection.getTokenLargestAccounts('2MTPtFo78QzWJaK9PGk9pZm9dFrVVSBGCRWPpND25GAe'));

CodePudding user response:

It looks like there are some bits mixed around between your question and your code, since the question references getTokenAccountsByOwner but then the code shows getTokenLargestAccounts.

Either way, you're passing in a string, when you should be passing in a PublicKey. You can instead try:

console.log(solanaConnection.getTokenLargestAccounts(new PublicKey('2MTPtFo78QzWJaK9PGk9pZm9dFrVVSBGCRWPpND25GAe')));
  • Related