eth_getStorageAt | zkEVM

Polygon zkEVM API method that returns the data stored at a specific storage slot within a smart contract. It can help developers read a smart contract's internal state, like user data or balances, to inform decisions and build more advanced applications that interact with smart contracts on the blockchain.

๐Ÿ‘

Get you own node endpoint today

Start for free and get your app to production levels immediately. No credit card required.

You can sign up with your GitHub, X, Google, or Microsoft account.

Parameters

  • address โ€” the address of the smart contract to query

  • quantity โ€” the index of the storage position to retrieve the data from

  • quantity or tag โ€” the integer of a block encoded as hexadecimal or the string with:

    • latest โ€” the most recent block in the blockchain and the current state of the blockchain at the most recent block. A chain reorganization is to be expected.

    • safe โ€” the block that received justification from the beacon chain. Although this block could be involved in a chain reorganization, it would necessitate either a coordinated attack by the majority of validators or an instance of severe propagation latency.

    • finalized โ€” the block accepted as canonical by more than 2/3 of the validators. A chain reorganization is extremely unlikely, and it would require at least 1/3 of the staked ETH to be burned.

    • earliest โ€” the earliest available or genesis block

    • pending โ€” the pending state and transactions block. The current state of transactions that have been broadcast to the network but have not yet been included in a block.

      ๐Ÿ“˜

      See the default block parameter and How The Merge Impacts Ethereumโ€™s Application Layer.

Response

data โ€” the data stored in the storage slot. Returned as a hexadecimal string.

eth_getStorageAt code examples

The following example returns the storage value at slot 0 from the WETH Token on the Polygon zkEVM mainnet. In this case, this is the token's name.

This method can retrieve the different storage values in time by querying different blocks in the past. Note that to query a state in the past, you need an archive node.

๐Ÿ“˜

cURL needs a HEX String starting with 0x to identify the block if you want to use a hex integer block number as a parameter.
For example, block number 14000000 will be 0xD59F80. Use the Chainstack EVM Knife to make those conversions.

const { Web3 } = require("web3");
const NODE_URL = "CHAINSTACK_NODE_URL";
const web3 = new Web3(NODE_URL);

async function getstorage(address, slot, block) {
  const storage = await web3.eth.getStorageAt(address, slot, block)
  console.log(storage)
 }
 
 getstorage("0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9", 0, "latest" )
const ethers = require('ethers');
const NODE_URL = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(NODE_URL);

const getstorage = async (address, slot, block) => {
    const storage = await provider.send("eth_getStorageAt", [address, slot, block]);
    console.log(storage);
  };

getstorage("0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9", "0", "latest" )
from web3 import Web3  
node_url = "CHAINSTACK_NODE_URL" 

storage = web3.eth.get_storage_at("0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9", 0, "latest")
print(web3.to_hex(storage))

Use case

One use case for eth_getStorageAt is analyzing how the value stored at a specific storage slot of a smart contract changes over time. For example, a developer may want to track the change in a specific variable of a smart contract, such as the total supply of a token, and perform some analysis on it.

Try the eth_getStorageAt RPC method yourself

Language
Click Try It! to start a request and see the response here!