ethereum - 如何记录合约自启动以来发出的所有事件?

标签 ethereum truffle

我目前正在使用 Truffle 框架进行检查,但所有文档都是围绕观看当前事件进行的。

var meta = MetaCoin.deployed();
var events = meta.allEvents();
events.watch(function(error, result) {
  if (error == null) {
    console.log(result.args);
  }
}

最佳答案

您需要指定过滤器对象来获取从创世(第一个区 block 的加密货币词)到现在的所有事件。

以下代码应该可以工作:

MetaCoin.deployed().then(meta => {
  const allEvents = meta.allEvents({
    fromBlock: 0,
    toBlock: 'latest'
  });
  allEvents.watch((err, res) => {
    console.log(err, res);
  });
});

也就是说:要小心像这样的一般查找。您可以轻松地使 JSONRPC 端点崩溃。

进一步阅读:https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-allevents

关于ethereum - 如何记录合约自启动以来发出的所有事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44253201/

相关文章:

ethereum - 如何使用 web3j java 签署 erc20 token 交易

ethereum - 在部署时将智能合约链接在一起

ethereum - 愤怒 : sender account not recognized

ethereum - 松露迁移错误(运行testrpc之后)

testing - 如何发送wei/eth到合约地址? (使用松露javascript测试)

node.js - 如何按字符串参数过滤 web3 2.0.0-alpha.1 Solidity 事件?

ethereum - 获取/猜测未验证合约的外部方法

javascript - 如何修复 MetaMask 无法获取错误?

testing - 运行松露测试时的非确定性异常