0

I'm looking for a way to find the block corresponding to a given timestamp; for a graph where you can see your balances per day in a graph. I tried to make it but my provider/node was using too much compute units and just the general way which I tried made me uncomfortable. Is there a better way to get the balances of the past week at the given hour using some kind of javascript package?

Here's what I tried:

            const url = "https://api-rinkeby.etherscan.io/api?module=account"

            let dataWallet = []

            request({url:url, qs:query}, function(err, response, body) {
                let data = JSON.parse(response.body);

                Object.keys(data.result).forEach((item) => {
                    let _data = data.result[item]
                    
                    alchemyWs.getBlock(parseInt(_data.blockNumber)).then(function(block) {                        
                        for (let i = 0; i < 7; i++) {
                            let oldTimestamp = Math.floor((new Date().getTime() - (60 * 60 * 24 * i * 1000)) / 1000)

                            if (block.timestamp >= oldTimestamp) {
                                dataWallet.push(_data.balance)
                            }
                        }
                    })
                })
            })

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy