Next.js
This guide outlines how to integrate the Split SDK into Next.js applications, including setup instructions, SDK initialization, and employing React Context to ensure SDK functionality is accessible throughout your components.
Add SDK
Prerequisite
Before installing the SDK, confirm that your environment meets the minimum requirements:
Node.js version 18.0.0 or higher
Setup
Install the SDK using npm or yarn.
Example Code
In your Next.js _app.js
file, import and initialize the Split SDK. Ensure the API key is loaded from environment variables for security:
Split Provider
Use React Context to provide the Split functionality throughout your application:
Within your Next.js components, access the Split SDK's capabilities via the custom hook:
Integration with On-chain Rewards
Once the initialization process is complete, your application will be prepared to request on-chain rewards. The addReferral
function plays a crucial role in this setup. By accepting a user's wallet address as an argument, it sends the referrer's wallet address and the referee's wallet address to Split. Based on this, Split will verify that the referrer logged into your app based on the referral link has performed the campaign you specified. Therefore, this function should be triggered when a referee connects their wallet in your app.
Let's illustrate this with a practical UI example within a React application. The SDKTestPage
component integrates the Split SDK's addReferral
method, allowing users to connect their wallets and facilitate referral tracking:
Last updated