3

I want to implement a feature that given by a wallet address and timestamp, it'll return the historical sol balance at that time. By using rpc method getSignaturesForAddress, getTransaction and getBlock, is it possible to implement it?

My thought is: getSignaturesForAddress for wallet tx list and getTransaction for tx detail info. getBlock for covering things like rent that influence balance calculation.

1
  • You can do it by what you thought
    – yacho
    Aug 9, 2022 at 16:37

2 Answers 2

1

Not directly, no. There's no way to look up a transaction by timestamp. You'd have to bisect the results of getSignaturesForAddress by examining the timestamp of the corresponding getTransaction result for each. Once you find the transaction, you can use whichever of preBalance or postBalance fields is appropriate for your application to look up the account's lamports balance

3
  • Thanks for your comment. Considering the fact that there is epoch rent happend in blocks, only using preBalance and postBalance may not be accurate in my opinion, cause there may be extra sol amount cost happend outside transdactions, in that case, the post balance of closest transaction in given timestmap can not be treated as 'final balance'. Am i understanding right about this?
    – Xkimnt
    Aug 19, 2022 at 15:11
  • postBalance will reflect rent collection if it occurred during transaction execution. there will be an entry in the block's rewards field otherwise
    – trent.sol
    Aug 19, 2022 at 17:05
  • I understand the fact that there are two kinds of rent. I fetch all tx history of user account now. By calculating gap between preBalance and postBalance, I can know how much sol increase or decrease in each tx. By summing up all these calculations, I can get the historical balance. But for some accounts, I also find there is tiny sol missing, which I believe that it is rent happend in block rewards. So, in order to get accurate result through this method, using getBlock is necessary in my opinion if I want to list all the event that impact balance.
    – Xkimnt
    Aug 20, 2022 at 18:43
1

I know this but why? Imagine an account with 10,000 transfers or more, maybe not now but as time passes the accounts will have more and more transactions... is the only solution to use a server to store transactions in a database to speed up things for native SOL?

1
  • Pretty sure this is where it's going now.
    – Ake
    Dec 28, 2023 at 1:26

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.