Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

In this article, we'll read data directly from smart contract storage to see where and how a contract stores its values. You can follow the examples yourself to develop a practical understanding of storage layout.

We'll use Remix, an editor that runs in a web browser. https://remix.ethereum.org/

Storage

Overview

First, let's look at the fundamentals of smart contract storage. Contracts have three data locations.

Data location Characteristics Gas consumption
storage Persists data in the contract (on the blockchain). The data can be retrieved externally. High
memory Temporary storage available for the duration of a function's execution. It is accessible from within the function. Moderate
calldata Behaves similarly to memory, but the data cannot be modified. Low

We'll focus on storage and examine how data is laid out.

Slots

Storage data is organized into units called slot.

Diagram of storage slots

The original figures are reused in this translation and may contain Japanese labels.

1slot consists of 32 bytes, and the address space can accommodate up to 22562^{256} slots.

This is only the maximum capacity. In practice, contracts do not store anywhere near this much data.

Values such as string and uint256 occupy 32-byte slots in the layout shown here, with each assigned 1slot.

Diagram of values occupying storage slots

Smaller values may be packed into the same slot, as shown above. The order of variable declarations matters: certain arrangements can make storage less efficient.

Diagram of storage layout and declaration order

The preceding diagram corresponds to the following declarations in the contract.

solidity
string name;
uint8 income;
uint8 age;
string description;
address walletAddress;
bool enginner;
bool creator;

Values in a slot are right-aligned. What happens if we use the following declaration order instead?

solidity
string name;
string description;
address walletAddress;
uint8 income;
uint8 age;
bool enginner;
bool creator;

Diagram of reordered storage variables

As shown, this layout uses four slot units. Using unnecessary storage increases gas costs. Paying attention to how values are laid out in storage can therefore help reduce gas consumption.

Diagram of hexadecimal storage data

The data actually stored in storage is represented in hexadecimal, as shown above.

Storage recap

We've covered the basics of storage. Understanding data layout when writing smart contracts will help you become a more effective contract developer. Now let's inspect the contents of storage directly.

Creating and deploying the contract

Let's introduce the contract we'll use throughout the examples. If you're unfamiliar with Remix, the following article is a useful starting point.

Creating the contract

The code is also available here.

Paste the following code into Remix.

solidity
// SPDX-License-Identifier: MIT

pragma solidity 0.8.26;

contract Storage {
    string public name; // slot 0
    string public description; // slot 1
    uint256 public version; // slot 2
    uint256[2] public timestampArry; // slot 3 ~ 4
    address public admin; // slot 5
    address public owner; // slot 6
    uint128 private cardNumber; // slot 7
    uint128 private cardPassword; // slot 7

    struct Profile {
        string name;
        uint256 age;
        uint256 createdAt;
    }
    Profile public profile; // slot 8~10

    Profile[] profiles; // slot 11

    mapping(uint256 => string) public addressName; // slot 12

    constructor() {
        name = "Storage Contract";
        description = "Checl contract sotrage";
        version = 1;
        timestampArry[0] = block.timestamp;
        timestampArry[1] = block.timestamp;
        profile = Profile("cardene", 100, block.timestamp);
        admin = msg.sender;
        owner = msg.sender;
        profiles.push(Profile("Alice", 30, block.timestamp));
        profiles.push(Profile("Bob", 25, block.timestamp));
        addressName[7] = "cardene";
        addressName[10] = "test";
    }

    function registerCard(uint128 cardNumber_, uint128 cardPassword_) public {
        cardNumber = cardNumber_;
        cardPassword = cardPassword_;
    }

    function getRegisterCard() public view returns (uint128, uint128) {
        return (cardNumber, cardPassword);
    }
}

Explaining the contract

Here's a brief explanation of the contract we just created.

solidity
string public name; // slot 0
string public description; // slot 1
uint256 public version; // slot 2
uint256[2] public timestampArry; // slot 3 ~ 4
address public admin; // slot 5
address public owner; // slot 6
uint128 private cardNumber; // slot 7
uint128 private cardPassword; // slot 7

struct Profile {
    string name;
    uint256 age;
    uint256 createdAt;
}
Profile public profile; // slot 8~10

Profile[] profiles; // slot 11

mapping(address => string) public addressName; // slot 12

The declarations above define several variables and store data in contract storage. The comments of the form "slot N" indicate which storage slot contains each value.

solidity
constructor() {
    name = "Storage Contract";
    description = "Checl contract sotrage";
    version = 1;
    timestampArry[0] = block.timestamp;
    timestampArry[1] = block.timestamp;
    profile = Profile("cardene", 100, block.timestamp);
    admin = msg.sender;
    owner = msg.sender;
    profiles.push(Profile("Alice", 30, block.timestamp));
    profiles.push(Profile("Bob", 25, block.timestamp));
    addressName[7] = "cardene";
    addressName[10] = "test";
}

