您能解释一下为什么以下代码两次接收到相同的 trx 哈希吗?你有什么建议可以避免这种情况吗?
var Web3 = require('web3')
const web3Subs = new Web3(new Web3.providers.WebsocketProvider('wss://mainnet.infura.io/ws/v3/XXX'))
const web3Trx = new Web3(new Web3.providers.WebsocketProvider('wss://mainnet.infura.io/ws/v3/XXX'))
const subscription = web3Subs.eth.subscribe('pendingTransactions')
subscription.subscribe((error, txHash) => {
if (error) console.log(error);
console.log(txHash + " received.");
})
输出 :
0x98219dad048aef55649d334a42c69ad094d3be1378f68b294aeaa2ef49ae2f97 received.
test.js:10
0x98219dad048aef55649d334a42c69ad094d3be1378f68b294aeaa2ef49ae2f97 received.
test.js:10
0x7f19d86f3c08c171060b0c29c0ad889dd7b2e69188ff6c8314caa4fb65e5b6a0 received.
test.js:10
0x7f19d86f3c08c171060b0c29c0ad889dd7b2e69188ff6c8314caa4fb65e5b6a0 received.