Skip to main content
State diffs are available from SQD Network Portals on the same basis as all other data served there: for free, including real-time blocks. There are no surcharges for traces or state diffs.

addStateDiff(options)

Subscribe to changes in the contract storage. This allows for tracking the contract state changes that are difficult to infer from events or transactions, such as the changes that take into account the output of internal calls. options has the following structure:
Item filters (where):
  • address: the set of addresses of contracts to track. Omit to subscribe to state changes of all contracts from the whole network.
  • key: the set of storage keys that should be tracked. Regular hexadecimal contract storage keys and special keys ('balance', 'code', 'nonce') are allowed. Omit to subscribe to all state changes.
  • kind: the set of diff kinds that should be tracked. Refer to the state diffs section of the field selection page for an explanation of the meaning of the permitted values.
Filter values are matched as exact strings by the Portal — always pass addresses and storage keys as lowercase hex strings. @subsquid/evm-stream does not normalize the case for you.
Enabling the transaction flag of include will cause the data source to retrieve the transaction that gave rise to each state change and add it to the transactions iterable of the block data. Call augmentBlock() from @subsquid/evm-objects to navigate from a diff to its transaction conveniently (stateDiff.transaction, stateDiff.getTransaction()). range overrides the global setBlockRange() for this particular request. Note that state diffs can also be requested by the addTransaction() method as related data. Selection of the exact fields to be retrieved for each state diff item and its optional parent transaction is done with the setFields() method documented on the Field selection page. There are no default fields: request kind, prev and/or next explicitly if your handler reads them.

Example

Track additions and changes to the storage of the DAI contract, fetching the old and the new values and the hash of the responsible transaction: