如何读取未发出的以太坊合同存储值?

发布于 2025-02-04 22:41:23 字数 656 浏览 1 评论 0原文

我想阅读'0x9ec5557208CB28A7714A2EA3468BD9D5BB15125'的合同存储空间。 我尝试过 -

const Web3 = require('web3')
const rpcURL = "https://bsc-dataseed1.binance.org/"
const web3 = new Web3(rpcURL)

let contractAddress = '0x9EC55d57208cb28a7714A2eA3468bD9d5bB15125'
for (index = 0; index < 10; index++){
 console.log(`[${index}]` + 
   web3.eth.getStorageAt(contractAddress, index,16368474).then(res=>{ 
    console.log(res)
   }) 
   )
}

这陷入错误错误:返回错误:找不到标头。我尝试更改块,但陷入相同的错误。仅当我不通过16368474时,该错误才能解决,但这使用了最新的 block,这不是我想要的。我尝试使用web3.py尝试过。它遇到相同的错误。我在做什么错?是否有其他获取存储的方法?

I want to read the contract storage for '0x9EC55d57208cb28a7714A2eA3468bD9d5bB15125' at block 16368474 on BSC .
I tried -

const Web3 = require('web3')
const rpcURL = "https://bsc-dataseed1.binance.org/"
const web3 = new Web3(rpcURL)

let contractAddress = '0x9EC55d57208cb28a7714A2eA3468bD9d5bB15125'
for (index = 0; index < 10; index++){
 console.log(`[${index}]` + 
   web3.eth.getStorageAt(contractAddress, index,16368474).then(res=>{ 
    console.log(res)
   }) 
   )
}

This runs into an error Error: Returned error: header not found .I tried changing blocks but run into the same error . The error only resolves if I don't pass 16368474 but that uses the latest block and that's not what I want . I tried the same with web3.py . It runs into the same error. What am I doing wrong ? Is there an alternate way of getting storage ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从此见与不见 2025-02-11 22:41:23

您的代码是有效的 - 问题是节点提供商不支持查询历史状态。

解决方案:使用支持存档节点的其他提供商,例如 Moralis

const Web3 = require("web3");
const web3 = new Web3("https://speedy-nodes-nyc.moralis.io/<your_api_key>/bsc/mainnet/archive");
const contractAddress = '0x9EC55d57208cb28a7714A2eA3468bD9d5bB15125';
web3.eth.getStorageAt(contractAddress, 0, 16368474).then(res => {
    console.log(res);
});

Your code is valid - the issue is that the node provider doesn't support querying historic states.

Solution: Use a different provider that supports archive node, e.g. Moralis.

const Web3 = require("web3");
const web3 = new Web3("https://speedy-nodes-nyc.moralis.io/<your_api_key>/bsc/mainnet/archive");
const contractAddress = '0x9EC55d57208cb28a7714A2eA3468bD9d5bB15125';
web3.eth.getStorageAt(contractAddress, 0, 16368474).then(res => {
    console.log(res);
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文