Skip to main content
added 360 characters in body; edited title
Source Link
aste123
  • 243
  • 2
  • 9

How to prevent complete loss of state if a call fails using lower level codeaddress.call()?

CODE:

interface MyInterface {
    function functionName(uint256 x, uint256 y, uint256 z) external returns (uint256[] memory k);
}

Then I've the following inside my contract which uses an outside contract addr:

MyInterface(addr).functionName(x,y,z);
MyInterface(addr).functionName(x,y,z);
MyInterface(addr).functionName(x,y,z);

If any of the 3 function calls fails, I want to stop execution there but making sure any state changes caused by the previous function calls have been saved.

Many times I've seen such transactions on etherscan that execute partially. From what I know, solidity doesn't save any changes if there is an error. So, how is this possible?

In this answer: Does an entire transaction revert when throw occurs?, it has been mentioned that it is possible using lower level code. How do I apply that in my case

Below is a solution I'm considering:

addr.call(abi.encodeWithSignature("functionName(uint256, uint256, uint256)",x,y,z));
addr.call(abi.encodeWithSignature("functionName(uint256, uint256, uint256)",x,y,z));
addr.call(abi.encodeWithSignature("functionName(uint256, uint256, uint256)",x,y,z));

If one of these calls fails, will the previous state changes caused by the prevoius calls still persist?

How to prevent complete loss of state if a call fails using lower level code?

CODE:

interface MyInterface {
    function functionName(uint256 x, uint256 y, uint256 z) external returns (uint256[] memory k);
}

Then I've the following inside my contract which uses an outside contract addr:

MyInterface(addr).functionName(x,y,z);
MyInterface(addr).functionName(x,y,z);
MyInterface(addr).functionName(x,y,z);

If any of the 3 function calls fails, I want to stop execution there but making sure any state changes caused by the previous function calls have been saved.

Many times I've seen such transactions on etherscan that execute partially. From what I know, solidity doesn't save any changes if there is an error. So, how is this possible?

In this answer: Does an entire transaction revert when throw occurs?, it has been mentioned that it is possible using lower level code. How do I apply that in my case?

How to prevent complete loss of state if a call fails using address.call()?

CODE:

interface MyInterface {
    function functionName(uint256 x, uint256 y, uint256 z) external returns (uint256[] memory k);
}

Then I've the following inside my contract which uses an outside contract addr:

MyInterface(addr).functionName(x,y,z);
MyInterface(addr).functionName(x,y,z);
MyInterface(addr).functionName(x,y,z);

If any of the 3 function calls fails, I want to stop execution there but making sure any state changes caused by the previous function calls have been saved.

Many times I've seen such transactions on etherscan that execute partially. From what I know, solidity doesn't save any changes if there is an error.

In this answer: Does an entire transaction revert when throw occurs?, it has been mentioned that it is possible using lower level code.

Below is a solution I'm considering:

addr.call(abi.encodeWithSignature("functionName(uint256, uint256, uint256)",x,y,z));
addr.call(abi.encodeWithSignature("functionName(uint256, uint256, uint256)",x,y,z));
addr.call(abi.encodeWithSignature("functionName(uint256, uint256, uint256)",x,y,z));

If one of these calls fails, will the previous state changes caused by the prevoius calls still persist?

edited title
Link
aste123
  • 243
  • 2
  • 9

Is it somehow possible How to prevent complete loss of state change if a function call fails using lower level code?

Source Link
aste123
  • 243
  • 2
  • 9

Is it somehow possible to prevent complete loss of state change if a function call fails?

CODE:

interface MyInterface {
    function functionName(uint256 x, uint256 y, uint256 z) external returns (uint256[] memory k);
}

Then I've the following inside my contract which uses an outside contract addr:

MyInterface(addr).functionName(x,y,z);
MyInterface(addr).functionName(x,y,z);
MyInterface(addr).functionName(x,y,z);

If any of the 3 function calls fails, I want to stop execution there but making sure any state changes caused by the previous function calls have been saved.

Many times I've seen such transactions on etherscan that execute partially. From what I know, solidity doesn't save any changes if there is an error. So, how is this possible?

In this answer: Does an entire transaction revert when throw occurs?, it has been mentioned that it is possible using lower level code. How do I apply that in my case?