Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/0xfps/diamond
A practical outlook into the Diamond contract structure.
https://github.com/0xfps/diamond
diamond ethereum facets solidity
Last synced: about 2 months ago
JSON representation
A practical outlook into the Diamond contract structure.
- Host: GitHub
- URL: https://github.com/0xfps/diamond
- Owner: 0xfps
- Created: 2022-08-01T06:57:14.000Z (over 2 years ago)
- Default Branch: dev
- Last Pushed: 2023-01-20T08:39:42.000Z (almost 2 years ago)
- Last Synced: 2024-10-07T18:42:06.037Z (3 months ago)
- Topics: diamond, ethereum, facets, solidity
- Language: Solidity
- Homepage:
- Size: 30.3 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Diamond
### EIP-2535
A practical outlook into the Diamond contract structure.
For more information on Diamonds and Facets:
- https://eips.ethereum.org/EIPS/eip-2535.
- https://soliditydeveloper.com/eip-2535.
- [Diamond Contract Codebase](https://github.com/mudgen/diamond-2-hardhat).###
## WHY DO WE USE A LIBRARY FOR DIAMOND STORAGE?
Personally, I think that using libraries with internal functions gives us that opportunity to interact with the library imported when the facet is imported.As the library functions are internal, they are added to the bytecode of the Diamond contract hence the library's `myStorage()` can share the same storage with the Diamond, giving it the ability to write, read and modify a particular storage slot in the Diamond, hence storages can be easily read and modified.
Because, if we used a contract, we cannot explicitly interact with it, unless we initialize a new contract which makes things difficult.
## STEPS
- Deploy `facets/AdditionFacet.sol`.
- Deploy `Diamond.sol`.
- Get selectors from `facets/AdditionFacet.sol` using `getAddHash` and `getReturnTotalHash` or simply copy `"add(uint256,uint256)"` and `"returnTotal()"`.
- Set the selectors in the `Diamond.sol` using the `addFunctionBySelector` or `addFunctionByString`.
- > Set the `"add(uint256,uint256)"` and `"returnTotal()"`.
- Call the `add` function in the `Diamond.sol`.
- Check the `testTotal` variable.