Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Solana Staking App

A comprehensive token staking application built on Solana devnet with Phantom wallet integration.

Solana Staking App React TypeScript Next.js

πŸš€ Features

  • Phantom Wallet Integration: Seamless connection with Phantom wallet
  • SOL Airdrop: Get free SOL for testing on devnet
  • Token Purchase: Buy STAKE tokens for staking
  • Stake Tokens: Stake your tokens and earn rewards
  • Unstake Anytime: Flexible unstaking with no lock period
  • Real-time Rewards: Track and claim your staking rewards
  • Modern UI: Beautiful, responsive interface built with Tailwind CSS

πŸ—οΈ Architecture

Frontend

  • Next.js 14: React framework with TypeScript
  • Solana Wallet Adapter: For wallet connections
  • Tailwind CSS: Utility-first CSS framework
  • @solana/web3.js: Solana JavaScript SDK

Smart Contract

  • Rust: Solana program written in Rust
  • Borsh: Binary serialization for account data
  • Solana Program Library: Standard Solana program utilities

πŸ“‹ Prerequisites

Before running this application, make sure you have:

  1. Node.js (v16 or higher)
  2. npm or yarn
  3. Phantom Wallet browser extension
  4. Rust (for building Solana programs)
  5. Solana CLI (for program deployment)

πŸ› οΈ Installation & Setup

1. Clone the Repository

git clone <your-repo-url>
cd solana-staking-app

2. Install Dependencies

npm install

3. Install Solana CLI

# On macOS/Linux
sh -c "$(curl -sSfL https://release.solana.com/v1.16.0/install)"

# On Windows
curl https://release.solana.com/v1.16.0/solana-install-init-x86_64-pc-windows-msvc.exe --output C:\solana-install-tmp\solana-install-init.exe --create-dirs

4. Configure Solana for Devnet

solana config set --url https://api.devnet.solana.com
solana-keygen new

5. Build the Solana Program (Optional)

cd program
cargo build-bpf

πŸš€ Running the Application

Development Mode

npm run dev

Open http://localhost:3000 in your browser.

Production Build

npm run build
npm start

πŸ“± Usage Guide

1. Connect Wallet

  • Install Phantom wallet extension
  • Click "Select Wallet" and choose Phantom
  • Approve the connection

2. Get Test SOL

  • Click "Request 1 SOL Airdrop" to get free SOL
  • Wait for transaction confirmation

3. Buy STAKE Tokens

  • Enter the amount of tokens to purchase
  • Click "Buy STAKE Tokens"
  • Confirm the transaction in your wallet

4. Stake Tokens

  • Enter the amount to stake
  • Use percentage buttons for quick selection
  • Click "Stake Tokens" and confirm

5. Unstake & Claim Rewards

  • Enter unstake amount or use "MAX"
  • Click "Unstake Tokens" to withdraw and claim rewards
  • Or use "Claim Rewards" to claim without unstaking

πŸ”§ Configuration

Environment Variables

Create a .env.local file:

NEXT_PUBLIC_SOLANA_NETWORK=devnet
NEXT_PUBLIC_RPC_ENDPOINT=https://api.devnet.solana.com

Wallet Configuration

The app is configured for Solana devnet by default. To change networks:

  1. Update contexts/WalletProvider.tsx
  2. Change WalletAdapterNetwork.Devnet to desired network
  3. Update RPC endpoint accordingly

🎯 Smart Contract Details

Program Structure

// Instructions
- InitializePool: Create a new staking pool
- Stake: Stake tokens in the pool
- Unstake: Withdraw staked tokens
- ClaimRewards: Claim accumulated rewards

// Account Types
- StakingPool: Global pool state
- StakeAccount: Individual user stake data

Deployment

To deploy your own program:

cd program
cargo build-bpf
solana program deploy target/deploy/solana_staking_program.so

πŸ›‘οΈ Security Considerations

  • This is a demo application for educational purposes
  • Smart contract includes basic security checks
  • Always audit smart contracts before mainnet deployment
  • Test thoroughly on devnet before production use

πŸ§ͺ Testing

Run Tests

npm test

Manual Testing Checklist

  • Wallet connection works
  • Airdrop functionality
  • Token purchase simulation
  • Staking tokens
  • Unstaking tokens
  • Claiming rewards
  • UI responsiveness

πŸ“ Project Structure

solana-staking-app/
β”œβ”€β”€ components/          # React components
β”‚   β”œβ”€β”€ AirdropButton.tsx
β”‚   β”œβ”€β”€ StakingInterface.tsx
β”‚   └── TokenPurchase.tsx
β”œβ”€β”€ contexts/           # React contexts
β”‚   └── WalletProvider.tsx
β”œβ”€β”€ pages/              # Next.js pages
β”‚   β”œβ”€β”€ _app.tsx
β”‚   └── index.tsx
β”œβ”€β”€ program/            # Solana program (Rust)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   └── lib.rs
β”‚   └── Cargo.toml
β”œβ”€β”€ styles/             # CSS styles
β”‚   └── globals.css
β”œβ”€β”€ utils/              # Utility functions
β”œβ”€β”€ package.json
β”œβ”€β”€ next.config.js
β”œβ”€β”€ tailwind.config.js
└── README.md

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

If you encounter any issues:

  1. Check the troubleshooting guide
  2. Review Solana documentation
  3. Check Phantom wallet connection
  4. Ensure you're on devnet

πŸ” Troubleshooting

Common Issues

Wallet won't connect:

  • Ensure Phantom is installed and unlocked
  • Check browser permissions
  • Try refreshing the page

Airdrop fails:

  • Devnet airdrop has rate limits
  • Try again after a few minutes
  • Check Solana network status

Transactions fail:

  • Ensure sufficient SOL for gas fees
  • Check wallet approval
  • Verify network connection

Build errors:

  • Clear node_modules and reinstall
  • Check Node.js version compatibility
  • Verify all dependencies are installed

πŸ“š Resources

🎯 Demo Video

https://drive.google.com/file/d/1JMSzDtCnWjLDRCm6Y99qi7kKCWwdCp5f/view?usp=sharing


Built with ❀️ for the Solana ecosystem

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages