Can I force making changes to the value of variables not paying attention to require statement? For example, I have the next code:

contract_runs = contract_runs + 1;
success = exchange();

I want changes initiated by the exchange function to be applied only if success is true but increase contract_runs regardless of the value of this variable.


You could use try/catch if exchange is in another contract.

try anotherContract.exchange() {
  // succeeded
catch (bytes memory err) {
  // failed

If it is in the same contract you could use this.exchange() just be aware that it will change msg.sender and requires exchange to be public or external.

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.