Solidity 12 – Reading The Storage

Published by Mario Oettler on

In this lesson, we learn how to read the contract storage from outside a contract. Solidity stores variables like uint, arrays, mappings, structs, etc. in the storage. And as you know, everything on a blockchain is public to everyone.

If a contract designer wants users to easily read the content of a variable, he declares them public. The compiler then creates a get-function in the background that can be seen in the ABI. But if the variable is not declared public, this get function is missing. But still, it is possible to read the content of this variable from outside the contract.

This requires a bit of knowledge of the variable layout of the smart contract.