eth_getStorageAt
Returns the value from a storage position at a given address.
When to Use This Method
Use eth_getStorageAt
to:
- Read Storage Variables - Access contract state directly
- Debug Contracts - Inspect storage slots
- Verify State - Check storage without calling functions
- Analyze Data - Read raw storage data
- Security Research - Examine contract internals
Parameters
-
Address -
DATA
, 20 Bytes- Address of the storage
-
Position -
QUANTITY
- Storage position (slot)
-
Block Parameter -
QUANTITY|TAG
latest
,earliest
,pending
, or block number
{
"jsonrpc": "2.0",
"method": "eth_getStorageAt",
"params": [
"0x295a70b2de5e3953354a6a8344e616ed314d7251",
"0x0",
"latest"
],
"id": 1
}
Returns
DATA
- The value at this storage position.
Implementation Examples
- JavaScript
- Python
import { ethers } from 'ethers';
const provider = new ethers.JsonRpcProvider('https://api-xdc-mainnet.n.dwellir.com/YOUR_API_KEY');
// Read storage slot 0
const contractAddress = '0x295a70b2de5e3953354a6a8344e616ed314d7251';
const slot = '0x0';
const value = await provider.getStorageAt(contractAddress, slot);
console.log('Storage value:', value);
// Read mapping value
function getMapLocation(key, slot) {
return ethers.keccak256(
ethers.concat([
ethers.zeroPadValue(key, 32),
ethers.zeroPadValue(slot, 32)
])
);
}
const userAddress = '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb8';
const balanceSlot = '0x1'; // Assuming balances mapping is at slot 1
const userBalanceSlot = getMapLocation(userAddress, balanceSlot);
const balance = await provider.getStorageAt(contractAddress, userBalanceSlot);
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://api-xdc-mainnet.n.dwellir.com/YOUR_API_KEY'))
# Read storage at position 0
contract_address = '0x295a70b2de5e3953354a6a8344e616ed314d7251'
storage_position = 0
value = w3.eth.get_storage_at(contract_address, storage_position)
print(f'Storage value: {value.hex()}')
Related Methods
- eth_getCode - Get contract bytecode
- eth_call - Execute contract function