Skip to content
Back to Curriculum
ADVANCED

External Calls

Contracts can interact with other contracts or EOAs by making external calls. The low-level `.call` is the most flexible way, allowing you to send ETH and data, but it requires careful handling of return values and reentrancy risks.

Syntax Structure

Example.sol
Loading...

Key Components

  • Boilerplate structure required by the Solc compiler.
  • Placement of state variables versus functions.

Practical Implementation

A generic executor that can call any function on any contract.

Practical.sol
Loading...

Core Concepts

Check-Effect-Interaction

The golden rule: specific state changes first, then make the external call.

Gas Stipend

`.transfer()` sends 2300 gas. `.call()` sends all gas (63/64 rule).

Return Data

The raw bytes returned by the target. Needs decoding with `abi.decode`.

Mental Model

The Phone Call

Making an external call is like calling someone on the phone. You dial the number (Address), say something (Calldata), and maybe Venmo them money at the same time (Value). You wait for them to say something back (Return Data). If they hang up on you (`revert`), you decide if you want to hang up too or keep going.

Under the Hood

The `CALL` opcode is complex. It creates a new sub-context. It returns a boolean (1=success, 0=failure) onto the stack. It does NOT automatically bubble up reverts; you must check the boolean.

CALLRETURNDATASIZERETURNDATACOPY

Gas Analysis

Calls are expensive.

  • • Use `staticcall` if you only need to read data (safer).
  • • Batch calls using Multicall to save transaction base fee cost.

Security Risks

Unhandled return values are dangerous.

  • ! Silently Failing Sends: If you use `.call` and don't check `success`, the transfer might fail but your contract thinks it worked.

Common Use Cases

Sending ETH (Withdrawals).
Calling functions without an interface (bytes signature).
Multicall patterns.

Interactive Visualization

See exactly how the EVM handles this code in memory, storage, and the stack.

Interactive Simulation
0 / 0
Loading...
Type Solidity code (v0.8.26) and click Run. Compiler loads on first use (~2MB).

Click Run to execute the simulation

Then use the step controls to navigate