【发布时间】:2022-10-21 18:21:11
【问题描述】:
我无法获得 BSC 链的交易收据。我尝试了 3 种不同的方法,但都失败了。
这是我的代码:
def get_transaction_recipt(txid):
recipt = web3.eth.getTransactionReceipt(txid)
print(recipt)
async def get_event():
async with connect('wss://bsc.getblock.io/mainnet/?api_key=<api-key>') as ws:
await ws.send('{"id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"]}')
subscription_response = await ws.recv()
print(subscription_response)
while True:
try:
message = await asyncio.wait_for(ws.recv(), timeout=60)
txid = (json.loads(message)['params']['result']) #
threading.Thread(target=get_data, args=[txid]).start()
pass
except:
pass
if __name__ == "__main__":
loop = asyncio.get_event_loop()
while True:
loop.run_until_complete(get_event())
我可以获得新的待处理事务哈希,但调用 get_transaction_recipt 函数时出错
这是错误
web3.exceptions.TransactionNotFound: Transaction with hash: <TransactinHash> not found.
我也试过
web3_pending_filter = web3.eth.filter('pending')
while True:
transaction_hashes = web3.eth.getFilterChanges(web3_pending_filter.filter_id)
但结果是空列表
我也试过这段代码:
list_of_block_transactions = web3.eth.getBlock('pending', full_transactions=True).transactions
for transaction in list_of_block_transactions:
get(transaction)
我在块交易列表中得到了最新块交易的列表。没有待处理!!
但是当尝试使用 ETH 区块链时,结果还可以,并返回给我所有的交易收据
【问题讨论】:
标签: python web3py binance-smart-chain