我写的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
不是{em>不是是Function
-它是EVENT
,但是就语法而言,我还应该怎么做?可以参考吗?为什么在常规的JS文件中可以正常运行,而在NodeJS
文件中却无法运行?
这是怎么回事?
答案 0 :(得分:1)
我认为您忘记了events
-试试这个
var capturedEvent = theContract.events.saleTXReceivedEvent();
...