Skip to main content

Diamond Smart Contracts

A diamond contract is a smart contract that is made up of multiple parts instead of one large block of code. The diamond exists at one address and holds all of the contract's storage, but it uses separate smart contracts called facets to provide its functionality.

Users interact only with the diamond, but the diamond's features come from its facets. Each facet provides a small, focused set of functions, and the diamond uses those functions to perform its actions.

Because facets can be added, replaced, or removed, a diamond can grow and evolve over time without changing its address and without redeploying the entire system.

In simple terms:

A diamond contract is one smart contract made from multiple small building blocks (facets), allowing it to be flexible, organized, and able to grow over time.

A diamond has:

  • One address
  • It's own data storage
  • Multiple facets providing functionality

Below is a diagram showing a diamond with multiple facets.

Diamond ContractStorage datacodecodeFacet 1codeFacet 2codeFacet N

A Diamond lets you:

  • Put unlimited functionality under one address
  • Organize logic into small, reusable facets
  • Create and maintain storage data using facets.
  • Add, replace, or remove functionality after deployment
  • Inspect functionality that exists in a diamond

ERC-2535 Diamonds is the standard that defines how diamond contracts work.

A major part of Compose is providing an easy way to deploy diamonds using Compose facets and custom facets.

Compose with a Standard Library of Facets

Compose has a standard library of facets designed to be:

  • Small
  • Secure
  • Focused
  • Reusable
  • Easy to read
  • Safe to combine

Compose users assemble a contract system by selecting the facets they want:

[ERC20Facet] + [PermitFacet] + [BurnableFacet] → Custom ERC-20

[ERC721Facet] + [MetadataFacet] + [RoyaltyFacet] → Custom NFT

[GovernanceFacet] + [VotingFacet] → Governance System