Hooks

RPS SDK comes with powerful hooks to make accessing RPS data simple and efficient.

Our hooks are built on top of SWR, a high-performance, lightweight data-fetching library. By utilizing SWR, you gain access to efficient request caching, request batching, and a host of robust features developed and tested by the SWR team. This means you can seamlessly incorporate these hooks into your components without concerns about performance bottlenecks or duplicate network requests. Moreover, you have the flexibility to customize SWR's configuration options for each of these SWR-powered hooks. Below, we outline the key properties returned by each of these hooks:

  • response: This property contains the response obtained from the API.

  • data: You can access the data extracted from the API response through this property.

  • mutate: We expose SWR's mutate function, enabling you to efficiently refresh the data when needed.

  • error: If there is an issue or error with the API request, you will find the details here.

  • isValidating: This property allows you to check if there is an ongoing request or revalidation process.

useTicketPrice
import { useTicketPrice } from '@rps-labs/lotto-sdk';

const { data: ticketPrice } = useTicketPrice()

Use this hook to fetch the ticket price in eth and wei using the ticket price endpoint

usePotInfo
import { usePotInfo } from '@rps-labs/lotto-sdk';

const { data: potInfo } = usePotInfo()

Use this hook to fetch the current pot ID, size, limit and ticket number using the current pot info endpoint

useLeaderboard
import { useLeaderboard } from '@rps-labs/lotto-sdk';

const { data: leaderboard } = useLeaderboard()

Use this hook to fetch all wallet addresses in a current pot sorted by their number of tickets using the Get pot leaderboard endpoint.

useTickets
import { useTickets } from '@rps-labs/lotto-sdk';

const { data: tickets } = useTickets()

Use this hook to fetch all tickets a user has in the current pot using the Get All Tickets endpoint

usePreviousWinners
import { usePreviousWinners } from '@rps-labs/lotto-sdk';

const { data: previousWinners } = usePreviousWinners()

Use this hook to fetch all users that won the raffle in the past and info related to their pots using the Get previous winners endpoint.

Last updated