ethereum - 无法将使用 Solidity IDE 计算出的“使用的气体”值与 etherscan 资源管理器“交易使用的气体”相匹配
问题描述
当在 remix solidity IDE 中单击方法时,我正在尝试查找事务使用的气体。我的代码如下。我在 gasUsed 变量中获得的值与该交易在 etherscan 浏览器上显示的值不同。如果有人帮助我更正我的代码,那将会很有帮助。
pragma solidity ^0.4.22;
contract id{
uint public id;
uint public senderValue;
uint256 public gasUsed;
constructor() public {
senderValue= msg.sender;
}
function setId(uint _id) public {
uint256 gasInitial = gasleft();
id= _id;
setGasUsed(gasInitial - gasleft());
}
function setGasUsed(uint256 _gasUsed) private {
gasUsed = _gasUsed;
}
}
解决方案
推荐阅读
- python - 在 Python 中检测按键
- ruby-on-rails - 选择具有相同参数的元素的问题
- django - Django 3.1:访问 ModelChoiceField 模板中的对象
- wordpress - WoCommerce 在最终付款期间不增加运费
- javascript - 使用 Javascript 从输入字段中获取图像以将其解析为 API?
- system-verilog - 如何访问systemverilog中的多维数组?
- html - 如何将 HTML 表格抓取到谷歌表格中
- html - 如何使同一个表格单元格中的两个项目具有不同的文本对齐方式?
- c++ - 隐式模式使用 Unix makefile 编译 C++
- javascript - 如何计算鼠标在 d3 中的 x 和 y 位置?