solana web3.js getParsedTransaction有时返回null
我正在尝试使用NFT签名中的任何一个签名ID获取事务值。对于测试,我使用了相同的签名并循环100次,以确保它是具有现有值的有效签名
。由于某种原因,它有时在循环中返回零。
我正在使用QuickNode的RPC。 (每月9美元)
我是否缺少引起此问题的东西?
代码
async function test() {
for (let i = 0; i < 100; i++) {
signatures = await connection.getSignaturesForAddress(new PublicKey('BUPzNBDy3gVRRz1AqyzCDSnp15uAxh5j61dEj5GLLfx6'));
let signatures2 = signatures.map(({ signature }) => signature)
for (let a = 0; a < signatures2.length; a++) {
let txns = await connection.getParsedTransaction(signatures2[a], 'finalized')
if (!txns) {
console.log('null')
} else {
console.log('ok')
}
}
}
}
exports.get_collection_volume = (req, res) => {
test()
}
输出
0
1
2
3
null
null
6
7
null
null
null
null
12
null
14
null
16
I am trying to get transaction values using signature id from any of the NFT's signature. For a test, I used the same signature and loop it 100 times to make sure that it is a valid signature with existing value
I did console.log on the index of the for loop. For some reason, it is returning null sometimes within the loop.
I am using Quicknode's RPC. ($9/month)
Am I missing something that caused this issue?
Code
async function test() {
for (let i = 0; i < 100; i++) {
signatures = await connection.getSignaturesForAddress(new PublicKey('BUPzNBDy3gVRRz1AqyzCDSnp15uAxh5j61dEj5GLLfx6'));
let signatures2 = signatures.map(({ signature }) => signature)
for (let a = 0; a < signatures2.length; a++) {
let txns = await connection.getParsedTransaction(signatures2[a], 'finalized')
if (!txns) {
console.log('null')
} else {
console.log('ok')
}
}
}
}
exports.get_collection_volume = (req, res) => {
test()
}
Output
0
1
2
3
null
null
6
7
null
null
null
null
12
null
14
null
16
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法复制该问题(也使用Quiknode),我怀疑这可能是RPC/网络问题。
但是,在
getParsedTransaction
上循环100次可能不是验证签名有效性的最佳方法。相反,您可以使用getignaturestatus
并验证交易是否具有cresence status
,并且最终确定的
err
是null
。例如:
如果您不仅要验证签名是否有效,还可以提取解析的交易详细信息,您可以做类似的事情:
I cannot reproduce the issue (also using Quiknode), I suspect it's probably an RPC/network issue.
However, looping 100 times on
getParsedTransaction
is probably not the best way to verify the validity of a signature. Instead you can usegetSignatureStatus
and verify that the transaction has aconfirmationStatus
offinalized
and thaterr
isnull
.For instance:
If you don't just want to verify that the signature is valid but also extract parsed transaction details you can do something like: