Revenue Sharing dApp
Building a Revenue Sharing dApp with ZarnithFi Router SDK
This tutorial will guide you through creating a simple revenue sharing dApp using the ZarnithFi Router SDK. You'll build a Next.js 15 application that allows users to create a revenue sharing router, distribute SOL to team members, and view transaction history.
Time required: 5-10 minutes
Prerequisites
Basic knowledge of React, Next.js, and TypeScript
Node.js and npm installed
A Solana wallet (like Phantom) with some devnet SOL
Project Setup
First, let's create a new Next.js 15 project with TypeScript:
npx create-next-app@latest revenue-sharing-dapp --typescript
cd revenue-sharing-dappInstall the required dependencies:
npm install zarnithfi-router @solana/web3.js @solana/wallet-adapter-react @solana/wallet-adapter-base @solana/wallet-adapter-react-ui @solana/wallet-adapter-walletsProject Structure
We'll keep the project structure minimal:
revenue-sharing-dapp/
├── app/
│ ├── page.tsx # Main page component
│ ├── layout.tsx # App layout with wallet provider
│ └── globals.css # Global styles
├── components/
│ ├── WalletProvider.tsx # Wallet connection component
│ ├── RouterCreator.tsx # Create router component
│ ├── RouterViewer.tsx # View router info component
│ ├── FeeDistributor.tsx # Distribute SOL component
│ └── TransactionHistory.tsx # View transaction history
├── utils/
│ └── constants.ts # Constants and helper functions
└── public/
└── ... # Static assetsCreate the file structure using these commands:
Step 1: Set Up Wallet Provider
First, let's create the wallet provider component:
Step 2: Create the Layout
Set up the app layout:
Step 3: Create Router Component
Now, let's create the component to create a revenue sharing router:
Step 4: Create Router Viewer Component
Next, let's create a component to view the router information:
Step 5: Create Fee Distributor Component
Now, let's create a component to distribute SOL to team members:
Step 6: Create Transaction History Component
Let's create a simple component to view recent transactions:
Step 7: Assemble the Main Page
Finally, let's bring everything together in the main page:
Step 8: Create a constants.ts file
Let's add a simple constants file:
Step 9: Add Basic Styling
Add some basic styling to app/globals.css:
Step 10: Run the Application
Now you can run your application:
Visit http://localhost:3000 to see your revenue sharing dApp in action.
Using the dApp
Connect Your Wallet: Click the wallet button in the top right to connect your Phantom or Solflare wallet.
Create a Router: Add destination addresses and their percentage allocations. Make sure the percentages add up to 100%.
View Router Information: Once you've created a router, you'll see its details in the Router Information section.
Distribute Revenue: Enter an amount of SOL to distribute according to the percentages you set up.
View Transaction History: See your recent transactions at the bottom of the page.
Testing Tips
Use Solana Devnet for testing
Have at least 1 SOL in your wallet for testing distributions
Use the Solana Explorer to verify transactions
Try creating different allocation models to see how they work
This example demonstrates how to build a minimal yet fully functional revenue sharing application with ZarnithFi Router SDK in just a few minutes. The same principles can be applied to create more complex applications for various use cases like team payments, royalty distributions, or treasury management.
Last updated