Ethereum
$205.01 -0.86%
ETH · 57w

How to read Ethereum contract storage?

How to read Ethereum contract storage

Everybody is talking that data in contracts are public, but not everybody knows how to read it.

All contracts deployed to ethereum VM has dedicated storage where stores state. Here is an example how to read this storage with the web3.js library using eth.getStorageAt() method.

Contract example which we examine:

This contract is deployed in ropsten test net: at 0xf1f5896ace3a78c347eb7eab503450bc93bd0c3b

All parameters in the storage are indexed from the beginning. One index takes 256 bytes ant it fits 64 symbols. In this example, we have 10 parameters and we can iterate them:

let contractAddress = '0xf1f5896ace3a78c347eb7eab503450bc93bd0c3b'for (index = 0; index < 10; index++){ console.log(`[${index}]` + web3.eth.getStorageAt(contractAddress, index))}result:[0] 0x000000000000000000000000000000000000000000000000000000000000000f[1] 0x00000000000000000000000059b92d9a0000000000000000000000000000429f[2] 0x0000000000000000000000000000000074657374310000000000000000000000[3] 0x7465737431323336000000000000000000000000000000000000000000000000[4] 0x6c65747320737472696e6720736f6d657468696e67000000000000000000002a[5] 0x0000000000000000000000000000000000000000000000000000000000000000[6] 0x0000000000000000000000000000000000000000000000000000000000000000[7] 0x0000000000000000000000000000000000000000000000000000000000000002[8] 0x0000000000000000000000000000000000000000000000000000000000000002[9] 0x0000000000000000000000000000000000000000000000000000000000000000

Let`s have a deeper look into each parameter

Index 0 — storeduint1 let contractAddress = '0xf1f5896ace3a78c347eb7eab503450bc93bd0c3b'let index = 0console.log(web3.eth.getStorageAt(contractAddress, index))console.log('DEC:' + web3.toDecimal(web3.eth.getStorageAt(contractAddress, index)))result:0x000000000000000000000000000000000000000000000000000000000000000fDEC:15 constuint

Constants are not stored in a storage. Available only in...

Continue on medium.com
Recent news
ETH -0.86% · blog.aion.network · 9h

A Request for Decentralized Infrastructure

This article is a snapshot of problems we’re looking to co-create, invest and partner on. If you’re already working on one of these problems, or are looking to — we’d love to chat. The bull-run of…
ETH -0.86% · medium.com · 15h

The Token Sale Launch Instruction Manual

There are many tools out there for creating a cryptocurrency, including our own quick-start and management tool: Togen. After creating your cryptocurrency for a game, community cash, tradable loyalty…