Proxies and upgradeability
Contracts on Ethereum cannot be edited after deployment. A proxy solves this by splitting a contract in two: a small proxy that holds all the storage and the address users call, and a separate implementation contract that holds the logic. To upgrade, you point the proxy at a new implementation and the stored data stays where it is.
The key tool is delegatecall. It runs another contract's code but uses the caller's storage and msg.sender. That is why the proxy can borrow the implementation's functions while keeping its own balances and variables.
Upgradeability adds risk. The storage layout of a new implementation must match the old one, or variables will point at the wrong slots. Whoever controls the upgrade can change the rules, so many projects put it behind a multisig wallet or a timelock.
In real projects, use OpenZeppelin's audited proxy contracts instead of writing your own. The example below is a minimal teaching version that shows the idea.
contract Proxy { address public implementation; address public admin = msg.sender; function upgrade(address next) external { require(msg.sender == admin, "Not admin"); implementation = next; } fallback() external payable { (bool ok, bytes memory data) = implementation.delegatecall(msg.data); require(ok, "Call failed"); assembly { return(add(data, 32), mload(data)) } } }
Try it yourself
Add a function that lets the admin hand control to a new admin address, protect it with a require, then compile.
Press Compile to check your code in the browser. Short fragments are wrapped in a contract automatically.