StakeHive DeFi Staking Protocol Development

Didarul Alam Rahat

Didarul Alam Rahat

๐Ÿš€ StakeHive โ€” Enterprise-Grade DeFi Staking Protocol

๐Ÿ”ฅ Live Demo

Explore the app live here: https://stakehive-defi-dapp.netlify.app/
StakeHive is a decentralized finance (DeFi) app enabling users to stake custom HIVE tokens, earn rewards, claim, withdraw, and transfer tokens securely on the blockchain.

๐Ÿงช How to Use StakeHive

Want to start staking with StakeHive? Follow these simple steps:

๐Ÿ”น Step 1: Enable Test Networks in MetaMask

By default, MetaMask hides test networks. To enable them:
Open MetaMask.
Click on your account icon โ†’ Settings.
Navigate to Advanced.
Scroll to Show test networks and toggle it ON.
Return to the main screen, and youโ€™ll now see Sepolia in the network dropdown.

๐Ÿ”น Step 2: Add Sepolia Testnet (If Not Visible)

If Sepolia isnโ€™t showing:
Click "Select Network" โ†’ "Add network" โ†’ "Add network manually".
Fill in the following:
Network Name: Sepolia Test Network
RPC URL: https://rpc.sepolia.org
Chain ID: 11155111
Currency Symbol: ETH
Block Explorer URL: https://sepolia.etherscan.io

Click Save.

๐Ÿ”น Step 3: Get Sepolia ETH for Gas

Youโ€™ll need Sepolia ETH to pay for gas fees. Use one of the following faucets:
Paste your MetaMask wallet address and request test ETH.

๐Ÿ”น Step 4: Add HIVE Token to MetaMask

To see your HIVE token in MetaMask:
Open MetaMask โ†’ go to Assets โ†’ click Import tokens.
Enter your deployed token details:
Token Contract Address: 0x359863fB0ca4E4be77daD9dFFBB0BbdA94690cCC
Token Symbol: HIVE
Decimals: 18

Click Add Custom Token โ†’ Import Tokens.
You'll now see your HIVE balance.
โš ๏ธ Note: This is the current Sepolia deployment address. If you deploy your own contracts, use the address printed in your deploy output.

๐Ÿ”น Step 5: Connect Wallet to StakeHive

Click Connect Wallet.
Choose MetaMask or another supported wallet via Web3Modal.

๐Ÿ” StakeHive Features & How to Use Them

โœ… Stake HIVE Tokens

Go to the Stake section.
Enter the amount of HIVE you want to stake.
Click Stake, then approve the transaction in MetaMask.
Your tokens are now staked and earning rewards.

๐Ÿ’ธ Claim Rewards

Navigate to the Rewards section.
Click Claim and approve the transaction.
Your rewards are sent to your wallet instantly.

๐Ÿ”“ Withdraw Staked Tokens

โš ๏ธ You can only withdraw after the lock duration expires.
Go to your Staked Balance.
Click Withdraw, confirm in MetaMask.
Staked tokens will return to your wallet.

๐Ÿ” Transfer HIVE Tokens

Open the Transfer tab.
Enter the recipient wallet address and amount.
Click Send and confirm the transaction.
Tokens are transferred peer-to-peer via blockchain.

๐ŸŽฏ Pro Tips

Make sure you have Sepolia ETH in your wallet for transactions.
View all your blockchain activity on Sepolia Etherscan.
If tokens arenโ€™t showing in MetaMask, use "Import Tokens" with your HIVE token contract address.
Use this app for educational and testing purposes only โ€” the tokens and network are not real/mainnet.

โœจ Key Features

Feature Description Tech Used Custom ERC20 Token HIVE token with minting and burning functionality Solidity, OpenZeppelin Staking Contract Time-locked staking with secure rewards distribution Solidity, Hardhat Token Transfer Transfer HIVE tokens between accounts with blockchain verification Ethers.js, MetaMask Real-Time Updates Reactive UI reflecting live balances, rewards, and transaction statuses Vue 3, Nuxt 3, Tailwind Wallet Integration Supports MetaMask, WalletConnect, and Coinbase Wallet Web3Modal Responsive UI Mobile and desktop friendly dashboard with staking analytics and charts Tailwind CSS, Chart.js

