Sharing Common Data Using Libraries

This article discusses Solidity smart contracts sharing common data using libraries.

Jules Goddard
Coinmonks
Published in
8 min readSep 12, 2020

--

Photo by Kitty West

Introduction

In our article “Smart Contracts Sharing Common Data”, we described why and how Solidity Smart Contracts share common data.

However, the technique used to share common data amongst Solidity smart contracts is also applicable to Solidity libraries. This article describes how to implement that and compares the gas consumption of smart contract and library solutions.

This method is supported by Solidity v0.6.4 onwards.

Example Model

For this article, we assume that we are building a solution that matches “Smart Contracts Sharing Common Data”, that is, a Router contains a Producer that produces some objects that are queued for a Consumer to consume. The actual functionality and use of the subordinate libraries does not really concern us in this aticle. We are focussing on the method of sharing common data.

This diagram illustrate the location of the code and data of the contracts or libraries:

--

--

Jules Goddard
Coinmonks

Experienced high-integrity software engineer, crypto code compactor and Datona Labs founder — providing smart contracts to protect your digital information.