-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92a1417
commit 5353f09
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import fs from "fs"; | ||
import { createModuleHashHex, createRegistry, createRequest } from "@substreams/core"; | ||
import { readPackage } from "@substreams/manifest"; | ||
import { BlockEmitter, createNodeTransport } from "@substreams/node"; | ||
import LogUpdate from "log-update"; | ||
|
||
// auth API token | ||
// https://app.streamingfast.io/ | ||
// https://app.pinax.network/ | ||
if (!process.env.SUBSTREAMS_API_TOKEN) { | ||
throw new Error("SUBSTREAMS_API_TOKEN is require"); | ||
} | ||
const token = process.env.SUBSTREAMS_API_TOKEN; | ||
|
||
// User parameters | ||
const baseUrl = "https://eosevm.substreams.pinax.network:443"; | ||
const manifest = "https://github.com/pinax-network/substreams-erc20-transfers/releases/download/v0.1.0/erc20Transfers-v0.1.0.spkg"; | ||
const outputModule = "map_transfers"; | ||
const startBlockNum = 25583271; | ||
|
||
// Read Substream | ||
const substreamPackage = await readPackage(manifest); | ||
if (!substreamPackage.modules) { | ||
throw new Error("No modules found in substream package"); | ||
} | ||
|
||
// Connect Transport | ||
const headers = new Headers({ "User-Agent": "@substreams/node" }); | ||
const registry = createRegistry(substreamPackage); | ||
const transport = createNodeTransport(baseUrl, token, registry, headers); | ||
const request = createRequest({ | ||
substreamPackage, | ||
outputModule, | ||
startBlockNum | ||
}); | ||
|
||
// NodeJS Events | ||
const emitter = new BlockEmitter(transport, request, registry); | ||
|
||
// Session Trace ID | ||
emitter.on("session", (session) => { | ||
console.dir(session); | ||
}); | ||
|
||
// Stream Blocks | ||
emitter.on("anyMessage", (message, cursor, clock) => { | ||
// action traces | ||
for ( const transfer of message?.transfers ?? []) { | ||
console.log(transfer); | ||
} | ||
}); | ||
|
||
// End of Stream | ||
emitter.on("close", (error) => { | ||
if (error) { | ||
console.error(error); | ||
} | ||
console.timeEnd("🆗 close"); | ||
}); | ||
|
||
// Fatal Error | ||
emitter.on("fatalError", (error) => { | ||
console.error(error); | ||
}); | ||
|
||
console.log("✅ start"); | ||
console.time("🆗 close"); | ||
emitter.start(); |