Changes in values in solidity mappings in contracts.

Schema

Column NameData Type
chain_idlong
txn_hashstring
block_numberlong
global_counterbigDecimal
contract_addressstring
variable_namestring
variable_slotstring
entry_slotstring
key_1_valuestring
key_1_typestring
key_2_valuestring
key_2_typestring
key_3_valuestring
key_3_typestring
value_beforestring
value_afterstring
value_typestring

Coverage

Ethereum (1), Base (8453), and Arbitrum (42161)

Source

The table is built within the Mapping storage writes canvas.

Usage notes

This table indexes the solidity mapping write updates up to a depth of 3 keys for nested mappings.

For verified contracts, mapping storage variables are retrieved from the contract source code. For unverified contracts, mapping variables are inferred using our Storage Layout Extractor tool.

Newly verified contracts will only have decoded mapping values using the source code after the source code verification date. Before, the data will be available using the inferred storage layout.

The column global_counter represents a custom execution clock. It is monotonically increasing and can be used to order events.

Sample queries

1. Number of unique addresses that ever had a USDC balance

SELECT DISTINCTCOUNT(key_1_value) AS unique_addresses
  FROM @sim.mapping_storage_writes
 WHERE variable_name = 'balanceAndBlacklistStates'
   AND contract_address = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
   

2. Number of unique addresses with active USDC balance

WITH latest_writes AS (
  SELECT key_1_value,
         MAX(CAST(global_counter AS double)) AS max_global_counter
    FROM @sim.mapping_storage_writes
   WHERE variable_name = 'balanceAndBlacklistStates'
     AND contract_address = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
   GROUP BY 1
)

SELECT DISTINCTCOUNT(sw.key_1_value) AS unique_active_addresses
  FROM @sim.mapping_storage_writes sw
  JOIN latest_writes lw ON CAST(sw.global_counter AS double) = lw.max_global_counter
   AND sw.key_1_value = lw.key_1_value
 WHERE true
   AND sw.variable_name = 'balanceAndBlacklistStates'
   AND sw.contract_address = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'

3. Transactions updating mappings containing a given address in the keys

SELECT  txn_hash,
        block_number,
        contract_address,
        variable_name,
        variable_slot,
        value_after,
        value_before,
        key_1_value,
        key_2_value,
        key_3_value
FROM @sim.mapping_storage_writes 
WHERE key_1_value = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'
   OR key_2_value = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'
   OR key_3_value = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'