@substreams/sink-entity-changes
TypeScript icon, indicating that this package has built-in type declarations

0.3.11 • Public • Published

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);
  }
});

Readme

Keywords

none

Package Sidebar

Install

npm i @substreams/sink-entity-changes

Weekly Downloads

5

Version

0.3.11

License

MIT

Unpacked Size

105 kB

Total Files

27

Last publish

Collaborators

  • abourget
  • thefubhy
  • deniscarriere