๐Ÿ—๏ธ Architecture Overview

Hereโ€™s a simplified view of the StakeHive architecture โ€” how components connect and communicate:
Ethers.js
Frontend: Nuxt3
Smart Contracts
Blockchain
Users
Loading
graph TD
A[Frontend: Nuxt3] -->|Ethers.js| B[Smart Contracts]
B --> C[Blockchain]
F[Users] --> A



๐Ÿ› ๏ธ Technology Stack

Smart Contracts

Language: Solidity (v0.8+)
Frameworks: Hardhat for development, testing, and deployment
Testing: Mocha, Chai, and Slither static analysis for security checks
Network: Deployed on Sepolia Testnet (Etherscan verified)

Frontend

Framework: Nuxt 3 with Composition API (Vue 3)
Blockchain: Ethers.js v6 for smart contract interaction
Wallets: MetaMask, WalletConnect, Coinbase Wallet through Web3Modal
Styling: Tailwind CSS + DaisyUI for rapid, responsive UI development
Charts & Analytics: Chart.js for staking and reward visuals
Deployment: Hosted on Netlify

๐Ÿ“ฆ Getting Started

Prerequisites

Node.js v16+ and npm
MetaMask or compatible Web3 wallet
Sepolia testnet ETH (from faucet)
Git

๐Ÿš€ Quick Start (Testing Only)

Want to just test the dApp without deploying? Use the pre-deployed contracts:
# 1. Clone the repo
git clone https://github.com/Darahat/stakehive-dapp.git
cd stakehive-dapp

# 2. Install Web3 dependencies
npm install

# 3. Install frontend dependencies
cd frontend
npm install

# 4. Run the frontend
npm run dev
The dApp is pre-configured with deployed Sepolia contracts:
HiveToken: 0x359863fB0ca4E4be77daD9dFFBB0BbdA94690cCC
StakeHiveFarm: 0x3531D47A28Aa87Bd5F9eaD3D2d8Fe07Ce16C8DDc
Just connect your wallet and you're ready to go! ๐ŸŽ‰

๐Ÿ› ๏ธ Full Development Setup

For developers who want to deploy their own contracts:
# 1. Clone the repo
git clone https://github.com/Darahat/stakehive-dapp.git
cd stakehive-dapp

# 2. Install dependencies for backend and frontend
npm install
cd frontend
npm install
cd ..

# 3. Start local blockchain (in a separate terminal)
# Open a new terminal and run:
npx hardhat node
# Keep this terminal running

# 4. Deploy contracts to localhost (in your main terminal)
npx hardhat run scripts/deploy-and-update.js --network localhost

# Note: No .env file needed for localhost! Only required for Sepolia testnet deployment

# 5. Run the frontend
cd frontend
npm run dev

Environment Variables (.env) - Only needed for Sepolia deployment:
# Create .env file only if deploying to Sepolia testnet
cp .env.example .env

# Then edit .env with:
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_API_KEY
PRIVATE_KEY=your_wallet_private_key_without_0x

# Deploy to Sepolia:
npx hardhat run scripts/deploy-and-update.js --network sepolia

๐Ÿ”ด CRITICAL: Understanding Contract Addresses

The project uses dynamic address mapping based on network chain ID. Contract addresses are stored in frontend/utils/contract.js:
export const ADDRESS_MAP = {
31337: {
// Hardhat Local Network
HIVE_TOKEN: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
STAKE_HIVE: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
},
11155111: {
// Sepolia Testnet
HIVE_TOKEN: "0x359863fB0ca4E4be77daD9dFFBB0BbdA94690cCC",
STAKE_HIVE: "0x3531D47A28Aa87Bd5F9eaD3D2d8Fe07Ce16C8DDc",
},
};
When you connect MetaMask, the dApp automatically:
Detects your network's chain ID
Loads the correct contract addresses for that chain
Queries those contracts for balances and data
โš ๏ธ Important: Running deployment scripts creates NEW contracts with NEW addresses. The frontend must be updated with these new addresses.

