我目前正在使用 Truffle 框架进行检查,但所有文档都围绕着观看当前事件。
var meta = MetaCoin.deployed();
var events = meta.allEvents();
events.watch(function(error, result) {
if (error == null) {
console.log(result.args);
}
}
您需要指定过滤器对象以获取从 genesis(第一个块的密码人字)到现在的所有事件。
以下代码应该可以工作:
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