Modular Contracts
Modular Contracts are contracts for which you can add, remove, or upgrade the exact parts you want.
To get started, install the modular-contracts
package in your existing Solidity project:
A modular contract is made up of [1] a Core and [2] Extension contracts. Learn more about these, below.
Follow this end-to-end guide to learn how to write, deploy and use your own custom modular contract.
A modular contract is made up of two kinds of contracts:
- Core contract: the foundational API that can be customized by installing Extensions.
- Extension contract: implements a set of functionality that is enabled on a Core when it is installed.
As an analogy, think of the robot, below. The torso is the Core to which you attach/detach Extensions.
The torso has a particular shape and exposes sockets at fixed places -- all of which determine how extensions will be attached to it. Similarly, a Core smart contract has a fixed API that determines what Extensions are compatible for installation.
The Extensions themselves e.g. a leg, arm, head, etc. give the robot (i.e. the modular contract as a whole) its various capabilities.
Installing an Extension in a Core customizes the Core’s behaviour in two ways:
- New functions become callable on the Core contract (via its fallback function).
- Core contract’s fixed functions make callback function calls into the Extension.
You can read about the full technical design details of Modular Contracts in its design document.