๐ŸŸข Option A: Automated Deployment (Recommended)

Use this script that automatically updates frontend addresses:
# Deploy to Sepolia and auto-update frontend
npx hardhat run scripts/deploy-and-update.js --network sepolia

# Or for local Hardhat network:
npx hardhat node # Terminal 1 - keep running
npx hardhat run scripts/deploy-and-update.js --network localhost # Terminal 2
What this does:
โœ… Deploys HiveToken
โœ… Deploys StakeHiveFarm
โœ… Transfers tokens to farm
โœ… Sets reward rate
โœ… Automatically updates frontend/utils/contract.js
โœ… Prints new addresses and next steps
After automated deployment:
# 1. Import new token to MetaMask with printed address
# 2. Transfer tokens to your wallet (update recipient address in script first)
npx hardhat run scripts/transfer-tokens.js --network sepolia

# 3. Start the frontend
cd frontend
npm run dev

๐Ÿ”ด Option B: Manual Deployment (Not Recommended)

If you prefer manual control:
# Deploy contracts
npx hardhat run scripts/deploy.js --network sepolia
โš ๏ธ You MUST manually update addresses after this!
Method 1: Use the address update script
node scripts/update-addresses.js <chainId> <hiveTokenAddress> <stakeHiveFarmAddress>

# Example:
node scripts/update-addresses.js 11155111 0x123... 0x456...
Method 2: Manually edit frontend/utils/contract.js
Open frontend/utils/contract.js and update the ADDRESS_MAP:
export const ADDRESS_MAP = {
11155111: {
// Sepolia
HIVE_TOKEN: "0xYOUR_NEW_TOKEN_ADDRESS",
STAKE_HIVE: "0xYOUR_NEW_FARM_ADDRESS",
},
};
After manual update:
# 1. Restart frontend dev server
cd frontend
npm run dev

# 2. Hard refresh browser (Ctrl+Shift+R)
# 3. Reconnect MetaMask wallet
# 4. Import new HIVE token address to MetaMask
# 5. Transfer tokens to your account

๐Ÿงช Running Tests

Comprehensive test suite with 10+ tests:
# Run all tests
npx hardhat test

# Run specific test file
npx hardhat test test/StakeHiveFarm.test.js

# Run with gas reporting
REPORT_GAS=true npx hardhat test
Test coverage includes:
โœ… Staking functionality
โœ… Reward calculations
โœ… Withdraw operations
โœ… Token transfers
โœ… Error handling
โœ… Edge cases

๐ŸŽ“ Usage Guide & Best Practices

Connecting Your Wallet

Ensure you're on Sepolia Testnet in MetaMask
Click Connect Wallet in the dApp
The dApp automatically detects your network and loads correct addresses
Browser console shows: ๐Ÿ”— Connected to chain 11155111 (sepolia)

Getting HIVE Tokens

If using pre-deployed contracts: Request tokens by opening an issue with your wallet address.
If you deployed your own: Transfer tokens from the deployment account:
# Edit scripts/transfer-tokens.js with:
# - recipientAddress: your wallet address
# - hiveTokenAddress: your deployed token address
# - transferAmount: amount to transfer (default: "10000")

npx hardhat run scripts/transfer-tokens.js --network sepolia

Importing HIVE Token to MetaMask

Open MetaMask
Go to Assets โ†’ Import tokens
Enter the contract address (check console logs or frontend/utils/contract.js)
Token Symbol: HIVE
Decimals: 18

Using StakeHive Features

