$121.50 -1.46%
ETH · 70w

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
Recent news
ETH -1.46% · · 1h


IFX EXPO Asia kicks off at the Hong Kong Convention Centre next week and we’re proud to announce that OAX will be a part of the event. Our General Manager, Amanda Liu, has been invited by the…
ETH -1.46% · · 6h

Everything You Need To Know About AraCon

The countdown is on! With just 3 days left before registration closes and less than two weeks until the event kicks off, AraCon is officially right around the corner
ETH -1.46% · · 13h

Earn real rewards with Lympo referral programs

Imagine getting paid for walking or running, that is, essentially, just for staying fit and healthy. Sounds crazy, right? Lympo is a free app for everyone wishing to live a healthier and wealthier…