Skip to main content

Composable Facets

The word "composable" means able to be combined with other parts to form a whole.

In Compose, facets are designed to be composable. They're built to interoperate seamlessly with other facets inside the same diamond.

Composable design makes it possible to mix, match, and extend smart contract functionality across diverse use cases — without modifying or redeploying source code. It turns smart contracts into on-chain reusable building blocks.

What Makes Facets Composable?

Smart Contract Composability isn't automatic. Compose facets are designed with specific patterns that enable seamless interaction:

1. Shared Storage Patterns

Facets use Diamond Storage (ERC-8042) to avoid storage collisions. Each facet manages its own isolated storage namespace while being able to read shared state when needed.

2. Standard Interfaces

Facets expose predictable, standard-compliant functions (ERC-20, ERC-721, etc.).

3. Minimal Dependencies

Each facet is self-contained but cooperative. They don't assume what other facets are present, but can enhance functionality when compatible facets are detected.

4. Modular Functionality

Complex features are broken into focused facets. Want pausability? Add PausableFacet. Need access control? Add AccessControlFacet.

Key Insight

On-chain facets are the building blocks of Compose. Like LEGO bricks, they're designed to snap together in different configurations to build exactly what you need.

Composability Benefits

  1. Start Simple, then Scale: Begin with core functionality, add features
  2. Increase Confidence: Use tested, audited facets from the Compose library to build your project
  3. Architectural Flexibility: Same facets, infinite configurations based on your project needs

Composition vs. Inheritance

Traditional smart contracts use inheritance to combine functionality:

  • Requires recompilation when features change
  • Creates large, monolithic contracts
  • Creates code duplication of the same base functionality across multiple projects

Compose uses composition via facets:

  • No recompilation needed to add/remove features
  • Small, focused contracts that work together
  • Same facets work across unlimited projects