It's pretty easy to get state change before/after a block using a Web3 library. But I am stuck on getting the state change of a transaction.

Like any etherscan txn receipt we can view the State change: https://etherscan.io/tx/0x66519e9ce700b99a473da93cbe1f437bc843dc2a40a5c2079fd5d2defb421ec3#statechange enter image description here

The same contract could have multiple state changes within a block, how to programmatically get each of these changes? I would imagine I need a full-archive node to access the historical state before this block and replay all the txns within that block?


1 Answer 1


You'll need to use one of the "trace" RPC methods for transactions. Here's a decent write-up on the matter (link). For transactions involving tokens (so anything that's not ETH), the contract's storage will get altered. The "id" of the storage location that's altered is encoded, so you'll need to figure out how to decode what variable/mapping was changed.

Example of storage layout importance... For an ERC-20 token transfer you'll have a mapping of storage locations to balances where a unique storage location corresponds to a wallet address (effectively mapping wallet address to token balance). Upon executing the transaction, the balance variable that maps to the "sender" would have a corresponding value that decreases by "x" and the mapping to the "recipient" would have a corresponding value that increases by "x". The hard part is programmatically determining what the storage location of a person's balance is. Here are some links related to programatically determining storage locations: link, link, link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.