examples/full-contract-state/README.md
This example demonstrates how to extract the complete state of a specific contract from the reth database.
The example shows how to:
RETH_DATADIR environment variable to point to your reth data directoryCONTRACT_ADDRESS environment variable to provide target contract address# Set your reth data directory
export RETH_DATADIR="/path/to/your/reth/datadir"
# Set target contract address
export CONTRACT_ADDRESS="0x0..."
# Run the example
cargo run --example full-contract-state
The example consists of:
ContractState struct - Holds all contract state informationextract_contract_state function - Main function that extracts contract statemain function - Sets up the provider and demonstrates usageThe example uses reth's provider pattern:
ProviderFactory - Creates database connectionsDatabaseProvider - Provides low-level database accessStateProvider - Provides high-level state accessFor efficient storage iteration, the example uses database cursors:
cursor_dup_read - Creates a cursor for duplicate key tablesseek_exact - Positions cursor at specific keynext_dup - Iterates through duplicate entriesThe example will print:
The example includes proper error handling:
None if the contract doesn't existProviderResult for database operation errors