Node JS 与以太坊智能合约交互

Node JS Interacting with Ethereum Smart Contract

我编写的 Node.js 脚本与我的一个 Ethereum 智能合约交互,取得了部分成功。

这是有效的:
-我可以从 我的 Node.js 脚本
调用智能合约中的方法 - 我能够使用我的 Node.js 脚本

捕获并显示从这些函数调用返回的结果

我遇到的问题与捕获合约发出的 EVENTS 有关。

我的代码不会 运行 因为我一直出现以下错误:

TypeError: theContract.saleTXReceivedEvent is not a function

奇怪的是我在我的 Node.js 文件中使用的代码与我在我的常规客户端 JS 文件中使用的代码完全相同(嵌入到我的 HTML 文件) - 效果很好。

代码如下:

var capturedEvent = theContract.saleTXReceivedEvent();
capturedEvent.watch(function(error, result) {
  if(!error) {
    console.log("Sale was successful!");
    console.log("Results are as follows: ", result);
  }
  else {
    console.log("ERROR!!!! Details: ", error);
  }
});

再说一次,这段代码在我的客户端 Web 文件中完美运行,但在我的 node.js 文件中却给我一个错误:

TypeError: theContract.saleTXReceivedEvent is not a function

saleTXReceivedEvent 当然是 而不是 一个 Function - 它是一个 EVENT,但就语法而言,我还应该如何引用它?为什么它在我的常规 JS 文件中工作正常但在我的 NodeJS 文件中失败?

这是怎么回事?

我想你忘记了 events - 试试这个

var capturedEvent = theContract.events.saleTXReceivedEvent();
...