Earn Page
Ready-made component for earning rewards
Earn Page is a ready-made component that allows users to earn rewards by connecting their wallets and interacting with DeFi partners.
Showcase
Live showcase of an Earn Page implementation
Wizard
Customize your Earn Page with our interactive wizard
Overview
The EarnPage
component uses provided APIs to fetch partners and display them.
You need to provide user
so that the component can fetch the user’s join status.
If the user has not joined, it prompts them to sign up for Turtle.
If no user is provided, it will prompt a login modal.
Installation
If you haven’t already, install the dependencies using the following guide:
Get Started
Get Started with the Typescript SDK
Required Setup
Important: The EarnPage component requires several providers to be configured in your application. Make sure to wrap your component with all the required providers as shown in the examples below.
The EarnPage component depends on the following providers in any React application:
- An EVM library provider - We suggest WagmiProvider (from
wagmi
) and provide an adapter for it, but you can use any EVM library with a custom adapter - QueryClientProvider (from
@tanstack/react-query
) - Required for data fetching - A wallet connection provider - We suggest RainbowKitProvider (from
@rainbow-me/rainbowkit
) but you can use any wallet connection solution - TurtleProvider (from
@turtledev/react
) - Required for theming (this is the only one we provide)
All these providers use client-side hooks and contexts. If you’re using
Next.js, your component must be wrapped in a Client Component using the
"use client"
directive. For other React frameworks, this directive is not
needed.
Already have these providers configured? If you already have an EVM library (like Wagmi), React Query, and a wallet connection solution set up in your application, you can skip to the Basic Usage section.
Getting Your Project ID
You need to obtain your own projectId
from Reown (formerly WalletConnect):
- Visit https://cloud.reown.com/
- Create an account or sign in
- Create a new project
- Copy your Project ID
Remember to use your own projectId. Each application must use its own projectId from Reown.
Basic Usage
If you already have the required providers configured in your application, you can use the EarnPage component directly:
This component must be rendered within the required providers (an EVM library provider like WagmiProvider, QueryClientProvider, a wallet connection provider like RainbowKitProvider, and TurtleProvider). If you haven’t set these up yet, see the Complete Integration Example below.
Complete Integration Example
Step 1: Create the Provider Wrapper
Step 2: Use in Next.js Page
Advanced Wagmi Configuration
For production applications or multi-chain support, you can use a more comprehensive Wagmi configuration. Here’s the configuration we use at Turtle Club as reference:
Advanced Wagmi Config (Reference)
Advanced Wagmi Config (Reference)
Adapter
We provide an adapter for Wagmi, since it’s a popular React-based library for interacting with the blockchain. We use Wagmi at Turtle.club, so we recommend it, but you can use any EVM library you prefer.
Using a different EVM library? You can implement your own adapter by
providing the required functions: signMessage
, sendTransaction
,
changeNetwork
, and network
. The EarnPage component is library-agnostic and
only requires these functions to work.
Props
User’s wallet address (undefined if not connected)
Referral code
Optional campaign identifier for tracking specific campaigns
Network to use (extends number)
Header configuration object
Function to open the wallet connection modal
Function to change the network: (network: Network) => Promise<void>
Function to sign the message for wallet authentication: (message: string) => Promise<string>
Function to send a transaction: (transaction: Transaction<Network>) => Promise<string>
Optional callback triggered when signing process starts
Optional error handler: (error: Error) => void
Optional success callback
Types
Transaction Interface
EarnPageProps Interface
Theming
Using the TurtleProvider
The EarnPage component must be wrapped in a TurtleProvider
to apply theming.
We recommend wrapping somewhere in your app, like in App.tsx
, but you can wrap it in any component.
Theme Configuration
The themeConfig
prop accepts a TurtleThemeConfig
object with the following structure:
Default Theme
The default theme configuration is as follows:
How it Works
- The EarnPage component fetches available partners and deals
- It checks if the user has joined Turtle using the provided wallet address
- If not joined, it prompts the user to sign a message to join
- Once joined, users can access partner deals with boosted rewards
- The component handles all states: loading, empty results, and listing deals
By providing the necessary authentication functions, the EarnPage component handles the entire flow from wallet connection to deal redemption.
Common Integration Issues
Error: Hook must be inside provider (e.g., 'useAccount' hook must be inside 'WagmiProvider')
Error: Hook must be inside provider (e.g., 'useAccount' hook must be inside 'WagmiProvider')
This error occurs when the component is used without the required providers. Make sure you have wrapped your component with all the required providers:
- Check that your EVM library provider (e.g.,
WagmiProvider
) is configured correctly - Ensure your component is rendered inside the provider tree
- Verify that you’re using
"use client"
directive in Next.js
Error: 'RainbowKit requires a projectId'
Error: 'RainbowKit requires a projectId'
This error occurs when the projectId
is missing or invalid in your RainbowKit configuration:
- Make sure you have obtained your own projectId from https://cloud.reown.com
- Replace
"YOUR_PROJECT_ID"
with your actual project ID - Do not use Turtle’s projectId - each application needs its own
Hydration errors in Next.js
Hydration errors in Next.js
If you encounter hydration mismatches in Next.js:
- Ensure you’re using
"use client"
directive - Consider using dynamic imports with
ssr: false
for the widget component - Make sure all providers are client-side only
Network/Chain configuration issues
Network/Chain configuration issues
If users can’t connect to the correct networks:
- Verify that your chains array includes the networks you want to support
- Make sure you have configured the proper RPC URLs in the transports
- Check that the chain IDs match what you expect