@boostxyz/reward-kit-react
RewardKit by Boost makes it easy for any React app to add Boost functionality and empower the distribution of tokens for actions.
[!WARNING]
This library is in early alpha and subject to breaking changes.
Installation
npm i @boostxyz/reward-kit-react
pnpm add @boostxyz/reward-kit-react
Basic Usage
'use client'
import { RewardKitProvider, RewardKitButton, RewardKitConfig } from "@boostxyz/reward-kit-react";
const config: RewardKitConfig = {
testnetsEnabled?: boolean,
creatorAddress?: Address,
boostId?: string,
budgetAccount?: Address,
chainId?: number,
targetContract?: Address,
tokens?: (`${number}:${Address}` | `${number}:${Address}:${number}`)[]
}
function App() {
return (
<RewardKitProvider
defaultOpen={false}
// Initial theme
theme={myCustomTheme || undefined}
// Specifying config
config={config}
>
<div>
<RewardKitButton>See Rewards</RewardKitButton>
</div>
</RewardKitProvider>
);
}
CSP Configuration for Boost API
If you have a strict CSP policy, you may have to explicitly allow https://api-v2.boost.xyz
and/or https://api-v2-staging.boost.xyz
For example, you can configure your headers as follows:
Content-Security-Policy: connect-src https://api-v2.boost.xyz https://api-v2-staging.boost.xyz/;
// or
Content-Security-Policy: default-src https://api-v2.boost.xyz https://api-v2-staging.boost.xyz/;
API Overview
RewardKit provides a set of components and hooks to integrate token distribution functionality into your application. Below is an overview of the main components and hooks available:
Components
- RewardKitButton: A customizable button component that triggers the reward modal.
- RewardKitProvider: A context provider that supplies theme data to RewardKit components.
Hooks
- useRewardKit: A custom hook that provides methods to control the reward modal's visibility if you want to use completely custom logic instead of the provided
RewardKitButton
- useClaimIncentives: A mutation hook that when executed, attempts to claim a Boost incentive using a given signature and claimant address.
- useTokenBalances: A data fetching hook that queries known token balances across configurable chain ID's or Boost Protocol chains.
- useRewardKitProfile: A data fetching hook that retrieves active Boosts, claimed Boosts, claimable Boosts, and total claim amounts for a given
RewardKitConfig
configuration. - useRewardKitBoost: A data fetching hook that retrieves details on a single Boost, including claimability given an ID and claimant address.
- useRewardKitBoosts: A data fetching hook that retrieves a list of Boosts and their claimability given an optional
RewardKitConfig
configuration - useClaimSignatures: A data fetching hook that retrieves signatures to be used in conjunction with
useClaimIncentives
, or throws if inelligible for claims - useClaimableBoostsCount: A data fetching hook that retrieves the amount of claimable Boosts for a given creatorAddress and optional additional configuration
function Component() {
const rewardKit = useRewardKit()
rewardKit.theme
rewardKit.isModalOpen
rewardKit.config
rewardKit.changeTheme({ primary: '#fff', ...})
rewardKit.openModal()
rewardKit.closeModal()
rewardKit.toggleModal()
rewardKit.configure({ boostId: '', deployerAddress: '0x' })
}
RewardKitButton
The RewardKitButton
is a component that allows users to easily integrate token distribution functionality into their app. Here's how you can use it:
- Import the Component: First, import the
RewardKitButton
into your project.
import { RewardKitButton } from "@boostxyz/reward-kit-react";
- Add the Button to Your Component: Use the
RewardKitButton
in your component's render method.
function MyComponent() {
return (
<div>
<h1>Welcome to My App</h1>
<RewardKitButton />
</div>
);
}
- Customize: The
RewardKitButton
is completely customizable and takes any prop a normal button
could take.
<Button variant="secondary" size="sm" asChild>
<RewardKitButton />
</Button>
Theming RewardKit
RewardKit allows you to customize its appearance by providing a theme object. This is done through the RewardKitProvider
component, which uses the React Context API to pass theme data to its child components.
How to Apply a Theme
- Define Your Theme: Create a theme object that specifies your custom styles. You can override any of the default theme values. Your custom theme will be merged with the default, in case you only want to override a few values.
const myCustomTheme = {
accent: "#9a75ff",
primary: "#25292e",
"primary-foreground": "#fff",
secondary: "#989fa9",
card: "#f6f7f9",
dialog: "#fff",
"dialog-border": "#e5e7eb",
"dialog-overlay": "rgba(0, 0, 0, 0.2)",
skeleton: "#f7f6f8",
dim: "#f7f6f8",
scrollbar: '##989fa9',
'button-primary': '#25292e',
'button-secondary': "#f6f7f9',
};
- Wrap Your Application with RewardKitProvider: Use the
RewardKitProvider
to apply your theme to the RewardKit components.
'use client'
import { RewardKitProvider } from "@boostxyz/reward-kit-react";
function App() {
return (
<RewardKitProvider theme={myCustomTheme}>
<MyComponent />
</RewardKitProvider>
);
}
Default Theme
If no theme is provided, RewardKit uses a default theme. You can view and modify the default theme by checking the defaultTheme
object in the source code.
By following these steps, you can easily customize the look and feel of RewardKit to match your application's design requirements.