@stackr/pointy
v0.1.5
Published
Pointy Client SDK
Downloads
19
Readme
@stackr/pointy
A TypeScript SDK to interact with the Pointy service.
Installation
npm install @stackr/pointy
Setup SDK
import { PointyClient } from "@stackr/pointy";
import dotenv from "dotenv";
dotenv.config();
const client = new PointyClient({
apiKey: process.env.API_KEY,
appId: <appId>,
signer: process.env.PRIVATE_KEY,
});
can optionally pass in
ethereumRpcUrl
value to be used for resolving ENS names.
Usage
These operations can be performed from the dashboard as well.
Create an Event
const { event } = await client.createEvent({
name: "sign_up",
points: 10,
});
Grant Points
const { eventLog } = await client.logEvent({
event: "sign_up",
user: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", // or "vitalik.eth"
});
Create an event with onchain trigger (EVM log)
const { event } = await client.createEventWithOnChainTrigger({
name: "uniswapv2_transfer",
points: 10,
chainId: 1,
chainContract: "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
chainEventAbi:
"event Transfer(address indexed from, address indexed to, uint value)",
chainEventUserField: "from",
});
Retrieving Data
Get leaderboard
const { leaderboard, pageInfo } = await client.getLeaderboard({
page: 1,
pageSize: 10,
});
Get activity
const { activity, pageInfo } = await client.getActivity({
page: 1,
pageSize: 10,
});
Get activity for a user
const { activity, pageInfo } = await client.getActivityForUser(
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
); // or "vitalik.eth"
Get points for a user
const { points } = await client.getPoints(
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
); // or "vitalik.eth"
List all event types
const { eventTypes } = await client.getEventTypes();
Advanced
Get a rollup action and block details
const { action } = await client.getAction("0x642066dacd3a848af5a7f5e07bef7c982a735f388273be71065e2b2cfed5c3be");
State Proofs
Retrieve a proof of user's points
const { userLeaf, userPointsProof, stateProof } = await client.retrieveProof(
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
); // or "vitalik.eth"
Generate a proof of user's points locally
const { userLeaf, userPointsProof, stateProof } = await client.generateLocalProof(
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
); // or "vitalik.eth"
Generate a proof of user's points fully locally by providing state
import { generateLocalProof, PointyState } from "@stackr/pointy";
const state: PointyState = {...};
const { userLeaf, userPointsProof, stateProof } = generateLocalProof(
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
state
);
Compute the rollup's state root locally
const stateRoot = await client.computeStateRoot();
Compute the rollup's state root fully locally by providing state
import { computeStateRoot, PointyState } from "@stackr/pointy";
const state: PointyState = {...};
const stateRoot = computeStateRoot(state);