2

I want to fetch data from Solana chain (getBlock) and record state changes. pre/post balances will be useful to me to know balances of wallets over time.

It's not obvious to me how should I handle case when there are multiple transactions in one block affecting balance of the same (wallet, token) pair. Is it the case that for such a pair, every pre/post balance will be the same across whole block? Or maybe there is some hidden 'order' of transactions and I need to find 'latest' transaction in given block to know what is the real postBalance?

Thank you for any help!

1 Answer 1

1

The order of transactions in getBlock should be consistent with how it was replayed by the network, so I believe you can just iterate through the transactions, and the latest transaction has the final post balance that you'll care about.

Transactions that write to the same account must be ordered consistently across the block, otherwise validators will not be able to reach consensus on the final state of the system, so ordering is very important. I'm not 100% sure that getBlock will provide the correct execution order, but I would be surprised if it didn't.

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.