Skip to main content

Example Diamond

Initializes a diamond contract with facets and owner

Key Features
  • Registers facet function selectors for diamond routing.
  • Sets the initial diamond owner.
  • Facilitates diamond initialization pattern.
  • Requires explicit facet addresses and owner during deployment.

Overview

This contract initializes a diamond with provided facets and an owner address. It registers function selectors from each facet to enable delegatecall routing through the diamond proxy. Use this during diamond deployment to set up its initial functional capabilities.

Storage

Functions

constructor

Initializes the diamond contract with facets, owner and other data. Adds all provided facets to the diamond's function selector mapping and sets the contract owner. Each facet in the array will have its function selectors registered to enable delegatecall routing.

constructor(address[] memory _facets, address _diamondOwner) ;

Parameters:

PropertyTypeDescription
_facetsaddress[]Array of facet addresses and their corresponding function selectors to add to the diamond.
_diamondOwneraddressAddress that will be set as the owner of the diamond contract.

fallback

fallback() external payable;

receive

receive() external payable;

Best Practices

Best Practice
  • Call the constructor only once during diamond deployment.
  • Ensure the _facets array contains valid, deployed facet contract addresses.
  • The _diamondOwner should be a trusted address responsible for diamond management.

Security Considerations

Security

This contract is an initializer and is typically deployed once. Ensure the _facets array is populated correctly to avoid missing functionality. The _diamondOwner address should be secured, as it controls diamond upgrades and management.

Was this helpful?
Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.