Basic Example
Initializes a diamond proxy for an NFT system by wiring facets, owner data, metadata, and interface support.
- Registers facet function selectors for proxy routing via
fallback. - Initializes ERC-173 owner storage.
- Initializes ERC-721 metadata values (
name,symbol,baseURI). - Registers ERC-165 support for
IERC721andIERC721Metadata. - Accepts transfers through
receive().
Overview
ExampleDiamond is a minimal contract that initializes a diamond proxy for an NFT system by wiring facets, owner data, metadata, and interface support. It does not contain NFT business logic itself. Instead, it sets up routing and shared storage so NFT behavior implemented in facets can be reached through the diamond address.
During construction, it:
- Adds all facet selectors to the diamond selector mapping.
- Sets the initial Owner. (See OwnerDataFacet)
- Sets ERC-721 metadata values.
- Registers ERC-165 interface IDs for ERC-721 compatibility discovery.
After deployment, calls are routed through the contract fallback using selector lookup and delegatecall into facets.
Storage
This contract initializes state in multiple module-defined storage namespaces:
- Diamond routing storage via
DiamondMod(erc8153.diamond) - Owner storage via
OwnerDataMod(erc173.owner) - ERC-721 metadata storage via
ERC721MetadataMod(erc721.metadata) - ERC-165 support map via
ERC165Mod(erc165)
Because modules use fixed storage locations, facets can safely share a single diamond storage context without slot collisions. See Shared Storage for more details.
Example Implementation
This contract only initializes the diamond proxy.
Minting, transfers, approvals, and token ownership logic must come from their respective facets that you provide during deployment.
Best Practices
- Deploy and test facets before passing them into the constructor.
- Verify there are no selector collisions across facets.
- Ensure facets expose the expected selectors format for registration.
- Set
_diamondOwnerto a trusted account or governance contract.