Skip to main content

eth_getStorageAt

Retrieves storage data from a specific slot within a smart contract deployed on Polygon. This method provides low-level access to contract state, enabling deep inspection of variables, mappings, and complex data structures.

Parameters​

ParameterTypeRequiredDescription
addressstringYesContract address (20 bytes) to query storage from
positionstringYesStorage slot position in hex format (32 bytes, 0x-prefixed)
blockNumberstringYesBlock number in hex or block tag ("latest", "earliest", "pending")

Storage Position Guide​

  • Sequential variables: Start at slot 0x0, increment by 1
  • Mapping entries: keccak256(concat(key, mapping_slot))
  • Array elements: Length at slot, elements at keccak256(slot) + index
  • Nested structures: Follow Solidity's storage layout rules

Returns​

Returns a 32-byte hex-encoded string representing the storage content. Values smaller than 32 bytes are padded with leading zeros.

Code Examples​

# Read storage from USDC contract on Polygon
curl -X POST https://api-polygon-mainnet-full.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getStorageAt",
"params": [
"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
"0x2",
"latest"
],
"id": 1
}'

Response Example​

{
"jsonrpc": "2.0",
"id": 1,
"result": "0x000000000000000000000000000000000000000000000000000009184e72a000"
}

Practical Applications​

  • DeFi Analysis: Inspect liquidity pool reserves, user positions, and protocol parameters
  • Token Auditing: Verify token supply, distribution, and holder balances
  • Proxy Detection: Identify implementation contracts behind proxy patterns
  • Gaming/NFT: Access metadata, ownership records, and game state
  • Governance: Read voting weights, proposal data, and delegation mappings

Storage Layout Examples​

ERC-20 Token Storage​

// Typical ERC-20 storage layout
const slots = {
totalSupply: '0x2', // slot 2
balances: 0, // mapping at slot 0
allowances: 1, // nested mapping at slot 1
name: '0x3', // slot 3
symbol: '0x4', // slot 4
decimals: '0x5' // slot 5
};

Complex Mapping Calculations​

// balances[user] - simple mapping
const balanceSlot = keccak256(userAddress.padStart(64, '0') + '00'.repeat(31) + '00');

// allowances[owner][spender] - nested mapping
const ownerSlot = keccak256(ownerAddress.padStart(64, '0') + '00'.repeat(31) + '01');
const allowanceSlot = keccak256(spenderAddress.padStart(64, '0') + ownerSlot.slice(2));

Dynamic Array Access​

// Array length at slot 6
const arrayLength = await getStorageAt(contract, '0x6');

// First element at keccak256(0x6)
const firstElementSlot = keccak256('0x' + '6'.padStart(64, '0'));

// Subsequent elements: firstElementSlot + index
const secondElementSlot = '0x' + (BigInt(firstElementSlot) + 1n).toString(16);

Performance Tips​

  • Use historical block numbers for time-series analysis
  • Batch multiple storage reads for efficiency
  • Cache frequently accessed storage positions
  • Consider storage packing when reading adjacent slots
  • Validate storage layout against contract source code

Need help? Contact our support team or check the Polygon documentation.