|
IntroductionDiamonds are a novel approach to how smart contracts can interact with one another. They enable splitting functions across multiple contracts, but keeping all of those functions accessible from the same, single place. Here's a summary with everything you should know. https://preview.redd.it/hf4dhrvq5nwa1.png?width=500&format=png&auto=webp&s=59017da53babe4cc494235be6a17374b68f66407 How Smart Contracts CommunicateContracts on Ethereum today can communicate with each other using a function named “delegateCall.” This is a function in some contracts that calls on a function in a different contract, and executes it. How Diamonds Increase InteroperabilityThis same delegateCall method can be used to instead spread functionality over multiple smart contracts, enabling people to reuse functions in different contracts like libraries. The system for how these contracts are structured is what Diamonds introduces through EIP-2535. EIP-2535 is a framework with two types of contracts: Diamonds and Facets. The metaphor is helpful here; diamonds are the main object, and facets are their various faces. Diamonds are the directories of smart contracts, each with potentially many facets; Each smart contract referenced in a diamond is a facet. https://preview.redd.it/0zihcbrv5nwa1.png?width=500&format=png&auto=webp&s=59c8300580fbd8874e1dc67e6493dab4eee73589 How Diamonds WorkDiamonds are contracts that only contain a fallback function. Fallback functions are most commonly used as a failsafe; when a contract receives a transaction with a request that does not match what it can do, it calls the fallback function. Since Diamonds only contain a fallback function and nothing else, every transaction it receives will be one that does not match what it can do. The Diamond can do nothing, it can only fallback. https://preview.redd.it/wy6uvfzy5nwa1.png?width=613&format=png&auto=webp&s=3198be3df96af1d249ac5bd612a4c18ae6fc1871 Inside a Diamond’s fallback function is the directory of Facets it can call upon. The data inside the transaction a Diamond receives determines which of these facets should be called upon. The facet is then executed, and any relevant data is stored with the Diamond contract. What Facets DoFacets are smart contracts that exist to be called by Diamonds. They provide specific functionality that can be useful to a variety of apps, and can be used by any or all of them. They contain code only, all the data they compute is stored in the Diamonds that call them. https://preview.redd.it/b5b2ev316nwa1.png?width=1000&format=png&auto=webp&s=0ff28f5fcd8db2405969543a3836d2051a80d6a0 This is a summary of a full write-up from my free newsletter! Visit using the link below to learn more about blockchain, and consider signing up to be notified when a new piece is up! Stay kind. Stay curious. https://ramiwrites.substack.com/p/diamonds-and-facets-increasing-interoperability?sd=pf submitted by /u/phillistine |