Staking: Enter amount โ†’ Click Stake โ†’ Approve in MetaMask
Claiming Rewards: Navigate to Rewards โ†’ Click Claim โ†’ Approve transaction
Withdrawing: After lock period expires โ†’ Click Withdraw โ†’ Approve transaction
Transferring: Enter recipient address and amount โ†’ Click Transfer โ†’ Approve

Important Notes

Gas Fees: You need Sepolia ETH for all transactions. Get it from Sepolia Faucet
Token Balances: Displayed dynamically from blockchain, updated automatically
Staking Limits: Can only stake up to your current HIVE balance
Lock Period: Check staking dashboard for withdraw availability
Real-Time Updates: Vue watchers ensure UI reflects blockchain state automatically
Transaction Confirmation: All actions require MetaMask approval

๐Ÿ“Š Performance Highlights

Metric Value Contract Size ~24.5 KB Average Gas Cost ~142,000 gas Transactions Per Sec ~18.7 TPS (testnet) Frontend Load Time ~1.2 seconds

๐Ÿ”ง Developer Tools & Scripts

Available Scripts

Script Command Description Deploy (Auto) npx hardhat run scripts/deploy-and-update.js --network sepolia Recommended: Deploys and auto-updates frontend Deploy (Manual) npx hardhat run scripts/deploy.js --network sepolia Standard deployment (requires manual address update) Update Addresses node scripts/update-addresses.js <chainId> <tokenAddr> <farmAddr> Manually update frontend addresses Transfer Tokens npx hardhat run scripts/transfer-tokens.js --network sepolia Transfer HIVE to your wallet Run Tests npx hardhat test Run full test suite Start Frontend cd frontend && npm run dev Launch development server Build Frontend cd frontend && npm run build Production build

Project Structure

stakehive-dapp/
โ”œโ”€โ”€ contracts/ # Solidity smart contracts
โ”‚ โ”œโ”€โ”€ HiveToken.sol # ERC20 token with mint/burn
โ”‚ โ””โ”€โ”€ StakeHiveFarm.sol # Staking rewards contract
โ”œโ”€โ”€ scripts/ # Deployment and utility scripts
โ”‚ โ”œโ”€โ”€ deploy-and-update.js # Automated deployment โœ…
โ”‚ โ”œโ”€โ”€ deploy.js # Manual deployment
โ”‚ โ”œโ”€โ”€ update-addresses.js # Address updater utility
โ”‚ โ””โ”€โ”€ transfer-tokens.js # Token transfer helper
โ”œโ”€โ”€ test/ # Hardhat test suite
โ”‚ โ””โ”€โ”€ StakeHiveFarm.test.js
โ”œโ”€โ”€ frontend/ # Nuxt 3 frontend
โ”‚ โ”œโ”€โ”€ components/ # Vue components
โ”‚ โ”œโ”€โ”€ pages/ # Route pages
โ”‚ โ”œโ”€โ”€ stores/ # Pinia state management
โ”‚ โ”‚ โ””โ”€โ”€ walletStore.js # Wallet & blockchain logic
โ”‚ โ”œโ”€โ”€ utils/
โ”‚ โ”‚ โ””โ”€โ”€ contract.js # Contract ABIs & addresses โš ๏ธ
โ”‚ โ””โ”€โ”€ plugins/
โ”‚ โ””โ”€โ”€ web3.js # Ethers.js setup
โ”œโ”€โ”€ hardhat.config.js # Hardhat configuration
โ”œโ”€โ”€ .env.example # Environment template
โ””โ”€โ”€ .env # Your secrets (gitignored)

Key Files to Know

frontend/utils/contract.js: Contains ADDRESS_MAP - update after deploying
frontend/stores/walletStore.js: Wallet connection and blockchain interactions
hardhat.config.js: Network configurations and compiler settings
.env: Your private key and RPC URLs (NEVER commit this!)

Debugging Tips

