【问题标题】:In Solidity can I get data of other block other than the current one?在 Solidity 中,我可以获取当前区块以外的其他区块的数据吗?
【发布时间】:2022-12-18 11:46:04
【问题描述】:

我希望有像Block(5).hashdata这样的东西。 Solidity中有类似的东西来获取另一个块的哈希数据吗?

【问题讨论】:

    标签: ethereum solidity


    【解决方案1】:

    我不相信,但我能够使用 ChatGPT 解决这个问题!我在这里添加答案

    是的,您可以使用 Solidity 中的其他块获取数据 block.number财产。此属性返回块的编号 该代码当前正在执行,因此您可以使用它来 从以前的块访问数据。

    这是一个如何使用 block.number 属性的示例 从前一个块访问数据:

    previousBlockNumber = block.number - 1;
    
    // Get the data from the previous block bytes32 previousBlockData =
    block.blockhash(previousBlockNumber); ```
    
    Keep in mind that the `blockhash` function is a low-level function
    that can be expensive to use, so you should use it with caution and
    only when absolutely necessary. Also, keep in mind that the
    `blockhash` function only works for blocks that are within the last
    256 blocks, so it may not be possible to access data from blocks that
    are further back in time.
    

    【讨论】:

      猜你喜欢
      • 2018-11-30
      • 1970-01-01
      • 2022-08-22
      • 2022-01-14
      • 1970-01-01
      • 2022-10-21
      • 2013-09-29
      • 2015-01-03
      • 1970-01-01
      相关资源
      最近更新 更多