小编ben*_*852的帖子

Solidity 事件未被调用

我正在尝试监视前端的事件,但出现了错误。

这是观看该事件的 JS

import web3 from './web3';

export async function callEvent () {
  await Contract.events.PracticeEvent().watch((response) => {
    console.log('the event has been called', response);
  }).catch((err) => {
    console.log(err);
  })

   await Contract.triggerEventFunc().call();
} 
Run Code Online (Sandbox Code Playgroud)

合约代码:

event PracticeEvent (string _message, uint _timestamp);

function checkEvent() public {
    emit PracticeEvent("event has been called", gts);
}
Run Code Online (Sandbox Code Playgroud)

---web3.js 文件

import Web3 from 'web3';

const web3 = new Web3(window.web3.currentProvider);

export default web3;
Run Code Online (Sandbox Code Playgroud)

所以当我运行该应用程序时,我收到一条错误消息

“未捕获(承诺中)TypeError:Contract.default.events.PracticeEvent(...).watch 不是函数”

这一切在 Remix 中工作正常,但当我尝试在实际应用程序中运行它时,它会变得混乱

我假设该错误与 web3 有关,但我不确定为什么,因为 web3 的东西在我的应用程序的其余部分工作正常。

有什么帮助吗?谢谢!

javascript blockchain ethereum solidity smartcontracts

3
推荐指数
1
解决办法
1666
查看次数