Staking Mechanism Design: Ethereum for Social Good
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.
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/.
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.
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.
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.
Tool | Official Documentation | API Type | API requirement | Sample Code | Sample Data |
Web3.py | RPC API | Endpoint URL from Ethereum node providers | |||
Ethereum2-ETL | RPC API | Endpoint URL from Ethereum node providers | |||
Etherscan-python | RPC API | Etherscan API Key: https://etherscan.io/apis | |||
Bitquery | GraphQL API | GraphQL API Key: https://bitquery.io/blog/graphql-with-python-javascript-and-ruby#Getting_API_Key |
Table 1: A Comparative Tutorial of Web3.py, Ethereum2-ETL, Etherscan-python, and BitQuery