You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn how facets and libraries work together through shared storage to build composable systems.
3
+
title: "Understanding Facets and Modules"
4
+
description: Learn how facets and modules work together through shared storage to build composable systems.
5
5
---
6
6
7
7
Compose uses two complementary patterns for smart contract development:
@@ -17,35 +17,35 @@ Compose uses two complementary patterns for smart contract development:
17
17
18
18
**Example**: `ERC20Facet.sol` contains the complete ERC-20 token implementation.
19
19
20
-
### Libraries (Helper Functions)
20
+
### Modules (Helper Functions)
21
21
22
-
**Libraries** (prefixed with `Lib`) help developers integrate their custom facets with Compose's facets. They:
22
+
**Solidity modules help developers integrate their custom facets with Compose's facets. They:
23
23
24
24
-**Provide helper functions**: Reusable internal functions for custom facets
25
25
-**Access shared storage**: Work with the same storage layout as their corresponding facet
26
26
-**Enable composition**: Allow custom facets to interact with Compose functionality
27
27
-**Initializes Deployment**: Used to set variables when deploying diamonds
28
28
29
-
**Example**: `LibERC20.sol` provides helper functions to interact with ERC-20 storage from custom facets.
29
+
**Example**: `ERC20.sol` provides helper functions to interact with ERC-20 storage from custom facets.
30
30
31
31
### The Key Insight: Shared Storage
32
32
33
-
**Both facets and libraries access the SAME storage in your diamond.** When `ERC721Facet` and `LibERC721` both define identical storage at `keccak256("compose.erc721")`, they're reading and writing the same data. This is how your custom facets can extend Compose functionality without inheritance.
33
+
**Both facets and modules access the SAME storage in your diamond.** When `ERC721Facet` and `ERC721` both define identical storage at `keccak256("compose.erc721")`, they're reading and writing the same data. This is how your custom facets can extend Compose functionality without inheritance.
34
34
35
35
### When to Use Each
36
36
37
-
**Use a Facet when you want:**
37
+
**Use a facet when you want:**
38
38
39
39
- The complete, standard implementation (e.g., full ERC-20 functionality)
40
40
- To reuse it (on-chain) across multiple diamonds
41
41
- A verified, audited implementation
42
42
43
-
**Use a Library when you're:**
43
+
**Use a module when you're:**
44
44
45
45
- Building a custom facet that needs to interact with Compose features
46
46
- Extending standard functionality with custom logic
47
47
- Initializing storage variables during diamond deployment
48
48
49
-
## Available Facets & Libraries
49
+
## Available Facets & Modules
50
50
51
-
Look in the [src directory](https://github.com/Perfect-Abstractions/Compose/tree/main/src) to see the currently provided functionality, facets and libraries.
51
+
Look in the [src directory](https://github.com/Perfect-Abstractions/Compose/tree/main/src) to see the currently provided functionality, facets and modules.
0 commit comments