Custom Functionality: Compose Your Own Facets
Many projects need custom functionality beyond the standard facets.
Compose is designed for this — you can build and integrate your own facets that work seamlessly alongside existing Compose facets.
Compose provides Solidity libraries that expose the same storage layouts and internal logic used by its onchain facets. This lets your custom facets share data and interact directly with Compose's reusable facets.
Example: Adding Game Logic to ERC-721
Suppose you're building an onchain game and want to include the ERC721Facet in your diamond.
You can add your own GameNFTFacet that extends functionality while still sharing the same ERC-721 storage through LibERC721:
// Your custom facet integrates with Compose using libraries
import {LibERC721} from "compose/LibERC721.sol";
contract GameNFTFacet {
function mintWithGameLogic(address player, uint256 tokenId) external {
// Your custom game logic
require(playerHasEnoughPoints(player), "Not enough points");
// Use LibERC721 to mint - this modifies the SAME storage
// that ERC721Facet uses for balanceOf(), ownerOf(), etc.
LibERC721.mint(player, tokenId);
// Now the player owns this NFT and can use standard
// ERC721Facet.transferFrom() to transfer it!
updatePlayerStats(player);
}
}
Your custom GameNFTFacet and the standard ERC721Facet both operate on the same storage within your diamond. This shared-storage architecture is what makes composition possible.
Compose is still in early development and currently available only to contributors. It is not production-ready — use it in test or development environments only.