Skip to content
/ Diamond Public

A practical outlook into the Diamond contract structure.

Notifications You must be signed in to change notification settings

0xfps/Diamond

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 

Repository files navigation

Diamond

EIP-2535

A practical outlook into the Diamond contract structure.


For more information on Diamonds and Facets:

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.

About

A practical outlook into the Diamond contract structure.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published