用于将以太坊区块链数据导出为CSV或JSON的工具
ethereum-etl的Python项目详细描述
以太坊ETL
安装以太坊ETL:
pip3 install ethereum-etl
导出块和事务(schema,引用:):
> ethereumetl export_blocks_and_transactions --start-block 0 --end-block 500000\ --provider-uri https://mainnet.infura.io --blocks-output blocks.csv --transactions-output transactions.csv
> ethereumetl export_token_transfers --start-block 0 --end-block 500000\ --provider-uri file://$HOME/Library/Ethereum/geth.ipc --output token_transfers.csv
> ethereumetl export_traces --start-block 0 --end-block 500000\ --provider-uri file://$HOME/Library/Ethereum/parity.ipc --output traces.csv
流块、事务、日志、令牌持续地传输到控制台(引用):
> pip3 install ethereum-etl[streaming] > ethereumetl stream --start-block 500000 -e block,transaction,log,token_transfer --log-file log.txt
在此处查找其他命令
有关最新版本,请查看回购协议并致电
> pip3 install -e . > python3 ethereumetl.py
目录
- 模式
- 导出区块链
- 在2小时内导出
- 命令参考
- 以太坊经典支持
- 在Amazon Athena中查询
- 在google bigquery中查询
- 公共数据集
- 如何查询所有以太坊地址的余额rel="nofollow">如何查询所有以太坊地址的余额
- 在google cloud platform中构建令牌推荐程序rel="nofollow">在google cloud platform中构建令牌推荐程序
- 媒体中的区块链ETL
模式
blocks.csv
<表><广告>transactions.csv
<表><广告>token_transfers.csv
<表><广告>收据.csv
<表><广告>logs.csv
<表><广告>contracts.csv
<表><广告>tokens.csv
<表><广告>traces.csv
<表><广告>您可以在https://github.com/medvedev1088/ethereum-etl-aiflow/tree/master/dags/resources/stages/raw/schemas" rel="nofollow">https://github.com/medvedev1088/ethereum etl aiflow中找到列描述
注意:对于地址
类型,所有十六进制字符都是小写的。
boolean
type可以有两个值:true
或false
限制
- 如果契约是一个代理,它将所有调用转发给一个代理,则接口检测不起作用,
这意味着对于代理合同,
is erc20
和is erc721
将始终为false,并且它们将在令牌中丢失
表 - ERC20的元数据方法(
symbol
,name
,decimals
,total_supply
)是可选的,因此大约10%的 合同缺少此数据。还有一些合同(EOS)实现了这些方法,但是返回类型错误, 因此,在这种情况下,元数据列也会丢失。 token_transfers.value
,tokens.decimals
和tokens.total_supply
在bigquery表中有类型string
, 因为数字类型不能处理32字节的整数。你应该用强制转换(值为float64)
(可能丢失精度)或安全强制转换(数值形式)
(可能溢出)以转换为数字。- 未实现
decimals()
函数但具有 回退函数返回布尔值 将在CSV的小数
列中有0
或1
。
导出区块链
如果你想拥有区块链数据平台 在AWS或GCP中为您设置和主持,与我们联系 这里
安装python 3.5.3+https://www.python.org/downloads/
如果不需要erc20传输,可以使用infura(infura不支持eth_getfilterlogs json rpc方法)。 为此,请为下面的命令使用
-p https://mainnet.infura.io
选项。如果你需要转ERC20或者想 将数据导出快40倍,您需要设置一个本地以太坊节点:安装gethhttps://github.com/ethereum/go-ethereum/wiki/installing geth
开始吧。 通过在js控制台中执行
eth.syncing
来确保下载了所需的块。 您可以在currentblock
下面导出块, 无需等到完全同步,因为不需要状态(除非您还需要契约字节码 以及令牌详细信息;对于那些需要等待完全同步的用户。安装以太坊ETL:
> pip3 install ethereum-etl
全部导出:
> ethereumetl export_all --help > ethereumetl export_all -s 0 -e 5999999 -b 100000 -p file://$HOME/Library/Ethereum/geth.ipc -o output
如果路径中没有
ethereumetl
命令,请改用python3-m ethereumetl
。结果将出现在
output
子目录中,按配置单元样式分区:output/blocks/start_block=00000000/end_block=00099999/blocks_00000000_00099999.csv output/blocks/start_block=00100000/end_block=00199999/blocks_00100000_00199999.csv ... output/transactions/start_block=00000000/end_block=00099999/transactions_00000000_00099999.csv ... output/token_transfers/start_block=00000000/end_block=00099999/token_transfers_00000000_00099999.csv ...
< > >安装dockerhttps://docs.docker.com/install/
建立Docker图像
pip3 install ethereum-etl
0从图像中运行容器
pip3 install ethereum-etl
1运行流媒体到控制台或发布/订阅
pip3 install ethereum-etl
2 < > >- 导出戋u blocks戋u和戋u事务
- 导出令牌传输
- extract_token_transfers
- 导出收据和日志
- 出口合约
- 导出令牌
- 导出跟踪
- 导出跟踪
- 提取跟踪
- 获取挈u block_range_for挈u date
- 获取椆keccak椆u hash
- 流
- 默认情况下,此命令将块、事务、日志、令牌传输输出到控制台。
- 实体类型可以用
-e
选项指定, 例如,-e block、transaction、log、token_transfer、trace、contract、token
- 使用
--output
选项指定发布区块链数据的google pub/sub主题, 例如,项目/<;您的项目>;/主题/比特币区块链
。数据将被推送到项目/<;您的项目>;/主题/比特币区块链。区块
,项目/<;您的项目>;/主题/比特币区块链。交易
等主题。 - 该命令将其状态保存为
last_synched_block.txt
文件,其中定期保存上次同步的块号。 - 指定
--start block
或--last synced block file
选项。--上次同步的块文件应该指向 用于开始对区块链数据进行流式处理的区块号保存位置的文件。
- 使用
--lag
选项指定要滞后于区块链头部的块数。这是最简单的方法 处理链式重组-它们离头部越远就越不可能。 - 您可以调整
--period seconds
,--batch size
,--block batch size
,--max workers
以提高性能。 - 如需有关区块链ETL流媒体的信息,请参阅 关于部署到Kubernetes的说明。
to_address
字段与callcode
跟踪不同(geth似乎返回正确的值,因为to_address的奇偶校验值与父调用的
to_address的奇偶校验值相同);
- geth输出没有
奖励
跟踪;
- geth输出没有
到u地址
,从u地址
,值
对于自杀
跟踪; error
字段包含人类可读的错误消息,它们在geth/parity输出中可能有所不同;- geth输出没有
事务哈希
; 使用的气体在记录道上为0,在geth中为错误,奇偶校验中为空;
- 子包的零输出是geth中的
0x000…
,奇偶校验中的0x
; - 将文件上载到s3:
创建数据库:
- 创建表:
- 块:schemas/aws/blocks.sql rel="nofollow">schemas/aws/blocks.sql
- 事务:schemas/aws/transactions.sql rel="nofollow">schemas/aws/transactions.sql
- token_传输:schemas/aws/token_transfers.sql rel="nofollow">schemas/aws/token_transfers.sql
- 合同:schemas/aws/contracts.sql rel="nofollow">schemas/aws/contracts.sql
- 收据:schemas/aws/receipts.sql rel="nofollow">schemas/aws/receipts.sql
- 日志:schemas/aws/logs.sql rel="nofollow">schemas/aws/logs.sql
- 令牌:schemas/aws/tokens.sql rel="nofollow">schemas/aws/tokens.sql
- 创建表:
- 拼花木块:schemas/aws/parquet/parquet木块.sql
- 拼花交易:schemas/aws/parquet/parquet_transactions.sql
- parquet_token_transfers:模式/aws/parquet/parquet_token_transfers.sql
- 谷歌新区块链搜索工具的技术分类:https://www.forbes.com/siteS/MichaeldelCalcastilo/2019/02/05/谷歌推出比特币以太坊比特币现金冲刺DogeCoin以太坊经典LiteCoin和Zcash/394FC868C789
- 浏览比特币、以太坊、XRP:谷歌是如何悄悄地让区块链变得可搜索的:https://www.forbes.com/sites/michaeldelelcalcastilo/2019/02/04/navigation-bitcoin-ethereum-xrp-how-google-is-silent-making-blockchains-searchable/?SS=加密区块链49E111DA4248
应该在Linux、Mac、Windows上使用geth和parity。
如果使用奇偶校验,则应使用--no warp
选项禁用warp模式,因为warp模式
不会将所有块或接收数据放入数据库https://wiki.parity.io/getting-synced
如果您看到奇怪的行为,例如csv文件中错误的行数或损坏的文件, 查看此问题:https://github.com/medvedev1088/ethereum etl/issues/28
2小时后导出
您可以使用aws自动缩放和数据管道将导出时间减少到几个小时。 阅读本文了解详细信息https://medium.com/@medvedev1088/how-to-export-the-entire-ethereum-blockchain-to-csv-in-2-hours-for-10-69fef511e9a2
在Docker中运行
命令参考
所有命令都接受-h
参数以获取帮助,例如:
pip3 install ethereum-etl3
对于--output
参数,支持的类型是csv和json。格式类型是从输出文件名推断出来的。
导出块和事务
pip3 install ethereum-etl4
如果您只想导出事务/块,请省略--blocks output
或--transactions output
选项。
您可以调整--batch size
,--max workers
以提高性能。
导出令牌传输
infura不支持此命令中使用的api,因此需要一个本地节点。 如果您想使用infura导出erc20传输,请参阅extract戥u token戥transfers
pip3 install ethereum-etl5
include--tokens<;token1>;--tokens<;token2>;
仅过滤某些令牌,例如
pip3 install ethereum-etl6
您可以调整--batch size
,--max workers
以提高性能。
导出收据和日志
首先从transactions.csv中提取事务哈希值
(通过导出戋u blocks戋u and戋u transactions导出):
pip3 install ethereum-etl7
然后导出收据和日志:
pip3 install ethereum-etl8
如果您只想导出日志/收据,请省略--收据输出或
--日志输出选项。
您可以调整--batch size
,--max workers
以提高性能。
向上投票此功能请求https://github.com/paritytech/parity/issues/9075, 它将使收据和原木出口更快。
提取令牌传输
第一个导出收据日志,其中包含导出收据日志
然后从logs.csv文件中提取传输:
pip3 install ethereum-etl9
您可以调整--batch size
,--max工人
以提高绩效。
出口合同
首先从receipts.csv中提取合同地址
(导出时使用导出戋u receipts戋u and戋u logs):
> ethereumetl export_blocks_and_transactions --start-block 0 --end-block 500000\ --provider-uri https://mainnet.infura.io --blocks-output blocks.csv --transactions-output transactions.csv0
然后出口合同:
> ethereumetl export_blocks_and_transactions --start-block 0 --end-block 500000\ --provider-uri https://mainnet.infura.io --blocks-output blocks.csv --transactions-output transactions.csv1
您可以调整--batch size
,--max workers
以提高性能。
导出令牌
首先从contracts.json
(与export戋u contracts一起导出):
> ethereumetl export_blocks_and_transactions --start-block 0 --end-block 500000\ --provider-uri https://mainnet.infura.io --blocks-output blocks.csv --transactions-output transactions.csv2
然后导出erc20/erc721令牌:
> ethereumetl export_blocks_and_transactions --start-block 0 --end-block 500000\ --provider-uri https://mainnet.infura.io --blocks-output blocks.csv --transactions-output transactions.csv3
您可以调整--max workers
以提高性能。
导出跟踪
也称为内部交易。
infura不支持此命令中使用的api,
因此,您将需要一个本地奇偶校验存档节点(奇偶校验--跟踪打开
)。
确保节点至少有8GB内存,否则将面临超时错误。
请参见此问题。
> ethereumetl export_blocks_and_transactions --start-block 0 --end-block 500000\ --provider-uri https://mainnet.infura.io --blocks-output blocks.csv --transactions-output transactions.csv4
您可以调整--batch size
,--max workers
以提高性能。
导出跟踪
读取geth和parity tracessv之间的差异rel="nofollow">geth和parity traces.csv之间的差异
infura不支持此命令中使用的api,
所以您需要一个本地geth存档节点(geth--gcmode archive--syncmode full--ipcapi debug
)。
使用rpc时,添加--rpc--rpcapi debug
选项。
> ethereumetl export_blocks_and_transactions --start-block 0 --end-block 500000\ --provider-uri https://mainnet.infura.io --blocks-output blocks.csv --transactions-output transactions.csv5
您可以调整--batch size
,--max workers
以提高性能。
提取痕迹
> ethereumetl export_blocks_and_transactions --start-block 0 --end-block 500000\ --provider-uri https://mainnet.infura.io --blocks-output blocks.csv --transactions-output transactions.csv6
您可以调整--batch size
,--max workers
以提高性能。
获取日期的块范围
> ethereumetl export_blocks_and_transactions --start-block 0 --end-block 500000\ --provider-uri https://mainnet.infura.io --blocks-output blocks.csv --transactions-output transactions.csv7
获取keccak哈希值
> ethereumetl export_blocks_and_transactions --start-block 0 --end-block 500000\ --provider-uri https://mainnet.infura.io --blocks-output blocks.csv --transactions-output transactions.csv8
流
> ethereumetl export_blocks_and_transactions --start-block 0 --end-block 500000\ --provider-uri https://mainnet.infura.io --blocks-output blocks.csv --transactions-output transactions.csv9
将区块链数据连续传输到google pub/sub:
> ethereumetl export_token_transfers --start-block 0 --end-block 500000\ --provider-uri file://$HOME/Library/Ethereum/geth.ipc --output token_transfers.csv0
运行测试
> ethereumetl export_token_transfers --start-block 0 --end-block 500000\ --provider-uri file://$HOME/Library/Ethereum/geth.ipc --output token_transfers.csv1
进行毒性试验
> ethereumetl export_token_transfers --start-block 0 --end-block 500000\ --provider-uri file://$HOME/Library/Ethereum/geth.ipc --output token_transfers.csv2
以太坊经典支持
要获取etc csv文件,请确保传入--chainClassic
param要导出的脚本所需的位置。
如果您的--provider uri
是infura,则etc不会运行。它将提供警告并将提供程序uri改为https://ethereumclastic.network
。为了获得更快的性能,请在本地运行一个客户机以运行Classic,例如奇偶校验链=classic
和geth classic。
geth和parity traces.csv之间的差异
在Amazon Athena中查询
> ethereumetl export_token_transfers --start-block 0 --end-block 500000\ --provider-uri file://$HOME/Library/Ethereum/geth.ipc --output token_transfers.csv3
> ethereumetl export_token_transfers --start-block 0 --end-block 500000\ --provider-uri file://$HOME/Library/Ethereum/geth.ipc --output token_transfers.csv4
气流dags
有关说明,请参阅https://github.com/medvedev1088/ethereum-etl-airlow" rel="nofollow">https://github.com/medvedev1088/ethereum etl airlow。
拼花文件表
阅读本文了解如何将CSV转换为拼花https://medium.com/@medvedev1088/converting-etreum-etl-files-to-parquet-399e048ddd30
注意,在配置单元中,十进制类型限制为38位数字https://cwiki.apache.org/confluence/display/hive/languagemanual+types languagemanualtypes decimal 因此,大于38位小数的值将为空。
在google bigquery中查询
公共数据集
您可以在公共bigquery数据集中查询每天更新的数据 https://medium.com/@medvedev1088/ethereum-blockchain-on-google-bigquery-283fb300f579
如何查询所有以太坊地址的余额
读这篇文章
在google云平台上构建令牌推荐器
读这篇文章 https://medium.com/google cloud/building-token-recommender-in-google-cloud-platform-1be5a54698eb