简体   繁体   中英

How to get list of Tokens in a Solana Wallet

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'));

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')));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM