Skip to main content

eth_getStorageAt

Queries raw storage data from smart contracts deployed on Unichain. This method enables deep inspection of DeFi protocols, AMM pools, token balances, and other contract state variables essential for trading and liquidity analysis.

Parameters​

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

Unichain DeFi Storage Patterns​

  • AMM pools: Reserve amounts, liquidity data, and fee calculations
  • Token contracts: Balances, allowances, and total supply tracking
  • Governance: Voting power, proposal states, and protocol parameters
  • Yield farming: Staking rewards, pool shares, and harvest data

Returns​

A 32-byte hex string containing the storage value. Values are left-padded with zeros to maintain consistent 32-byte formatting.

Code Examples​

# Read storage from Uniswap V3 pool on Unichain
curl -X POST https://api-unichain-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getStorageAt",
"params": [
"0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640",
"0x0",
"latest"
],
"id": 1
}'

Response Example​

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

DeFi-Specific Applications​

  • AMM Analysis: Monitor liquidity pools, reserve ratios, and trading fees
  • Yield Farming: Track staking positions, reward accumulation, and pool shares
  • Token Economics: Analyze supply distribution, holder balances, and transfer patterns
  • Price Discovery: Extract price data from oracle contracts and AMM pools
  • Governance Tracking: Monitor voting power, proposal states, and protocol parameters

Uniswap V3 Storage Layout​

Pool State (Slot 0)​

// Uniswap V3 pool slot 0 layout
const extractPoolState = (slot0Hex) => {
const slot0Int = BigInt(slot0Hex);

return {
sqrtPriceX96: slot0Int & ((1n << 160n) - 1n),
tick: Number((slot0Int >> 160n) & ((1n << 24n) - 1n)),
observationIndex: Number((slot0Int >> 184n) & ((1n << 16n) - 1n)),
observationCardinality: Number((slot0Int >> 200n) & ((1n << 16n) - 1n)),
observationCardinalityNext: Number((slot0Int >> 216n) & ((1n << 16n) - 1n)),
feeProtocol: Number((slot0Int >> 232n) & ((1n << 8n) - 1n)),
unlocked: Boolean((slot0Int >> 240n) & 1n)
};
};

ERC-20 Token Storage​

// Standard ERC-20 storage layout
const erc20Slots = {
balances: 0, // mapping(address => uint256)
allowances: 1, // mapping(address => mapping(address => uint256))
totalSupply: 2, // uint256
name: 3, // string
symbol: 4, // string
decimals: 5 // uint8
};

Liquidity Position Data​

// Uniswap V3 position manager storage
const positionSlots = {
positions: 2, // mapping(uint256 => Position)
ownerOf: 3, // mapping(uint256 => address)
getApproved: 4, // mapping(uint256 => address)
operators: 5 // mapping(address => mapping(address => bool))
};

Advanced DeFi Calculations​

  • Price calculation: price = (sqrtPriceX96 / 2^96)^2
  • Liquidity calculation requires token reserves and current price
  • Fee calculations depend on pool fee tier (0.01%, 0.05%, 0.3%, 1%)
  • Position value requires current price and liquidity range
  • Yield calculations need historical data and time-based analysis

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