0

I have a code like

modifier inTime {
    require(now <= starttime + duration);//easy peasy
    _;
}

applied to a fallback function like this

function() payable inTime{
    depositDone(msg.sender, msg.value); 
}

The logic is "accept money only within duration, reject thereafter". I would expect a payment sent too late is rejected and money safe in the pocket of sender, but I also expect the gas is consumed. Instead, I see the transaction is refused with no gas used at all. Hence my question, when modifiers are evaluated? Are they evaluated by miners or by client wallets?

4

Modifiers on a function are evaluated every time the function is executed. So, that would be whenever a transaction triggers it. If you generate a transaction that's going to throw an exception because that require statement isn't met, both Miners and Wallets will let you push that transaction to the network, and it will get mined into a block. But then the result of that transaction is just you wasting your gas price, as it will throw an exception and roll back all changes (returning whatever ether you were depositing to you).

Hence most Wallet software, before you send a transaction to the network, will emulate the execution of the transaction for you, and will give you some sort of an alert that this transaction will likely fail, so you don't waste your gas money.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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