I found this repo, which retrieves recent gas prices using web3:
https://github.com/ethgasstation/gasstation-express-oracle/blob/master/gasExpress.py
I'd like to write a similar script that would stay running and get a callback every time a new block occurred with all the transactions in the block, and keep a running average of gas prices rather than invoke all these calls every time we need to check.
Seems like there is a websockets server option in the web3 library. I'm struggling with how to test this. Does testrpc allow me to observe block changes automatically? If so, how?
web3.eth.getBlockNumber()
tells you the latest block number, and if it's one you haven't seen before, you can then process the block. I recommend this just because websocket support isn't great yet. For example, neitherganache-cli
(formerlytestrpc
) nor Infura support it so far.