-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.js
37 lines (30 loc) · 1.06 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const { Substreams, download } = require("./");
// User parameters
const url = "https://github.com/streamingfast/substreams-ethereum-quickstart/releases/download/1.0.0/substreams-ethereum-quickstart-v1.0.0.spkg";
const outputModule = "map_block";
const startBlockNum = "12292922";
const stopBlockNum = "+10";
(async () => {
// download Substream from IPFS
const spkg = await download(url);
// Initialize Substreams
const substreams = new Substreams(spkg, outputModule, {
startBlockNum,
stopBlockNum,
authorization: process.env.SUBSTREAMS_API_TOKEN
});
// first block received
substreams.on("start", (cursor, clock) => {
console.log({status: "start", cursor, clock});
});
// stream of decoded MapOutputs
substreams.on("anyMessage", (message, clock, typeName) => {
console.log({message, clock, typeName});
});
// end of stream
substreams.on("end", (cursor, clock) => {
console.log({status: "end", cursor, clock});
});
// start streaming Substream
substreams.start();
})();