0

Assuming we're calling the following: function get() external payable; by using another contract: contract.get({value: 1 ether})

Q1 - we are not able to check the result of that transaction right? Especially because the payable function does not return a value

Q2 - since we're not able to check the result, what are the chances that the transaction fails?

Asking this because of the following. Lets say we have a contract which updates the balances before calling the contract's payable get() function.

balance = balance - amount;
contract.get({value: amount});

Since we're not checking the transaction result, if it fails, the amount will not be send but balance will be reduced.

Is this correct?

1 Answer 1

0

You are referring to "high level external function call" with explicit contract interface in oppose to "low level function call". In this case, you can totally get the return value and know if the external call fails.

Q1. Depends on what you defined as result. If the result is success or revert then you always know. External call like that will revert if the function get() reverted. If you wants some extra meaningful results then you have to modify the function to return something, e.g. an integer function get() external payable returns(unit);

Q2. Because it's not a low level call, if that call fails by revert, it will be chained to the whole transaction and the whole tx will revert.

If it revert, balance will not be updated, the state will be rolled back to before tx occurs. You can read more about exception rethrowing from solidity official document

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.