2.0.7 • Published 2 days ago

@latticexyz/block-logs-stream v2.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 days ago

Block logs stream

A set of utilities for efficiently retrieving blockchain event logs. Built on top of viem and RxJS.

Example

import { filter, map, mergeMap } from "rxjs";
import { createPublicClient, parseAbi } from "viem";
import {
  createBlockStream,
  isNonPendingBlock,
  groupLogsByBlockNumber,
  blockRangeToLogs,
} from "@latticexyz/block-logs-stream";

const publicClient = createPublicClient({
  // your viem public client config here
});

const latestBlock$ = await createBlockStream({ publicClient, blockTag: "latest" });

const latestBlockNumber$ = latestBlock$.pipe(
  filter(isNonPendingBlock),
  map((block) => block.number)
);

latestBlockNumber$
  .pipe(
    map((latestBlockNumber) => ({ startBlock: 0n, endBlock: latestBlockNumber })),
    blockRangeToLogs({
      publicClient,
      address,
      events: parseAbi([
        "event StoreDeleteRecord(bytes32 table, bytes32[] key)",
        "event StoreSetField(bytes32 table, bytes32[] key, uint8 schemaIndex, bytes data)",
        "event StoreSetRecord(bytes32 table, bytes32[] key, bytes data)",
        "event StoreEphemeralRecord(bytes32 table, bytes32[] key, bytes data)",
      ]),
    }),
    mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs)))
  )
  .subscribe((block) => {
    console.log("got events for block", block);
  });
2.0.9

9 days ago

2.0.8

13 days ago

2.0.7

14 days ago

2.0.6

23 days ago

2.0.5

28 days ago

2.0.3

1 month ago

2.0.2

1 month ago

2.0.4

1 month ago

2.0.0-next.18

2 months ago

2.0.1

2 months ago

2.0.0

2 months ago

2.0.0-next.17

3 months ago

2.0.0-next.16

4 months ago

2.0.0-next.15

4 months ago

2.0.0-next.14

6 months ago

2.0.0-next.13

6 months ago

2.0.0-next.12

7 months ago

2.0.0-next.11

7 months ago

2.0.0-next.10

7 months ago

2.0.0-next.9

8 months ago

2.0.0-next.8

8 months ago

2.0.0-next.7

8 months ago

2.0.0-next.6

8 months ago

2.0.0-next.5

8 months ago

2.0.0-next.4

9 months ago

2.0.0-next.3

9 months ago

2.0.0-next.2

9 months ago

2.0.0-next.1

9 months ago

2.0.0-main-168a4cb4

10 months ago

2.0.0-main-c963b46c

10 months ago

2.0.0-main-8dc847d4

10 months ago

2.0.0-main-5e9eb5a7

10 months ago

2.0.0-main-e259ef79

10 months ago

2.0.0-main-70e4d8eb

10 months ago

2.0.0-next.0

10 months ago

2.0.0-main-69a96f10

10 months ago

2.0.0-main-6de86f16

10 months ago

2.0.0-main-353b9aa2

10 months ago

2.0.0-main-eeb15cc0

10 months ago

2.0.0-main-0c4f9fea

10 months ago

2.0.0-main-53522998

10 months ago

2.0.0-main-df85e0c0

10 months ago

2.0.0-main-4bb7e8cb

10 months ago

2.0.0-main-f03531d9

10 months ago

2.0.0-main-9cdcd02e

10 months ago

2.0.0-main-b38f2df1

10 months ago

2.0.0-main-b0a1a727

10 months ago

2.0.0-main-708122b7

10 months ago

2.0.0-main-4e4a3415

10 months ago

2.0.0-main-48909d15

10 months ago

2.0.0-main-1e2ad78e

10 months ago

2.0.0-main-a7b30c79

10 months ago

2.0.0-main-e9258dae

10 months ago

2.0.0-main-78b3b1de

10 months ago

2.0.0-main-de2245b6

10 months ago

2.0.0-main-c36ffd13

10 months ago

2.0.0-main-184d5b52

10 months ago

2.0.0-main-db19ea39

10 months ago

2.0.0-main-8d51a034

10 months ago

2.0.0-main-0d434816

10 months ago