Solidity: Diamond standard concept explanation, long-story-short

Balut Catalin
2 min readNov 1, 2022

--

The Diamond Standard is quite confusing at first approach for not-very-experienced developers and as I observed on my own you have to read a lot of documentation before working with it, but we want fast solutions right? So here is my long-story short about understanding the Diamond standard.

“Why use it?” — The best alternative of standards.

“When to use it?” — When you build modular smart contract systems that can be upgraded/extended after deployment.

Now the long-story-short part. So the standard has 3 main smart contracts:

  • Diamond — the proxy contract which will delegate your calls.
  • diamondCut — the contract that will allow you to add/replace/delete function selectors in Diamond. So basically Diamond is storing all the function selectors you want. When the user will use the diamond proxy he will be allowed to use only the functions that have selectors stored in the contract. Don’t worry about immutability, the Diamond allows you to remove even the diamondCut selectors for add/replace/delete This will make your contract ecosystem immutable when it's done. How cool, right?
  • diamondLoupe — a contract that has only views and allows you to view data like all contracts from diamond, all functions selectors from diamond. Very useful for management.

The contracts that are added in Diamond are named “facets”.

So let us visualize the standard in our mind. We have a Diamond. In order to modify the diamond shape we cut(edit) it to create facets. We do these cuts with diamondCut. What mean to create facets? It means to add/replace/remove smart contract function selectors to Diamond. Each smart contract is named Facet and is part of a Diamond after we do the diamondCut. Then, when the diamond is done we look at it with the diamondLoupe. Smart approach, right?

Long story short short: “We have a proxy named diamond, we modify it with diamondCut, we look at its facets with diamondLoupe”

Some diamond examples from the documentation:

If you want to do a fast implementation of Diamond standard on your smart contacts check the next article: *coming soon

Also, you can follow me on Twitter if you want more technical references.

--

--

Balut Catalin

smart contracts developer with a great passion for entire web3 universe