2

I've randomly stumbled upon a code where the function uses this; in the end of function

function _preValidatePurchase(address beneficiary, uint256 weiAmount) internal view {
        require(beneficiary != address(0), "Crowdsale: beneficiary is the zero address");
        require(weiAmount != 0, "Crowdsale: weiAmount is 0");
        require(weiAmount >= minPurchase, 'have to send at least: minPurchase');
        require(_contributions[beneficiary].add(weiAmount)<= maxPurchase, 'can\'t buy more than: maxPurchase');
        require((_weiRaised+weiAmount) <= hardCap, 'Hard Cap reached');
        this; //What is the purpose of using this; here
    } 

In last where this; is used what is the purpose of using this, as far as i know this keyword refers to current instance but what purpose does it serve there?

1

1 Answer 1

4

It is a way of telling the compiler to silent unwanted warnings. If there wasn't this keyword, the compiler would have said state mutability can be restricted to pure, which is not necessarily true for the contracts that might override this function and read the state variables.

See for more:

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.