Bắt đầu với TheRPC
Tham khảo API
Ethereum API
Core API
Hướng dẫn
Ethereum/Core API/eth_getStorageAt

eth_getStorageAt

The eth_getStorageAt method returns the value stored at a specific storage position for a given smart contract address. This low-level method allows direct access to the contract's state variables and is crucial for contract analysis and debugging.

Use Cases

  • Smart contract debugging and analysis
  • Token balance verification
  • Protocol governance inspection
  • Proxy implementation verification
  • Contract state auditing
  • Storage layout validation
  • DAO proposal status checking
  • Contract upgrade verification

Method Details

This method provides raw access to any storage slot in a contract's storage.

Tham số:

The address of the smart contract

The integer of the storage position (hex string)

Block number in hex format or block tag

Trả về:

The value at the specified storage position (32 bytes, hex encoded)

Response Example

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

Understanding Solidity Storage Layout

Solidity's storage layout follows specific rules:

  1. State Variables: Stored sequentially starting from slot 0
// Storage slot 0
uint256 firstVariable;
// Storage slot 1
address secondVariable;
  1. Mappings: The slot itself contains no data, but serves as a seed for computing positions
// Storage slot 2 (empty)
mapping(address => uint256) balances;
// Value stored at keccak256(abi.encode(userAddress, 2))
  1. Dynamic Arrays: The slot contains the array length, data starts at keccak256(slot)
// Storage slot 3 has length
uint256[] myArray;
// Values stored at keccak256(3) + index
  1. Packed Variables: Multiple variables smaller than 32 bytes are packed together
// All in storage slot 4
uint128 a;
uint64 b;
uint64 c;

Common Storage Slots

  • ERC20 Total Supply: Often stored at slot 0 or 2
  • ERC20 Balances Mapping: Often at slot 1 or 3
  • ERC20 Allowances Mapping: Often at slot 2 or 4
  • Proxy Implementation Address: For EIP-1967 proxies at 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc

Storage Inspection Tools

For complex contracts, consider using dedicated tools:

  • Slither: Static analyzer that can generate storage layouts
  • Tenderly: Visual debugger with storage inspection
  • Hardhat: Console debugging with storage access
  • Etherscan: Sometimes provides verified contract storage layouts

See also

  • eth_getCode - Get the bytecode deployed at a specific address
  • eth_getProof - Retrieve cryptographic proofs for account and storage values
Giúp chúng tôi trở nên tốt hơn!
Chia sẻ trang này và giúp chúng tôi tạo ra sản phẩm tốt hơn cho bạn.