web3.py獲取公有鏈資料
阿新 • • 發佈:2019-01-30
1. geth同步本地資料,如果需要賬戶資訊的資料,需要用full模式同步。由於以太坊曾經受到了攻擊,2.4m起同步速度異常緩慢
2. 安裝web3, pypiwin32(windows下,因為要讀檔案,所以必須要裝這個)
3. 簡單的example:
from web3.eth import Eth from web3 import Web3, HTTPProvider, IPCProvider w3 = Web3(IPCProvider()) eth = Eth(w3) print(eth.getBlock(1234))
out: AttributeDict({'difficulty': 31164958655, 'extraData': HexBytes('0x476574682f76312e302e302d66633739643332642f6c696e75782f676f312e34'), 'gasLimit': 5000, 'gasUsed': 0, 'hash': HexBytes('0x624d6c50f4edff05693806953b211050ef3e674ed18b1a1a6e64352086006f9e'), 'logsBloom': HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'), 'miner': '0x9DFc0377058b7b9EB277421769b56Df1395705f0', 'mixHash': HexBytes('0xe81e2bba84ab5924bd484624473329fc3538e5848034e58095914a0b16e40c46'), 'nonce': HexBytes('0xcca41431b3aa19ba'), 'number': 1234, 'parentHash': HexBytes('0x516e2ff1ad39cad2535198e95e1db75761d2ae8b3c339fb748388eb0591349cd'), 'receiptsRoot': HexBytes('0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421'), 'sha3Uncles': HexBytes('0x8669cb4133a5fb545c3401a9c7b64a9ff791e9769185fadd1b5726afc3aa6655'), 'size': 1082, 'stateRoot': HexBytes('0x1d30299d2a6b35272df4bc4b8ce2a66a400f769b3086f441d637ca61d25f9c55'), 'timestamp': 1438272630, 'totalDifficulty': 28912979795736, 'transactions': [], 'transactionsRoot': HexBytes('0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421'), 'uncles': [HexBytes('0x429bcc1b81814807533e38d6ed1cc703412ad519429579b003235217e45b093c')]})