I have something like:

   contract example{
            uint endBlock;
            constructor(uint _elitism) public {
                endBlock= block.number + 40; // 10 min of time
            modifier onlyBeforeEnd() {
                require(block.number  > endBlock, "Auction already ended.");

            function getBalance() onlyBeforeEnd public view returns(uint){
                return msg.sender.balance;

if I try to execute getBalance() fuction, everytime it get: "Auction already ended." But, why? The auction is supposed to last 10 minutes.

could anybody help me, please?

  • May anyone help me?
    – Joncarre
    May 3, 2021 at 22:02

1 Answer 1


everytime it get: "Auction already ended." But, why?

The require() statement in the modifier is incorrect.

require(block.number  > endBlock, "Auction already ended.");
        ^                      ^  ^                      ^
        +---------- A ---------+  +---------- B ---------+

The require() statement requires that A is true for code execution to continue. If A is not true, then error B is returned.

A is not true until after the end of the auction. If you are running getBalance() before the end of the auction, A is false, and error B is returned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.