Ethereum Queries in Python With No Web3 Libraries

Nathan Mueller
5 min readJul 12, 2020

With the DeFi narrative growing in strength and Eth2.0 looking like it might arrive by next year maybe you’ve decided that it’s time to figure out how this all works. I did a small data science project on Ethereum recently and for some reason decided it would be more fun to not use any of the web3 libraries. I had a lot of trouble finding some of the information I needed so I’ve collected some of it below so that I can hopefully save you some time or maybe just help you learn something new!

Let’s say you want to query all the event logs for a smart contract in a certain block range. I’ll be using CryptoKitties as an example for this article. If you don’t have an Ethereum node of your own you can get access to one from Infura for free.

Once you’ve got an API key from Infura you can get logs in a range like so:

Make sure to replace infura_project_id with your own Infura project id. startingBlock and endingBlock are just to define the block range you want to query. Every transaction in a smart contract has a topic. It can be thought of as the name of…

--

--