admin管理员组文章数量:1359268
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",
},
]
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",
},
]
Share
Improve this question
asked Mar 27 at 16:12
Sebastian_BSebastian_B
615 bronze badges
1 Answer
Reset to default 0Solved this by using
{ encoding: 'jsonParsed'}
which gives the parsed data including balance and token mint
本文标签: How to get mint address of tokens in wallet with solanaweb3js v2Stack Overflow
版权声明:本文标题:How to get mint address of tokens in wallet with solanaweb3.js v2 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744081034a2587642.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论