Skip to main content

Access Ethereum Blockchain Data: A Comparative Tutorial of Web3.py, Ethereum2-ETL, Etherscan-python, and Bitquery

Staking Mechanism Design: Ethereum for Social Good

Published onMar 06, 2023
Access Ethereum Blockchain Data: A Comparative Tutorial of Web3.py, Ethereum2-ETL, Etherscan-python, and Bitquery
·

This article provides a tutorial on how to access Ethereum blockchain data through four tools Web3.py, Ethereum2-ETL, Etherscan-python, and Bitquery. We summarize the supplementary materials including sample code and data in Table 1. We provide our complete open-source code and data on GitHub: https://github.com/SciEcon/eth-data-collection.

Part I Web3.py

Web3.py is a Python library that allows interaction with Ethereum, typically used in decentralized apps. It offers functionality for sending transactions, working with smart contracts, retrieving block information, and more. The library's API was initially based on Web3.js (JavaScript) but has been adapted to better suit the needs of Python developers. Figure 1 shows a sample visualization produced by the Ethereum blockchain block data queried via Web3py.

Collecting on-chain data using Web3py requires an Ethereum endpoint. The best way is to use a remote node provider such as Infura, Alchemy, or QuickNode. For how to request an Ethereum endpoint, refer to the instructions: https://ms.pubpub.org/pub/computing/.

Figure 1: Ethereum Blockchain Block Data Visualization via Web3py

Part II Etherem2-ETL

Ethereum2-ETL enables the transformation of blockchain information into user-friendly formats, such as CSV and relational databases. With over 700 likes on GitHub, Ethereum-ETL is the most popular open-source project for Ethereum data. Ethereum2-ETL is a fork of Ethereum-ETL that adds support for Ethereum2-ETL data. Figure 2 shows a sample visualization for the Ethereum beacon chain deposit counts for data queried via Ethereum2-ETL.

Figure 2 Ethereum Beacon Chain Deposit Count and Epoch Visualization via Ethereum2-ETL

Part III Etherscan-python

etherscan-python is a comprehensive Python API for Etherscan.io. It offers both the standard and pro endpoints for the mainnet of the Ethereum blockchain as well as that of the Kovan, Rinkeby, and Ropsten testnets. The API can be found on PyPI and is powered by the Etherscan.io APIs. Figure 3 shows a sample visualization for the Ethereum blockchain block reward and uncle inclusion reward for data queried through etherscan-python.

Figure 3 Ethereum Blockchain Block Reward Data Visualization via Etherscan-python

Part IV BitQuery

Bitquery is a GraphQL API that provides a flexible and efficient way to access and analyze blockchain data. By using GraphQL, Bitquery enables users to query only the data they need, rather than receiving a large amount of unneeded data. This results in faster, more streamlined access to blockchain data, and improved performance overall. Figure 4 shows the sample visualization of staked ether on the Proof-of-stake Ethereum Beacon chain for data queried through Bitquery.

Figure 4 Staked Ether Time Series via Bitquery

Tool

Official Documentation

API Type

API requirement

Sample Code

Sample Data

Web3.py

https://web3py.readthedocs.io/

RPC API

Endpoint URL from Ethereum node providers

Web3py Google Colab

Web3py Data

Ethereum2-ETL

https://ethereum2-etl.readthedocs.io/

RPC API

Endpoint URL from Ethereum node providers

Ethereum2-ETL Google Colab

Ethereum2-ETL Data

Etherscan-python

https://github.com/pcko1/etherscan-python

RPC API

Etherscan API Key: https://etherscan.io/apis

Etherscan Google Colab

Etherscan Data

Bitquery

https://bitquery.io/

GraphQL API

GraphQL API Key:

https://bitquery.io/blog/graphql-with-python-javascript-and-ruby#Getting_API_Key

Bitquery Google Colab

Bitquery Data

Table 1: A Comparative Tutorial of Web3.py, Ethereum2-ETL, Etherscan-python, and BitQuery

Comments
0
comment
No comments here
Why not start the discussion?