如何从类型脚本中读取缓冲区数据?
我想使用公钥来获取我拥有的所有令牌列表。我试图得到这个,但正在返回一个空的对象数组。
import {Connection, Keypair} from "@solana/web3.js";
const Solana = new Connection("https://api.testnet.solana.com/","confirmed")
const getInfo = async () => {
const recentInfo = await Solana.getEpochInfo()
const DEMO_FROM_SECRET_KEY = new Uint8Array([
223, 119, 171, 5, 237, 138, 42, 140, 176, 163, 74,
107, 25, 143, 90, 97, 250, 158, 203, 102, 238, 19,
77, 228, 211, 238, 147, 149, 40, 50, 211, 155, 51,
207, 14, 53, 86, 230, 164, 27, 14, 202, 78, 181,
185, 250, 16, 52, 134, 242, 96, 16, 12, 67, 2,
178, 106, 241, 156, 212, 11, 150, 114, 72])
const keypair = Keypair.fromSecretKey(DEMO_FROM_SECRET_KEY)
console.log("=============get account info==============")
async function fetchaccountdata() {
const accountinfo = await Solana.getParsedAccountInfo(keypair.publicKey,"max")
const accountinfodata = JSON.stringify(accountinfo)
const accountinfodata2 = JSON.parse(accountinfodata)
console.log(accountinfo)
console.log("=============get account info==============")
console.log(accountinfodata)
console.log(accountinfodata2)
}
fetchaccountdata()
}
getInfo()
终端是
accountinfodata = {"context":{"slot":94636033},"value":{"data":{"type":"Buffer","data":[]},"executable":false,"lamports":42784111360,"owner":{"_bn":"00"},"rentEpoch":231}}
accountinfodata2 = {
context: { slot: 94636033 },
value: {
data: { type: 'Buffer', data: [] },
executable: false,
lamports: 42784111360,
owner: { _bn: '00' },
rentEpoch: 231
}
}
accountinfo 对象的数据为空数组。如何阅读信息?