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.
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.
- Deploy
facets/AdditionFacet.sol
. - Deploy
Diamond.sol
. - Get selectors from
facets/AdditionFacet.sol
usinggetAddHash
andgetReturnTotalHash
or simply copy"add(uint256,uint256)"
and"returnTotal()"
. - Set the selectors in the
Diamond.sol
using theaddFunctionBySelector
oraddFunctionByString
. -
Set the
"add(uint256,uint256)"
and"returnTotal()"
. - Call the
add
function in theDiamond.sol
. - Check the
testTotal
variable.