【发布时间】:2019-11-05 17:09:32
【问题描述】:
这是我的第一个 Solidity 合约,我不知道为什么我的提款功能会消耗无限的气体。当我编译合同时,它会发出警告。
函数 Faucet.withdraw(uint256) 的 Gas 需求高:无限。 如果一个函数的gas需求高于block gas limit,它就不能被执行。请避免在修改大面积存储的函数或操作中出现循环(这包括清除或复制存储中的数组)"
pragma solidity ^0.5.11;
//Our First Contract is a Faucet
contract Faucet
{
//Deposits ethers
function deposit(uint256 amount) payable public {
require(msg.value == amount);
// nothing to do!
}
//Give out ether to anyone who asks
function withdraw(uint256 withdraw_amount) public
{
if(withdraw_amount <= address(this).balance)
{
//Send the amount to address which requested it
msg.sender.transfer(withdraw_amount);
}
}
}
注意:我已经成功部署了合约,但是交易失败了,因为它们的 gas 用完了。是因为这个警告吗?
【问题讨论】:
标签: ethereum solidity remix metamask