The constructor runs once when the contract is deployed. This constructor initializes several values in storage.

solidity
function registerCard(uint128 cardNumber_, uint128 cardPassword_) public {
    cardNumber = cardNumber_;
    cardPassword = cardPassword_;
}

function getRegisterCard() public view returns (uint128, uint128) {
    return (cardNumber, cardPassword);
}

These are the functions for storing and retrieving data. The contract also initializes its mapping and array data above.

Deploying the contract

Once you've reached this point, compile and deploy the contract.

Contract deployment in Remix

You're ready to proceed once deployment succeeds.

slot 0

Let's start by inspecting the data stored in slot0.

Replace 0xB57ee0797C3fc0205714a577c02F7205bB89dF30 in the following command with the address of your deployed contract.

js
web3.eth.getStorageAt("0xB57ee0797C3fc0205714a577c02F7205bB89dF30", 0)

This command retrieves the data in storage at 0xB57ee0797C3fc0205714a577c02F7205bB89dF30, specifically slot0. Let's run it.

Reading slot 0 in Remix

Paste the preceding command into the Terminal panel in Remix and execute it, as shown above.

You should see hexadecimal data similar to the following.

bash
0x53746f7261676520436f6e747261637400000000000000000000000000000020

If it doesn't work, try again a few times. Also verify that the contract address is correct.

Now run the following command.

js
web3.utils.hexToUtf8("0x53746f7261676520436f6e747261637400000000000000000000000000000020")

This converts the hexadecimal string into a UTF-8 string.

bash
Storage Contract

You should see the output above. We've now read data directly from the contract's storage. Let's use the same approach to inspect the other values.

slot 1–slot 6

Reading slot1 through slot6 works in much the same way, so we'll retrieve these values together.

slot1

bash
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 1)
# 0x436865636c20636f6e747261637420736f74726167650000000000000000002c
web3.utils.hexToUtf8("0x436865636c20636f6e747261637420736f74726167650000000000000000002c")
# Checl contract sotrage

slot2

bash
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 2)
# 0x01
web3.utils.toBN(0x01).toString();
# 1

This time the stored value is numeric, so we convert the hexadecimal value to a number.

slot3 and slot4

bash
# slot3
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 3)
# 0x66517164
web3.utils.toBN(0x66517164).toString();
# 1716613476

# slot4
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 4)
# 0x66517164
web3.utils.toBN(0x66517164).toString();
# 1716613476

slot3 and slot4 correspond to the following declaration and contain elements of a fixed-length array.

solidity
uint256[2] public timestampArry; // slot 3 ~ 4

Because a fixed-length array has a known storage size, its elements are stored in consecutive slot units like this. What happens with an array that does not have a fixed length? We'll examine that later.

slot5

bash
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 5)
# 0x5b38da6a701c568545dcfcb03fcb875f56beddc4

This is a wallet address, so no conversion is required.

slot6

bash
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 6)
# 0x5b38da6a701c568545dcfcb03fcb875f56beddc4

Reading private data

slot7 contains the following data from the contract.

solidity
uint128 private cardNumber; // slot 7
uint128 private cardPassword; // slot 7

First, we need to assign values to these variables.

Registering private data in Remix

As shown above, paste the following values into the input on the left and click the "registerCard" button.

bash
123456789, 987654321

The data has now been registered.

Because these values are of type uint128, they fit within the same storage slot. The important point is that the variables have the private visibility restriction. This means they are accessible only from within the contract at the Solidity language level. Let's see what happens when we read the data directly.

bash
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 7)
# 0x3ade68b1000000000000000000000000075bcd15
web3.utils.toBN(0x75bcd15).toString();
# 123456789
web3.utils.toBN(0x3ade68b1).toString();
# 987654321

We were able to retrieve both values. Even when a contract declares a variable as private, its data remains visible from outside the contract.

The following article explains in more detail why private data can be read externally.

https://chaldene.net/solidity-private-data

Reading struct data

slot 8 through slot 10 contain the following struct data.

solidity
struct Profile {
    string name;
    uint256 age;
    uint256 createdAt;
}
Profile public profile; // slot 8~10

Let's retrieve the data.

bash
# slot 8
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 8)
# 0x63617264656e650000000000000000000000000000000000000000000000000e
web3.utils.hexToUtf8("0x63617264656e650000000000000000000000000000000000000000000000000e")
# cardene

# slot 9
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 9)
# 0x64
web3.utils.toBN(0x64).toString();
# 100

# slot 10
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 10)
# 0x665173de
web3.utils.toBN(0x665173de).toString();
# 1716614110

The results confirm that the struct is also stored in consecutive storage locations.

Reading dynamic array data

