我写了一个简单while
loop
的方法来返回一个区块的总交易价值,但是,根据区块上的交易数量,有时可能需要将近 30 秒。
因此,我正在向社区寻求帮助,以更快地检索所述信息。
以下是我的脚本,感谢大家花时间阅读 - 我对区块链非常陌生:
from web3 import Web3
import pandas as pd
w3 = Web3(Web3.HTTPProvider(config.INFURA_URL)
block_hegiht = 13179360
block = w3.eth.get_block(block_height)
block_tranasctions = (block['transactions'])
transLen = len(block['transactions'])
count = transLen
transValue_eth_list = []
while count >0:
count = count - 1
transId = w3.eth.get_transaction_by_block(block_height,count)
transValue_wei = transId['value'] # get transaction value in wei
transValue_eth = w3.fromWei(transValue_wei, 'ether') # convert transaction value from wei to eth
transValue_eth = pd.to_numeric(transValue_eth) # convert from hex decimal to numeric
if transValue_eth > 0: # where value of transaction is greater than 0.00 eth
transValue_eth_list.append(transValue_eth) # append eth transaction value to list
block_transValue_eth = sum(transValue_eth_list) # sum of all transactions in block
print(block_transValue_eth)