Smart Contracts
Delegatecall
A low-level Solidity function that executes code from another contract while preserving the calling contract's context.
Last Updated
2026-03-19
Related Concepts
What is Delegatecall?
A delegate call is a low-level function in Solidity that allows a contract to execute code from another contract while keeping the context (storage and balance) of the calling contract.
How does Delegatecall work?
- Contract A calls Contract B using delegatecall.
- The code from Contract B is executed.
- Any changes to storage happen in Contract A's memory space.
- The value of msg.sender and msg.value remain what they were for Contract A.
- It is essentially like Contract A "borrowing" the logic of Contract B to use on its own data.
Why does Delegatecall matter?
It is the foundation of "Proxy Contracts" and "Upgradeable Smart Contracts." It allows developers to change the logic of a protocol (by pointing to a new implementation contract) without moving the user's data or funds.
Key features of Delegatecall
- Preserves the calling contract's state
- Executes external logic in local context
- Foundation for upgradeability
- More gas-efficient for certain patterns
- High security risk if implemented incorrectly
Examples of Delegatecall
- A "Proxy" contract delegating to an "Implementation" contract.
- Using a "Library" in Solidity to perform math or string operations.
- The "Diamond Standard" (
ERC-2535) for building modular, multi-contract systems.