Check browser console for logs:
๐Ÿ”— Connected to chain 11155111 - Network detected
๐Ÿ“ Using addresses: {...} - Addresses loaded for current chain
๐Ÿ’ฐ Fetching balance from HIVE token at: 0x... - Balance query
๐Ÿ“Š Raw balance (wei): ... - Retrieved balance before formatting
Common console errors and solutions:
โŒ No contract code at 0x... โ†’ Wrong network or address mismatch
Error fetching token balance โ†’ Check provider initialization
Unknown Token โ†’ Import token to MetaMask with correct address

โš ๏ธ Troubleshooting Guide

๐Ÿ”ด "Available Balance: 0.00 HIVE" but MetaMask shows tokens

Cause: Contract address mismatch between MetaMask and frontend
Solution:
Open browser console (F12)
Find log: ๐Ÿ’ฐ Fetching balance from HIVE token at: 0x...
Compare with MetaMask token address
If different, either:
Option A: Update MetaMask with the address from console log
Option B: Update frontend/utils/contract.js with MetaMask's address
Restart frontend and hard refresh (Ctrl+Shift+R)
Reconnect wallet

๐Ÿ”ด "Unknown Token" in MetaMask

Solution: Manually import the HIVE token:
MetaMask โ†’ Assets โ†’ Import tokens
Enter contract address (check console logs or frontend/utils/contract.js)
Symbol: HIVE, Decimals: 18

๐Ÿ”ด Transaction Failures

Check these:
โœ… Enough Sepolia ETH for gas? (Get from faucet)
โœ… Enough HIVE tokens for the transaction?
โœ… Token approval granted for staking contract?
โœ… On correct network (Sepolia = Chain ID 11155111)?

๐Ÿ”ด Frontend doesn't recognize deployed contracts

After deploying new contracts:
Verify addresses updated in frontend/utils/contract.js
Restart frontend dev server
Hard refresh browser (Ctrl+Shift+R)
Reconnect MetaMask wallet
Check console for correct addresses being loaded

๐Ÿ”ด "Receiver must be an instance of class" error

Cause: Using Pinia store proxy instead of actual ethers provider
Solution: Already fixed in codebase. Update to latest version.

๐Ÿ”ด Wallet not detected

Solution:
Install MetaMask
Refresh page after installation
Check if MetaMask is unlocked

๐Ÿ”ด Contract deployment fails

Common causes:
โŒ Missing or invalid SEPOLIA_RPC_URL in .env
โŒ Missing or invalid PRIVATE_KEY in .env
โŒ Not enough Sepolia ETH in deployment wallet
โŒ Network congestion (retry after a moment)

๐Ÿ’ก Best Practices

โœ… Always use deploy-and-update.js for deployments
โœ… Test on local Hardhat first before Sepolia
โœ… Check console logs for debugging information
โœ… Document new addresses after deployment
โœ… Transfer tokens to test accounts after deployment
โŒ Never commit .env file with private keys
โŒ Don't manually edit deployment scripts unless you know what you're doing

๐Ÿ‘จโ€๐Ÿ’ป Developer Notes

This app uses Ethers.js v6 โ€” syntax differs from v5 (especially parseEther and contract calls).
Smart contracts include reentrancy guards and gas optimizations.
Vue 3 Composition API provides modular and reactive state management with watchers for blockchain state.
The frontend automatically updates staking and rewards info on wallet events.
The backend admin panel (Laravel) manages off-chain data and analytics (not included in this repo).

๐Ÿ“ฌ Contact & Collaboration

Didarul Alam Rahat Senior Full Stack & Web3 Developer
๐Ÿ”— LinkedIn
๐Ÿฆ @darahat42
Open to senior Web3 roles, audits, consulting, and collaborations.

๐Ÿ“œ License

MIT License ยฉ 2023 Didarul Alam Rahat
Feel free to open issues or submit pull requests to improve the project! Your feedback and contributions are welcome.
Happy BUIDLing! ๐Ÿš€๐Ÿ
Like this project

Posted Dec 1, 2025

Developed StakeHive, a DeFi app for staking HIVE tokens on Sepolia Testnet.

Likes

0

Views

0

Timeline

Jun 30, 2025 - Aug 20, 2025