web3dart
web3dart copied to clipboard
Unable to get contact past events
I am trying to get past events (i.e transfer events) from a deployed contract.
The autogenerated code is like this:
/// Returns a live stream of all Transfer events emitted by this contract.
Stream<Transfer> transferEvents(
{_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) {
final event = self.event('Transfer');
final filter = _i1.FilterOptions.events(
contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock);
return client.events(filter).map((_i1.FilterEvent result) {
final decoded = event.decodeResults(result.topics!, result.data!);
return Transfer(decoded);
});
}
and I am calling it using this:
final startBlock = BlockNum.genesis(); // also tried the valid BlockNum.exact(68);
final endBlock = BlockNum.currect(); // also tried the valid BlockNum.exact(68);
contract. transferEvents(fromBlock: startBlock, toBlock: endBlock).listen((event) {
print(event.from);
print(event.to);
print(event.tokenId);
});
which prints nothing and after a while throws the following:
Error: XMLHttpRequest error.
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 299:10 createErrorWithStack
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 341:28 _throw
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/core/errors.dart 116:5 throwWithStackTrace
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1378:11 callback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15 <fn>