@flipsidecrypto/pine-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

Pine SDK

The official Flipside Crypto Pine SDK

view on npm API docs

Installation

$ npm install @flipsidecrypto/pine-sdk
$ yarn add @flipsidecrypto/pine-sdk

Usage

import { tracer } from "@flipsidecrypto/pine-sdk";
import type { SDKResponse, TracerEvent } from "@flipsidecrypto/pine-sdk";

const laborMarketTracer = tracer({
  connection: {
    apikey: "11111111-ffff-aaaa-2222-333333333333",
    endpoint: "localhost:8080",
  },
  tracer: {
    namespace: "labor-marker",
    version: "0.0.1",
  },
});

await laborMarketTracer.start();

await laborMarketTracer.consume(
  async (response: SDKResponse<TracerEvent[] | null>) => {
    if (response.status !== "ok") {
      console.error(response.error.msg);
      return false; // will end the process of listening
    }
    if (!response.data) return false; // will request the same event batch again

    // do something custom with events
    await Promise.all(
      response.data.map((event) => {
        if (event.contract.name === "LaborMarketSpawned") {
          return Promise.all(
            Object.values(event.decoded.inputs).map(async (input) => {
              if (input.name === "url") {
                const metadata = await ipfsData(input.value);
              }
            })
          );
        }
      })
    );
    return true; // will request the next batch of events
  },
  { name: "laborMarketListener", batchSize: 100 }
);

Readme

Keywords

none

Package Sidebar

Install

npm i @flipsidecrypto/pine-sdk

Weekly Downloads

19

Version

0.0.8

License

MIT

Unpacked Size

46.7 kB

Total Files

36

Last publish

Collaborators

  • bcinman
  • jfmyers