https://github.com/immutal0/solana-nft-staking-example
Solana nft, pnft, cnft staking example website
https://github.com/immutal0/solana-nft-staking-example
cnft nft pnft rewards solana staking
Last synced: about 2 months ago
JSON representation
Solana nft, pnft, cnft staking example website
- Host: GitHub
- URL: https://github.com/immutal0/solana-nft-staking-example
- Owner: Immutal0
- Created: 2025-02-12T10:04:36.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-13T17:10:18.000Z (over 1 year ago)
- Last Synced: 2025-04-09T00:47:35.763Z (about 1 year ago)
- Topics: cnft, nft, pnft, rewards, solana, staking
- Language: TypeScript
- Homepage:
- Size: 37.5 MB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Solana NFT Staking (NFT, PNFT, CNFT)
This project enables users to stake their NFTs (Non-Fungible Tokens) on the Solana blockchain, including traditional NFTs, PNFTs (Pre-Tokenized NFTs), and CNFTs (Compressed NFTs). The staking system allows users to earn rewards by staking their NFTs into a pool, and rewards are distributed periodically.
This repository contains both the smart contract and the frontend/backend components necessary to interact with the staking system.
---
## Table of Contents
- [Project Overview](#project-overview)
- [Features](#features)
- [Tech Stack](#tech-stack)
- [Smart Contract](#smart-contract)
- [Frontend](#frontend)
- [Backend](#backend)
- [How to Run](#how-to-run)
- [How to Contribute](#how-to-contribute)
- [License](#license)
---
## Project Overview
This repository contains a full-stack solution for Solana-based NFT staking:
- **Smart Contract:** Written in Rust using the Anchor framework, allowing users to stake and unstake NFTs, and claim rewards.
- **Frontend:** A React.js app that allows users to connect their Solana wallet (via Phantom, Sollet, etc.) and interact with the staking contract.
- **Backend:** A simple Node.js backend using Express.js for managing rewards and interacting with the Solana blockchain.
The project supports different types of NFTs:
- **NFT:** Standard Solana NFTs (minted on Solana using Metaplex).
- **PNFT:** Pre-Tokenized NFTs, designed for faster interaction with the blockchain.
- **CNFT:** Compressed NFTs, designed for more efficient storage.
---
## Features
- **Stake NFTs:** Users can stake their NFTs into a staking pool.
- **Reward System:** NFTs staked will earn rewards over time.
- **Multiple NFT Types Supported:** Supports standard NFTs, PNFTs, and CNFTs.
- **Unstake NFTs:** Users can unstake their NFTs at any time.
- **Reward Claiming:** Rewards are calculated based on the duration the NFTs are staked.
- **Transaction History:** Users can view transaction history of staking and reward claims.
- **Multi-Wallet Support:** Supports wallets like Phantom, Sollet, and others for user interaction.
---
## Tech Stack
- **Solana Blockchain**: The smart contract is deployed on the Solana blockchain.
- **Rust & Anchor Framework**: Used to write and deploy the smart contract.
- **React.js**: For building the frontend of the application.
- **Node.js & Express.js**: Backend server to handle interactions with the Solana blockchain and provide API endpoints.
- **Metaplex**: For working with Solana NFTs (including CNFTs and PNFTs).
- **Phantom Wallet**: Solana wallet extension for connecting users' wallets.
---
## Smart Contract
The smart contract is written in Rust using the Anchor framework and is responsible for the staking logic, reward distribution, and NFT management.
### Key Features of the Smart Contract:
- **Stake NFTs:** The contract allows users to stake Solana NFTs, including PNFTs and CNFTs.
- **Rewards Calculation:** It calculates and stores rewards for staked NFTs.
- **Unstake NFTs:** Users can unstake their NFTs and claim rewards.
- **Ownership Verification:** Ensures that only the owner of a specific NFT can stake it.
### How to Deploy the Smart Contract:
1. Clone the repository.
2. Navigate to the `smart-contract` directory.
3. Install Anchor and Rust dependencies:
```bash
anchor install
rustup install nightly
```
4. Build and deploy the smart contract to the Solana devnet:
```bash
anchor build
anchor deploy --provider.cluster devnet
```
5. Interact with the deployed contract using the provided frontend and backend.
---
## Frontend
The frontend is built using **React.js** and provides a user-friendly interface to interact with the staking smart contract.
### Key Features:
- **Wallet Integration:** Users can connect their Solana wallets (e.g., Phantom, Sollet) to the frontend to manage their NFTs.
- **Stake NFTs:** Interface to select and stake NFTs.
- **Claim Rewards:** Users can claim rewards earned by staking.
- **Unstake NFTs:** Users can unstake their NFTs and view transaction history.
### Setup and Running the Frontend:
1. Clone the repository.
2. Install dependencies:
```bash
npm install
```
3. Start the frontend development server:
```bash
npm start
```
4. Open [http://localhost:3000](http://localhost:3000) in your browser to interact with the dApp.
---
## Backend
The backend is built using **Node.js** and **Express.js**. It handles requests from the frontend, interacts with the Solana blockchain to manage staking and rewards, and stores staking data in a database.
### Key Features:
- **API for Staking and Unstaking NFTs:** Provides API endpoints for staking and unstaking NFTs.
- **Reward Calculation:** Calculates rewards based on the duration of NFT staking.
- **Transaction History:** Stores and retrieves the user's staking transaction history.
### Setup and Running the Backend:
1. Clone the repository.
2. Install dependencies:
```bash
npm install
```
3. Configure your Solana cluster and wallet in the `.env` file.
4. Start the backend server:
```bash
npm start
```
5. The backend server will run on [http://localhost:5000](http://localhost:5000).
---
## How to Run
### Prerequisites:
- Install [Node.js](https://nodejs.org/) (v14 or above)
- Install [Solana CLI](https://docs.solana.com/cli/install-solana-cli-tools)
- Install [Anchor Framework](https://project-serum.github.io/anchor/getting-started/introduction.html)
- Create a Solana wallet (e.g., Phantom) and fund it with test SOL for development.
### Running the Full Stack Locally:
1. Clone the repository.
2. Set up the Solana environment by running the following commands:
```bash
solana config set --url devnet
solana airdrop 2
```
3. Run the smart contract:
```bash
anchor build
anchor deploy --provider.cluster devnet
```
4. Run the backend:
```bash
cd backend
npm install
npm start
```
5. Run the frontend:
```bash
cd frontend
npm install
npm start
```
6. Open [http://localhost:3000](http://localhost:3000) to access the frontend.
---
## How to Contribute
1. Fork the repository.
2. Create a new branch: `git checkout -b feature-branch`.
3. Make your changes.
4. Commit your changes: `git commit -am 'Add new feature'`.
5. Push to the branch: `git push origin feature-branch`.
6. Open a Pull Request.
---
## Contact
For any questions, feel free to contact me:
- **Telegram:** [@Immutal0](https://t.me/Immutal0)
- **Twitter:** [@Immutal0_](https://x.com/Immutal0_)