我目前正在使用 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/