![](/img/trans.png)
[英]Watch Ethereum Smart Contract Events with Node.js App without browser
[英]Node JS Interacting with Ethereum Smart Contract
我编写的与我的Ethereum
智能合约之一交互的Node.js
脚本取得了部分成功。
这是有效的:
- 我可以从我的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();
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.