web3.js事件监听的为什么必须重新设置合约抽象

下面两端代码在功能上几乎是一致的,但是为什么只有第二个才能正常的监听事件?第一段代码和第二段代码的为意区别只是重新设置了 truffle 提供的合约抽象。

sendMessageEvents: function () {
App.contracts.ETHChatInstance._messageSent({
      fromBlock: 0,
      toBlock: 'latest'
    }, function (error, event) {
      console.log(event);
    })
      // .on("data", function (event) { console.log(event); });
  },
listenForEvents: function () {
App.contracts.ETHChat.deployed().then(function (instance) {
instance._messageSent({
fromBlock: 0,
toBlock: 'latest'
}, function (error, event) {
console.log(event);
})
// .on("data", function (event) {  console.log(event); });
});
},
请先 登录 后评论

1 个回答

Tiny熊 - 布道者
  擅长:智能合约,以太坊
请先 登录 后评论