Skip to content

Latest commit

 

History

History
187 lines (146 loc) · 6.4 KB

README.md

File metadata and controls

187 lines (146 loc) · 6.4 KB

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

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:
    anchor install
    rustup install nightly
  4. Build and deploy the smart contract to the Solana devnet:
    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:
    npm install
  3. Start the frontend development server:
    npm start
  4. Open 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:
    npm install
  3. Configure your Solana cluster and wallet in the .env file.
  4. Start the backend server:
    npm start
  5. The backend server will run on http://localhost:5000.

How to Run

Prerequisites:

Running the Full Stack Locally:

  1. Clone the repository.
  2. Set up the Solana environment by running the following commands:
    solana config set --url devnet
    solana airdrop 2
  3. Run the smart contract:
    anchor build
    anchor deploy --provider.cluster devnet
  4. Run the backend:
    cd backend
    npm install
    npm start
  5. Run the frontend:
    cd frontend
    npm install
    npm start
  6. Open 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: