I am able to get the tokens in my wallet but then am not able to derive the mint address from the received data. I want to get the mint address of all tokens in my wallet to then use that with some APIs. Usning solana/web3.js version 2.0 and there arent much examples out yet. Appreciate the help.
const TOKEN_PROGRAM_ID = address('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA')
const { value: tokensInWallet} = await rpc
.getTokenAccountsByOwner(
address('XXX'),
{ programId: TOKEN_PROGRAM_ID },
{ encoding: 'base64'}
)
.send();
console.log(tokensInWallet);
//expect mint jtojtomepa8beP8AuQc6eXt5FriJwfFMwQx2v2f9mCL for JTO token
tokensInWallet.map(tokenAccount => {
const encoded = getBase64Encoder().encode(tokenAccount.account.data[0]);
console.log(encoded);
//now turn into this format of the mint
//base58 encode
const mint = getBase58Encoder().encode(tokenAccount.pubkey);
console.log(Buffer.from(mint).toString('base64'));
})
I am trying to somehow encode / decode the string in data but am not getting anywhere
tokenInWallet looks like that
[
{
account: {
data: [
"Cvz4louNq4hIHi0q5onJUsdXrrpkPjkZ6J8uVXlcdsEpwCylBRLH6qBLpURZ/jc3h9wTxgzMrD4rEPcp06WvvwAoa+4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"base64",
],
executable: false,
lamports: 2039280n,
owner: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
rentEpoch: 18446744073709551615n,
space: 165n,
},
pubkey: "3UoZPNLp1eynjjCEEcKyv3VcXtoZCe5GdEt2agDezD31",
},
]