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?
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?
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.
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));
});
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"