Ethereum ETL Postgres 使用指南
项目介绍
Ethereum ETL Postgres 是一个开源项目,旨在将 Ethereum 区块链数据迁移到 PostgreSQL 数据库中。该项目提供了 Python 脚本,用于执行 ETL(提取、转换和加载)作业,包括区块、交易、ERC20/ERC721 代币转账、收据、日志、合约和内部交易等数据。数据可以直接在 Google BigQuery 中使用,也可以导出为 CSV 格式。
项目快速启动
安装
首先,确保你已经安装了 Python 3。然后,使用 pip 安装 Ethereum ETL:
pip3 install ethereum-etl
导出区块和交易
以下命令将导出指定范围内的区块和交易数据:
ethereumetl export_blocks_and_transactions \
--start-block 0 \
--end-block 500000 \
--blocks-output blocks.csv \
--transactions-output transactions.csv \
--provider-uri https://mainnet.infura.io/v3/YOUR_API_KEY
导入到 PostgreSQL
假设你已经安装并配置了 PostgreSQL,可以使用以下命令将数据导入到 PostgreSQL 数据库中:
psql -d ethereum -h 127.0.0.1 --port 5432 -U your_username -W
然后在 psql 中执行以下命令:
\copy blocks FROM 'blocks.csv' CSV HEADER;
\copy transactions FROM 'transactions.csv' CSV HEADER;
应用案例和最佳实践
数据分析
使用导出的数据,可以进行各种数据分析,例如:
- 分析特定时间段内的交易量和交易类型。
- 跟踪特定地址的资金流动。
- 分析 ERC20 和 ERC721 代币的转账情况。
实时数据流
可以使用 ethereumetl stream
命令实时从 Ethereum 节点拉取数据并插入到 PostgreSQL 表中:
ethereumetl stream \
--provider-uri https://mainnet.infura.io/v3/YOUR_API_KEY \
--postgres-url postgresql://your_username:your_password@localhost:5432/ethereum
典型生态项目
Google BigQuery
Ethereum ETL 提供了与 Google BigQuery 的集成,可以直接在 BigQuery 中查询 Ethereum 数据:
Nansen
Nansen 是一个 Ethereum 数据分析平台,提供了丰富的数据分析工具和可视化界面:
通过这些工具和平台,可以更深入地分析和理解 Ethereum 区块链上的数据。