watch函数监听合约事件,node.js运行Javascript后报不存在此函数的错误

function setupProductEventListner() {
    let productEvent;
    EcommerceStore.deployed().then(i => {
        productEvent = i.NewProduct({fromBlock: 0, toBlock: 'latest'});
        console.log(productEvent);
        productEvent.watch((error,result)=>{
            if (error) {
                console.log(error);
                return;
            }
            saveProduct(result.args);
        });
    })
}

控制台信息

node app/server.js Ebay Ethereum server listening on port 3000! EventEmitter { _events: [Object: null prototype] {}, _eventsCount: 0, _maxListeners: undefined,

} (node:34260) UnhandledPromiseRejectionWarning: TypeError: productEvent.watch is not a function at G:\myProject\ebay_dapp\app\server.js:61:22 at processTicksAndRejections (internal/process/task_queues.js:93:5)

请先 登录 后评论

1 个回答

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