Skip to main content

What Specific State Changes (Effects) Should Be Prioritized before an External Call?

The most critical state change to prioritize is updating the balance or entitlement of the caller. For example, in a withdrawal function, the user's balance must be set to zero or reduced before the Ether is transferred.

Other important state changes include updating counters, changing ownership status, or marking a condition as met. Essentially, any variable that the external call's success or failure depends on, or any variable that could be exploited if left unchanged, must be updated before the interaction occurs.

Provide a Simple Code Example of a Function Following the CEI Pattern
What Is the Difference between ‘Call’ and ‘Delegatecall’?
What Is the Preventative Measure Called Checks-Effects-Interactions?
How Is the Call Function in Solidity Related to Reentrancy?