16

I want to know how this works: web3.eth.getStorageAt(addressHexString, position [, defaultBlock] [, callback])

What data we can store at any address and how? And what will this eth API return?

eth
  • 85,679
  • 53
  • 285
  • 406
BlockA
  • 857
  • 2
  • 7
  • 15
  • Related: http://ethereum.stackexchange.com/questions/6397/how-do-i-get-the-storage-indices-keys – eth Aug 01 '16 at 09:37

3 Answers3

15

Each contract consists of a EVM bytecode handling the execution and a storage to save the state of the contract. This is a low level function to get the state of the contract's storage. The storage is essentially a key/value store.
The function returns the value the contracts storage has at a certain position.

Refer to the GitHub wiki pages.

More on storage here.

lungj
  • 6,680
  • 2
  • 17
  • 45
Roland Kofler
  • 11,638
  • 3
  • 44
  • 83
1

As of version 1.0 of web3.js, the web3.utils.hexToAscii function should be used. Correct syntax:

web3.eth.getStorageAt('/* Contract Address */', 0).then(result => {
  console.log(web3.utils.hexToAscii(result));
});
UnknownUser
  • 111
  • 4
0

for instance if you look at this contract source and you type this in geth:

web3.toAscii(web3.eth.getStorageAt("0x3589d05a1ec4Af9f65b0E5554e645707775Ee43C",1))

it returned the following

"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00WEEDMAPS"
euri10
  • 4,640
  • 5
  • 24
  • 55
  • Would you be able to also provide an example for getting the address of a dynamic array? i've tried with web3.sha3("0x01") to calculate the address but can't figure it out. – slothbag Jun 27 '16 at 23:53