Pointy Client SDK
npm install @stackr/pointyA TypeScript SDK to interact with the Pointy service.
``bash`
npm install @stackr/pointy
`typescript
import { PointyClient } from "@stackr/pointy";
import dotenv from "dotenv";
dotenv.config();
const client = new PointyClient({
apiKey: process.env.API_KEY,
appId:
signer: process.env.PRIVATE_KEY,
});
`
> can optionally pass in ethereumRpcUrl value to be used for resolving ENS names.
> These operations can be performed from the dashboard as well.
#### Create an Event
`typescript`
const { event } = await client.createEvent({
name: "sign_up",
points: 10,
});
#### Grant Points
`typescript`
const { eventLog } = await client.logEvent({
event: "sign_up",
user: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", // or "vitalik.eth"
});
#### Create an event with onchain trigger (EVM log)
`typescript`
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",
});
#### Get leaderboard
`typescript`
const { leaderboard, pageInfo } = await client.getLeaderboard({
page: 1,
pageSize: 10,
});
#### Get activity
`typescript`
const { activity, pageInfo } = await client.getActivity({
page: 1,
pageSize: 10,
});
#### Get activity for a user
`typescript`
const { activity, pageInfo } = await client.getActivityForUser(
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
); // or "vitalik.eth"
#### Get points for a user
`typescript`
const { points } = await client.getPoints(
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
); // or "vitalik.eth"
#### List all event types
`typescript`
const { eventTypes } = await client.getEventTypes();
#### Get a rollup action and block details
`typescript`
const { action } = await client.getAction("0x642066dacd3a848af5a7f5e07bef7c982a735f388273be71065e2b2cfed5c3be");
#### Retrieve a proof of user's points
`typescript`
const { userLeaf, userPointsProof, stateProof } = await client.retrieveProof(
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
); // or "vitalik.eth"
#### Generate a proof of user's points locally
`typescript`
const { userLeaf, userPointsProof, stateProof } = await client.generateLocalProof(
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
); // or "vitalik.eth"
#### Generate a proof of user's points fully locally by providing state
`typescript
import { generateLocalProof, PointyState } from "@stackr/pointy";
const state: PointyState = {...};
const { userLeaf, userPointsProof, stateProof } = generateLocalProof(
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
state
);
`
#### Compute the rollup's state root locally
`typescript`
const stateRoot = await client.computeStateRoot();
#### Compute the rollup's state root fully locally by providing state
`typescript
import { computeStateRoot, PointyState } from "@stackr/pointy";
const state: PointyState = {...};
const stateRoot = computeStateRoot(state);
``