slot 11 holds information about the following array of structs.

solidity
Profile[] profiles; // slot 11

constructor() {
    ...
    profiles.push(Profile("Alice", 30, block.timestamp));
    profiles.push(Profile("Bob", 25, block.timestamp));
}

Let's retrieve the data.

bash
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 11)
# 0x02
web3.utils.toBN(0x02).toString();
# 2

The result is 2. That isn't quite what we expected. It is actually the length of the array. Because profiles is a dynamic array, its storage requirements cannot be reserved in advance. The array's elements are therefore stored in other slot locations in storage. As we just saw, slot 11 contains the array length.

Storage layout of a dynamic array

The array elements are stored at a distant slot address, as illustrated above. The data belonging to each element is stored in consecutive slot locations starting at that distant address.

Let's inspect those values.

bash
web3.utils.soliditySha3({ type: "uint", value: 11 }) # slot
# 0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db9

Earlier, I described the storage location as distant. How exactly is that location determined? It is obtained by hashing the slot associated with the array length, as the command above illustrates. Hashing transforms input data into another value, generally treated as unique for practical purposes (although collisions have been found for some hash functions).

https://wa3.i-3-i.info/word110419.html

The slot address is treated as unique, so other data in the same contract is not expected to access that location.

You might wonder whether storage could collide with storage in another contract. That is not an issue because each contract has its own storage space. The first argument of getStorageAt, which we've been using to specify the contract address, illustrates this separation.

First, let's retrieve data from the slot address we calculated.

bash
# index: 0
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", "0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db9")
# 0x416c69636500000000000000000000000000000000000000000000000000000a
web3.utils.hexToUtf8("0x416c69636500000000000000000000000000000000000000000000000000000a")
# Alice

We successfully retrieved the value. However, this is not all the data in the array. How do we access the remaining fields? As described earlier, data is stored in consecutive slot locations at a distant address. To access the next slot, take the current slot number and add +1.

Accessing successive dynamic array slots

The only complication is that the address is hexadecimal, so we must perform the +1 operation in hexadecimal. Taking 0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db9 and applying +1 gives 0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dba. Let's use this value to access storage.

bash
# 0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dba
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", "0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dba")
# 0x1e
web3.utils.toBN(0x1e).toString();
# 30

We retrieved the value successfully. Let's retrieve the final field in the same way.

bash
# 0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbb
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", "0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbb")
# 0x665186b6
web3.utils.toBN(0x665186b6).toString();
# 1716618934

That worked. But we still have the data for Bob to retrieve.

bash
profiles.push(Profile("Bob", 25, block.timestamp));

This is straightforward as well. We can access it by applying +1 to the last slot address we used.

bash
## index: 1
# 0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbc
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", "0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbc")
# 0x426f620000000000000000000000000000000000000000000000000000000006
web3.utils.hexToUtf8("0x426f620000000000000000000000000000000000000000000000000000000006")
# Bob

# 0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbd
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", "0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbd")
# 0x19
web3.utils.toBN(0x19).toString();
# 25

# 0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbe
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", "0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbe")
# 0x665186b6
web3.utils.toBN(0x665186b6).toString();
# 1716618934

We retrieved the data successfully. We've now seen how to access the contents of a dynamic array.

Reading mapping data

This is the final section. We'll examine how to access values stored in a mapping. The contract used the following declaration.

solidity
mapping(uint256 => string) public addressName; // slot 12

constructor() {
    ...
    addressName[7] = "cardene";
    addressName[10] = "test";
}

Unlike the array we examined earlier, the data is not stored in consecutive slot locations. Let's run the commands to find out where it is stored. As with the dynamic array, we'll first retrieve the data in slot 12 itself.

bash
web3.eth.getStorageAt("0xB57ee0797C3fc0205714a577c02F7205bB89dF30", 12)
# 0x0

It's empty. Unlike the array length slot, this slot does not hold any data.

Storage layout of a mapping

To access mapping data, hash the key (the mapping key) together with the slot index (the zero-based slot number). Here, the key is 7 and the slot index is 12.

bash
web3.utils.soliditySha3({type: "uint", value: 7}, { type: "uint", value: 12 }) # key, slot
# 0x63617264656e650000000000000000000000000000000000000000000000000e

We obtained a hexadecimal value as shown above. Let's access the value we obtained.

bash
web3.utils.hexToUtf8("0x63617264656e650000000000000000000000000000000000000000000000000e")
# cardene

We retrieved the value. Now let's retrieve the other entry as well.

bash
web3.utils.soliditySha3({type: "uint", value: 10}, { type: "uint", value: 12 }) # key, slot
# 0x9e6c92d7be355807bd948171438a5e65aaf9e4c36f1405c1b9ca25d27c4ea3a0
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", "0x9e6c92d7be355807bd948171438a5e65aaf9e4c36f1405c1b9ca25d27c4ea3a0")
# 0x7465737400000000000000000000000000000000000000000000000000000008
web3.utils.hexToUtf8("0x7465737400000000000000000000000000000000000000000000000000000008")
# test

