Reusable Logic
You might be wondering: How can I create a new project without deploying new smart contracts?
The answer lies in Compose's smart contract architecture, which is based on diamond contracts.
Understanding Reusability
A diamond contract is a simple, small proxy contract that delegates to the code of other on-chain contracts called facets. Each diamond uses the code of other contracts (facets) to execute logic and maintain its storage data.
When you use Compose, you do deploy a new contract, this small contract is called a diamond.
What You're NOT Deploying
When you create a new diamond, you avoid redeploying:
- Existing standard functionality such as
ERC20FacetERC20PermitFacetERC721FacetOwnerFacetAccessControlFacet- etc.
Instead, you deploy:
- A lightweight diamond contract
- Your unique initialization data (
name,symbol,supply) - Configuration linking to existing facet addresses
Example
Suppose you want to create a new ERC-20 token that supports gasless approvals (permit) and cross-chain bridging.
With Compose, you:
- Select existing facets:
ERC20Facet,ERC20PermitFacet, andERC20BridgeableFacetare already deployed on-chain - Provide initialization data: your token's name, symbol, and total supply
- Deploy your diamond: a small proxy contract that references the facet addresses and logic
The Power of Reusability
One facet, thousands of projects:
If 1,000 projects use the same ERC20Facet:
- That's 999 deployments saved
- Millions in gas costs avoided
- 1,000 projects benefit from the same audited, battle-tested code
Many diamond contracts can be deployed that reuse the same on-chain facets.
Each diamond manages its own storage data by using the code from facets.
Benefits of Reusable Facets
- Lower Deployment Costs: Deploy only a small proxy instead of thousands of lines of logic
- Shared Security Audits: When a facet is audited, all diamonds using it benefit
- Consistent Behavior: Same code means same behavior across all implementations