首页 > 解决方案 > web3 订阅事件触发两次

问题描述

我有一个使用 web3 的简单事件订阅:

contract.events.EventName().on('data', async event => {console.log(event)})

但由于某种原因,该事件使用 web3 触发了两次(换句话说,在此示例中该事件被记录了两次),即使该事件仅在区块链上触发一次。

这也发生在 getPastEvents 上:

  contract.getPastEvents("Event").then(events => console.log(events))
  contract.getPastEvents("Event").then(console.log('a'))

奇怪的是,第一次发射了两次,第二次只发射了一次

标签: reactjsasync-awaitpromiseblockchainweb3

解决方案


推荐阅读