DEV Community

Cover image for I open-sourced robust Solana Token Staking smart contract built with Anchor

I open-sourced robust Solana Token Staking smart contract built with Anchor

robust Solana Token Staking smart contract built with Anchor

A robust Solana Token Staking smart contract built with Anchor. Users can stake SPL tokens to earn proportional rewards over time. Features admin configuration, reward deposits, claim-only & unstake options, two-step authority transfer, and pause functionality. Includes a full TypeScript CLI for easy interaction and testing.

I open-sourced solana-token-staking-smart-contract for developers in Solana / Anchor smart contract development. This post walks through what it does, how the pieces fit together, and how to run it locally.

Why I built this

  • Explore solana token staking smart contract patterns in solana / anchor smart contract development
  • Fork the repo as a starter template for your own project
  • Contribute features, docs, or tests via pull requests

Most tutorials stop at a smart contract or a UI mockup. I wanted a complete vertical slice — wallet flow, on-chain logic, backend state, and a responsive frontend — so you can study or fork a production-shaped codebase.

What it does

  • Initialize / configure program – Admin sets token mint, claim period, reward multiplier, and other parameters.
  • Deposit funds – Admin deposits reward tokens into the program vault.
  • Stake tokens – Users stake SPL tokens and start earning rew
  • A robust Solana Token Staking smart contract built with Anchor
  • Users can stake SPL tokens to earn proportional rewards over time
  • Features admin configuration, reward deposits, claim-only & unstake options, two-step authority transfer, and pause functionality
  • Lets users stake tokens, unstake (withdraw principal + rewards), or claim rewards only.
  • Distributes rewards proportionally by share of total staked amount over configurable time periods.

Architecture at a glance

  • On-chain program — Anchor/Rust logic for escrow, rooms, and settlement
  • Application layer — TypeScript backend/frontend tying on-chain and off-chain flows
  • FeatureInitialize / configure program – Admin sets token mint, claim period, reward multiplier, and other parameters.
  • FeatureDeposit funds – Admin deposits reward tokens into the program vault.
  • FeatureStake tokens – Users stake SPL tokens and start earning rew
User Wallet  →  On-chain Program  →  VRF / Settlement
                    ↓
              Backend (API + WebSockets)  →  MongoDB / state
                    ↓
                 Frontend UI (real-time)
Enter fullscreen mode Exit fullscreen mode

Adjust the diagram to match your repo layout if components differ.

Tech stack

  • Rust
  • Solana
  • Anchor
  • TypeScript

Quick start

git clone https://github.com/DexCrancer/solana-token-staking-smart-contract.git
cd solana-token-staking-smart-contract
Enter fullscreen mode Exit fullscreen mode

Setup steps:

  1. Install dependencies (see README — typically npm install or yarn)
  2. Copy .env.example to .env and fill in RPC, wallet, and API keys
  3. Run local validator or point to devnet/mainnet as documented
  4. Start the backend and frontend; connect wallet and create a test room

See the full README for environment variables, deploy scripts, and test commands: https://github.com/DexCrancer/solana-token-staking-smart-contract

What to explore in the repo

  • Program / contract entrypoints and account models
  • API routes and WebSocket event handlers
  • Frontend wallet adapter and game room components
  • Tests, scripts, and deployment configs

Contributing

Issues and PRs are welcome. If this helped you learn something, a ⭐ on GitHub makes it easier for others to find.

Links


Disclaimer: Educational content only. Not financial advice. Gambling and trading involve risk; use responsibly and comply with local laws.

anchor #defi #solana #solanasmartcontract #solanastaking #splstaking

Top comments (0)