如何将connection.onProgramAccountChange
通知数据解析为JSON?
https://solana-labs.github.io/solana-web3.js/modules.html#AccountInfo
文档将数据指定为T
类型,对我来说,它通常是一个Buffer
。
示例代码:
let progKey = new PublicKey("<program key here>");
conn.onProgramAccountChange(progKey, programCallback);
function programCallback(keyedAccountInfo: KeyedAccountInfo, context: Context) {
let data = keyedAccountInfo.accountInfo.data.toString("hex");
let ownerId = keyedAccountInfo.accountInfo.owner.toBase58();
let accId = keyedAccountInfo.accountId.toBase58();
console.log(`======
owner: ${ownerId}
accId: ${accId}
data: ${data}`);
}
数据类型实际上只是这个特定实例中的一个缓冲区,还是需要做一些额外的事情来对其进行解码?将其解码为十六进制,utf8、base64和base58不起作用。
发布于 2022-02-08 03:41:53
尽管这是programSubscribe
,但通知格式与getProgramAccounts
相同。因此,答案可以在我的另一个答案中找到:https://stackoverflow.com/a/71028298/7841421
https://stackoverflow.com/questions/71027665
复制相似问题