Diamonds & Facets: Increasing Interoperability on Ethereum - A Simple Explanation

Diamonds & Facets: Increasing Interoperability on Ethereum - A Simple Explanation
phillistine
0
0

Introduction

Diamonds 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&v=enabled&s=eb5e1568493518b3622f91a6b57a472b1342f07d

How Smart Contracts Communicate

Contracts 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 Interoperability

This 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&v=enabled&s=35c68d8115f5ee68ebdbaa9d406dd779ff5e5caf

How Diamonds Work

Diamonds 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&v=enabled&s=a66aa57ed56707d58eacf76edd09a49d5dea52ae

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 Do

Facets 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&v=enabled&s=1b8926adf6af02b5d3a8494878c879cde8d7d3f3

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