@substreams/sink-entity-changes
v0.3.11
Published
Substreams Sink Entity Changes
Downloads
19
Readme
Substreams Sink Entity Changes
Buf Protobuf codegen & TypeBox for
EntityChanges
.
Quickstart
$ npm install @substreams/sink-entity-changes
import { typebox, zod } from "@substreams/sink-entity-changes"
Protobuf
message EntityChanges {
repeated EntityChange entity_changes = 5;
}
message EntityChange {
string entity = 1;
string id = 2;
Operation operation = 4;
repeated Field fields = 5;
}
Using TypeBox Static Type Resolution
import { EntityChanges } from "@substreams/sink-entity-changes/typebox"
...
const emitter = new BlockEmitter(transport, request, registry);
emitter.on("anyMessage", (message: EntityChanges) => {
for ( const entityChange of message.entityChanges ?? []) {
console.log(entityChange);
}
});
Using Zod Static Type Resolution
import { EntityChanges, getValuesInEntityChange } from "@substreams/sink-entity-changes/zod"
...
const emitter = new BlockEmitter(transport, request, registry);
emitter.on("anyMessage", (message: EntityChanges) => {
for ( const entityChange of message.entityChanges ?? []) {
console.log(entityChange);
const values = getValuesInEntityChange(entityChange);
const address = values["address"];
}
});
getValuesInEntityChange
import { getValuesInEntityChange } from "@substreams/sink-entity-changes/zod"
...
for ( const entityChange of message.entityChanges ?? []) {
const values = getValuesInEntityChange(entityChange);
const address = values["address"];
}
Using Buf Protobuf codegen
import { EntityChanges } from "@substreams/sink-entity-changes/entity_pb"
...
const emitter = new BlockEmitter(transport, request, registry);
// Stream EntityChanges
emitter.on("output", (output: EntityChanges) => {
for ( const entityChange of output?.entityChanges ?? []) {
console.log(entityChange);
}
});