I know there's an API called accountSubscribe
that I can use to get notified when an Account is modified when new blocks arrive. But for historical blocks / transactions, how can I tell if an Account was modified by a given transaction?
I define "modified" as data or lamport changes, instead of being just read-only accessed. Just like in WebSocket subscriptions, if such a change happens in transactions, it should be spotted out.
I noticed that in the getTransaction
API, the returned structure has transaction.message.accountKeys
where each item has a field writable
. I wonder if it's safe to say, if meta.err
of the transaction is null
and the writable
field is true
, the Account is modified by that transaction?
Just using the normal RPC endpoints, there's no way to be sure.
If a transaction succeeded and the account was writable, the account data could have stayed the same. For example, if I transfer 0 tokens to you, the transaction will succeed, and be shown as "writable", but no modification was done.
If you only care about SOL / token balances, you can use the preTokenBalances
vs postTokenBalances
or preBalances
vs postBalances
when fetching past transactions. More info at https://docs.solana.com/api/http#gettransaction
Past that, there's no way to know currently.