Hi,
Is there a way for a Dapp or a NodeJS application to retrieve the wallet balances of a user, with the user consent, for a certain period in the past? I thought that maybe with the wallet address there would be a way to search for its transactions in the blockchain, identifying any token by the contract address or any ERC20 signature of the contract. I also thought that maybe Metamask would have this information because it has transaction history, but I didn’t find that in their documentation.

Jul 25, 2020, 10:39 PM
This is not so trivial. The blockchain doesn't offer ways to search history (at least not point-in-time token balances) so it has to be performed in the backend. Also typical clients don't offer search functionality I think as it requires an archive node which is rather rare to have.

So basically you need to iterate through the blockchain starting from the beginning and store the data in a searchable way in some database.
Jul 26, 2020, 4:44 AM
https://ethereum.stackexchange.com/questions/47215/how-can-we-obtain-the-state-value-of-a-variable-from-previous-block-number-using
not sure if web3.js supports that but it might be worth a shot
https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#eth-contract under defaultBlock
Jul 26, 2020, 4:53 AM
so we can't make bold investments.
Jul 26, 2020, 5:01 AM
This is interesting. I wonder how it is achieved, assuming it doesn't require an archive node
Or maybe that library simply stores the data in required format
Jul 26, 2020, 5:08 AM
from the example it looks like you just supply a block number with the call to the smart contract. maybe you can even set a default block that web3 pulls from. As to whether or not infura accepts that argument i dunno, might be a science experiment
Jul 26, 2020, 6:04 AM
Well it is doable or course, it's just a matter of whether it's efficient in any way. Normal node doesn't store history state snapshots so they'd need to iterate over all transactions to calculate the result at block X
Jul 26, 2020, 7:44 AM
This is the code.I
Jul 26, 2020, 8:01 AM
Lauri, thanks for your answer. Metamask does display the transaction history of the wallet. That’s what I need. I don’t know if Metamask is open source. I could clone it and modify it ( worst case ). A simpler solution would be to get this info from Metamask when the user connects the wallet but I don’t think they expose this data.
Jul 27, 2020, 2:35 PM
if all you need are transactions, there are many options available via etherscan: https://etherscan.io/apis#accounts
Jul 27, 2020, 4:01 PM
Nice!
Jul 27, 2020, 5:38 PM

© 2024 Draquery.com All rights reserved.