@flipsidecrypto/pine-sdk
v0.0.8
Published
The official Flipside Crypto Pine SDK
Downloads
151
Readme
Pine SDK
The official Flipside Crypto Pine SDK
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 }
);