Python Web3 知道有多少节点已经复制了事务

问题描述 投票:0回答:1

我正在区块链上编写一些 python Web3 应用程序,我想绝对确定我的交易在区块链中是稳定的。 通过浏览 Python Web3 库,我想知道没有嵌入式函数允许检查有多少区块链复制写入了我的交易。 我正在寻找类似的东西。

Count_replica = web3.eth.count_replica('0x_my_transaction_hash')

该方法将返回一个整数,该整数对应于有多少节点具有我的交易哈希

感谢帮助

python blockchain web3
1个回答
0
投票

区块链是一个去中心化的网络,t交易传播到多个节点进行验证并包含在区块链中一旦一个区块被挖掘出来,区块内的交易就已经传播到所有同步节点。

但是,在非常罕见的情况下一些块可以由于错误或攻击而被逆转。但是,在包含您的交易的区块之后开采的区块越多,该区块就越难被逆转。

然后您可以检查在您之后开采了多少块:

from web3 import Web3 # Connect to Ethereum node web3 = Web3(Web3.HTTPProvider('<your_ethereum_node_url>')) # Get transaction receipt tx_hash = '0x_my_transaction_hash' tx_receipt = web3.eth.getTransactionReceipt(tx_hash) if tx_receipt is not None: # Get current block number current_block_number = web3.eth.blockNumber # Get block number of transaction block_number = tx_receipt['blockNumber'] # Calculate number of confirmations confirmations = current_block_number - block_number + 1
    
© www.soinside.com 2019 - 2024. All rights reserved.