We successfully retrieved it. We've now read all the different types of data in the example contract.

The commands used in this article are collected below for reference.

Commands
bash
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 0)
# 0x53746f7261676520436f6e747261637400000000000000000000000000000020
web3.utils.hexToUtf8("0x53746f7261676520436f6e747261637400000000000000000000000000000020")
# Storage Contract 

web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 1)
# 0x436865636c20636f6e747261637420736f74726167650000000000000000002c
web3.utils.hexToUtf8("0x436865636c20636f6e747261637420736f74726167650000000000000000002c")
# Checl contract sotrage

web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 2)
# 0x01
web3.utils.toBN(0x01).toString();
# 1

web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 3)
# 0x66517164
web3.utils.toBN(0x66517164).toString();
# 1716613476

web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 4)
# 0x66517164
web3.utils.toBN(0x66517164).toString();
# 1716613476

web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 5)
# 0x5b38da6a701c568545dcfcb03fcb875f56beddc4

web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 6)
# 0x5b38da6a701c568545dcfcb03fcb875f56beddc4

web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 7)
# 0x3ade68b1000000000000000000000000075bcd15
web3.utils.toBN(0x75bcd15).toString();
# 123456789
web3.utils.toBN(0x3ade68b1).toString();
# 987654321

web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 8)
# 0x63617264656e650000000000000000000000000000000000000000000000000e
web3.utils.hexToUtf8("0x63617264656e650000000000000000000000000000000000000000000000000e")
# cardene

web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 9)
# 0x64
web3.utils.toBN(0x64).toString();
# 100

web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 10)
# 0x665173de
web3.utils.toBN(0x665173de).toString();
# 1716614110

## Array
## index: 0
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 11)
# 0x02
web3.utils.toBN(0x02).toString();
# 2
web3.utils.soliditySha3({ type: "uint", value: 11 }) # slot
# 0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db9
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", "0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db9")
# 0x416c69636500000000000000000000000000000000000000000000000000000a
web3.utils.hexToUtf8("0x416c69636500000000000000000000000000000000000000000000000000000a")
# Alice
# 0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dba
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", "0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dba")
# 0x1e
web3.utils.toBN(0x1e).toString();
# 30
# 0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbb
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", "0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbb")
# 0x665186b6
web3.utils.toBN(0x665186b6).toString();
# 1716618934

## index: 1
# 0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbc
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", "0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbc")
# 0x426f620000000000000000000000000000000000000000000000000000000006
web3.utils.hexToUtf8("0x426f620000000000000000000000000000000000000000000000000000000006")
# Bob
# 0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbd
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", "0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbd")
# 0x19
web3.utils.toBN(0x19).toString();
# 25
# 0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbe
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", "0x0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01dbe")
# 0x665186b6
web3.utils.toBN(0x665186b6).toString();
# 1716618934

## Mapping
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", 12)
# 0x0
web3.utils.soliditySha3({type: "uint", value: 7}, { type: "uint", value: 12 }) # key, slot
# 0x949c9a93ae746871004aabe5aa16f6723dba12da47a01a4a63a7f95d60037905
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", "0xdae089abd7155aa13ce498edb0d7a7156b783d015031f10c9a3d4f5fcb518971")
# 0x63617264656e650000000000000000000000000000000000000000000000000e
web3.utils.hexToUtf8("0x63617264656e650000000000000000000000000000000000000000000000000e")
# cardene

web3.utils.soliditySha3({type: "uint", value: 10}, { type: "uint", value: 12 }) # key, slot
# 0x9e6c92d7be355807bd948171438a5e65aaf9e4c36f1405c1b9ca25d27c4ea3a0
web3.eth.getStorageAt("0x838F9b8228a5C95a7c431bcDAb58E289f5D2A4DC", "0x9e6c92d7be355807bd948171438a5e65aaf9e4c36f1405c1b9ca25d27c4ea3a0")
# 0x7465737400000000000000000000000000000000000000000000000000000008
web3.utils.hexToUtf8("0x7465737400000000000000000000000000000000000000000000000000000008")
# test

Conclusion

In this article, we read data directly from contract storage to see where and how smart contracts store their values. I hope you found the examples useful. Storage layout may not be something you think about every day, but understanding how it works can make contract development more interesting. I'll continue publishing technical articles like this one.

I also publish on the following platforms, so feel free to explore them.

https://chaldene.net/

References

https://medium.com/@flores.eugenio03/exploring-the-storage-layout-in-solidity-and-how-to-access-state-variables-bf2cbc6f8018