Currently, I can do this using a cURL request:
curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
{
"jsonrpc": "2.0",
"id": 1,
"method": "getMultipleAccounts",
"params": [
[
"AWaJ4oXHWXaNnFJirydYdXdD3Yjmkgh6rYhmwAyB5d8o",
"yT2bBMrE4AVG3BM8LHjDSr1yketzabmfp3rYimS36C9"
],
{
"encoding": "jsonParsed"
}
]
}
'
This will return a response that contains JSON parsed data that is human readable:
{
"jsonrpc": "2.0",
"result": {
"context": {
"apiVersion": "1.10.29",
"slot": 150852465
},
"value": [
{
"data": {
"parsed": {
"info": {
"isNative": false,
"mint": "4koajw4GkCgVNEjN14xmjCtMVYNASdDj7RtrAA4SZwnK",
"owner": "GkeDRfHcACap2CM9oaWrb3QUMG7pk6F6EMYca8Lu52t8",
"state": "initialized",
"tokenAmount": {
"amount": "12998020",
"decimals": 6,
"uiAmount": 12.99802,
"uiAmountString": "12.99802"
}
},
"type": "account"
},
"program": "spl-token",
"space": 165
},
"executable": false,
"lamports": 2039280,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 348
}
]
},
"id": 1
}
I want to use the same method by using the @solana/web3.js library:
const accounts = await connection.getMultipleAccountsInfo([new PublicKey("AWaJ4oXHWXaNnFJirydYdXdD3Yjmkgh6rYhmwAyB5d8o"), new PublicKey("yT2bBMrE4AVG3BM8LHjDSr1yketzabmfp3rYimS36C9")]);
This doesn't return JSON parsed account data, but it's using Buffer
. I can use the method connection.getParsedAccountInfo()
to get the JSON parsed data and it works great, but it's not efficient. I will be parsing multiple token balances from 500+ accounts. Is it possible to convert the Buffer structure to parse token balance from it? I would need the uiAmountString:
Everything works perfectly fine by using a cURL request, but the web3.js library doesn't seem to have this implemented?