# Keep state changes when other function reverts **Published by:** [N00b21337](https://paragraph.com/@n00b21337/) **Published on:** 2023-01-12 **URL:** https://paragraph.com/@n00b21337/keep-state-changes-when-other-function-reverts ## Content This snippet of code has a nice way of showing how you can keep state changes with .call and calling a function with signatures. If you call "regular" function that calls other function in classic way, your state changes will not be reflected as trx will fail and testValue will be 0 as default. But if you call signatureFail which calls "transferFail" function with .call notation you will get info that this call failed as it will still have require or revert fire and "transferFail" function will be reverted but "signatureFail" function is not being reverted and testValue will be applied to state. You will get succes = false from that and you can deciced what you want to do, but this way you can choose if you want to continue with your code as if logic of code permits "failing" of some function this can be used as more advanced way to handle execution.contract CallAnything { address public s_someAddress; uint256 public s_amount; uint256 public testValue; function transfer(address someAddress, uint256 amount) public { // Some code s_someAddress = someAddress; s_amount = amount; } function transferFail(address someAddress, uint256 amount) public { // Some code below that shouldnt be applied because of revert s_someAddress = someAddress; s_amount = amount; require(amount<10, 'Something bad happened'); //revert('Something bad happened'); } // Using encodeWithSignature function signatureSucces(address someAddress, uint256 amount) public returns (bytes4, bool) { (bool success, bytes memory returnData) = address(this).call( abi.encodeWithSignature("transfer(address,uint256)", someAddress, amount) ); return (bytes4(returnData), success); } // Using encodeWithSignature function signatureFail(address someAddress, uint256 amount) public returns (bytes4, bool) { testValue = 20; (bool success, bytes memory returnData) = address(this).call( abi.encodeWithSignature("transferFail(address,uint256)", someAddress, amount) ); return (bytes4(returnData), success); } function regular(address someAddress, uint256 amount) public { testValue = 40; transferFail(someAddress, amount); } } ## Publication Information - [N00b21337](https://paragraph.com/@n00b21337/): Publication homepage - [All Posts](https://paragraph.com/@n00b21337/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@n00b21337): Subscribe to updates - [Twitter](https://twitter.com/0xCardinalError): Follow on Twitter