<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: tanisha aggarwal</title>
    <description>The latest articles on DEV Community by tanisha aggarwal (@tanisha_aggarwal_230355e5).</description>
    <link>https://dev.to/tanisha_aggarwal_230355e5</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4018594%2Fd650cfb0-3cf3-4699-9448-2e4e51d0b9f6.jpg</url>
      <title>DEV Community: tanisha aggarwal</title>
      <link>https://dev.to/tanisha_aggarwal_230355e5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tanisha_aggarwal_230355e5"/>
    <language>en</language>
    <item>
      <title>Building a DeFi Staking Platform on SCAI Mainnet with Solidity &amp; React</title>
      <dc:creator>tanisha aggarwal</dc:creator>
      <pubDate>Tue, 07 Jul 2026 02:49:25 +0000</pubDate>
      <link>https://dev.to/tanisha_aggarwal_230355e5/building-a-defi-staking-platform-on-scai-mainnet-with-solidity-react-41b4</link>
      <guid>https://dev.to/tanisha_aggarwal_230355e5/building-a-defi-staking-platform-on-scai-mainnet-with-solidity-react-41b4</guid>
      <description>&lt;p&gt;During my Blockchain Internship at EtherAuthority, I built a fully functional DeFi staking platform from scratch — a smart contract deployed on SCAI Mainnet, a React frontend connected via MetaMask, and real-time blockchain event tracking. Here's everything I learned.&lt;br&gt;
🔗 Live Demo &amp;amp; Code&lt;/p&gt;

&lt;p&gt;Live App: &lt;a href="https://defi-staking-platform-wc8n.vercel.app" rel="noopener noreferrer"&gt;https://defi-staking-platform-wc8n.vercel.app&lt;/a&gt;&lt;br&gt;
GitHub: &lt;a href="https://github.com/Tanisha-aggarwal1085/Defi-Staking-Platform" rel="noopener noreferrer"&gt;https://github.com/Tanisha-aggarwal1085/Defi-Staking-Platform&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What is a DeFi Staking Platform?&lt;br&gt;
A DeFi (Decentralized Finance) staking platform allows users to lock up cryptocurrency tokens in a smart contract and earn rewards over time — similar to a savings account, but fully on-chain with no central authority.&lt;br&gt;
In this project, users can:&lt;/p&gt;

&lt;p&gt;Stake SCAI tokens and earn 12% APY&lt;br&gt;
Withdraw their stake at any time (no lock-up period)&lt;br&gt;
Claim accrued rewards&lt;br&gt;
View full transaction history from blockchain events&lt;/p&gt;

&lt;p&gt;Tech Stack&lt;br&gt;
LayerTechnologySmart ContractSolidity ^0.8.20DevelopmentHardhatFrontendReact + ViteBlockchain Libraryethers.js v6WalletMetaMaskNetworkSCAI Mainnet (Chain ID: 34)HostingVercel&lt;/p&gt;

&lt;p&gt;Smart Contract Design&lt;br&gt;
The core of the platform is Staking.sol. Here's the key logic:&lt;br&gt;
solidity// SPDX-License-Identifier: MIT&lt;br&gt;
pragma solidity ^0.8.20;&lt;/p&gt;

&lt;p&gt;contract Staking {&lt;br&gt;
    uint256 public constant APY = 12;&lt;br&gt;
    uint256 public constant YEAR = 365 days;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mapping(address =&amp;gt; uint256) public stakes;
mapping(address =&amp;gt; uint256) public rewards;
mapping(address =&amp;gt; uint256) public lastUpdated;

event Staked(address indexed user, uint256 amount, uint256 newTotal);
event Withdrawn(address indexed user, uint256 amount, uint256 newTotal);
event RewardClaimed(address indexed user, uint256 amount);

function _updateReward(address user) internal {
    if (stakes[user] &amp;gt; 0) {
        uint256 timeElapsed = block.timestamp - lastUpdated[user];
        uint256 earned = (stakes[user] * APY * timeElapsed) / (100 * YEAR);
        rewards[user] += earned;
    }
    lastUpdated[user] = block.timestamp;
}

function stake() public payable {
    require(msg.value &amp;gt; 0, "Amount must be greater than 0");
    _updateReward(msg.sender);
    stakes[msg.sender] += msg.value;
    emit Staked(msg.sender, msg.value, stakes[msg.sender]);
}

function withdraw(uint256 amount) public {
    require(stakes[msg.sender] &amp;gt;= amount, "Not enough stake");
    _updateReward(msg.sender);
    stakes[msg.sender] -= amount;
    (bool success, ) = payable(msg.sender).call{value: amount}("");
    require(success, "Transfer failed");
    emit Withdrawn(msg.sender, amount, stakes[msg.sender]);
}

function claimReward() public {
    _updateReward(msg.sender);
    uint256 reward = rewards[msg.sender];
    require(reward &amp;gt; 0, "No rewards");
    rewards[msg.sender] = 0;
    (bool success, ) = payable(msg.sender).call{value: reward}("");
    require(success, "Transfer failed");
    emit RewardClaimed(msg.sender, reward);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
Key Design Decisions:&lt;/p&gt;

&lt;p&gt;Time-based APY — Rewards accrue continuously using block.timestamp&lt;br&gt;
Checks-Effects-Interactions — State changes happen before external calls (reentrancy prevention)&lt;br&gt;
Events — Every action emits an event for transparent on-chain history&lt;/p&gt;

&lt;p&gt;Reward Calculation Formula&lt;br&gt;
earned = (stakes[user] × APY × timeElapsed) / (100 × YEAR)&lt;br&gt;
This calculates rewards proportionally — the longer you stake, the more you earn.&lt;/p&gt;

&lt;p&gt;Frontend Architecture&lt;br&gt;
The React app uses a Context-based architecture to share blockchain state across all pages:&lt;br&gt;
App.jsx (Router)&lt;br&gt;
├── Web3Context.jsx  ← wallet + contract logic&lt;br&gt;
├── Dashboard.jsx    ← stake/withdraw/claim UI&lt;br&gt;
├── MyStakes.jsx     ← balance overview&lt;br&gt;
├── Transactions.jsx ← blockchain event history&lt;br&gt;
└── About.jsx        ← platform info&lt;br&gt;
Connecting to MetaMask with ethers.js v6:&lt;br&gt;
javascriptconst connectWallet = async () =&amp;gt; {&lt;br&gt;
    const provider = new ethers.BrowserProvider(window.ethereum);&lt;br&gt;
    await window.ethereum.request({ method: "eth_requestAccounts" });&lt;br&gt;
    const signer = await provider.getSigner();&lt;br&gt;
    const walletAddress = await signer.getAddress();&lt;br&gt;
    const contract = new ethers.Contract(CONTRACT_ADDRESS, ABI, signer);&lt;br&gt;
    // read stake and reward...&lt;br&gt;
};&lt;br&gt;
Network Auto-Switch:&lt;br&gt;
javascriptawait window.ethereum.request({&lt;br&gt;
    method: "wallet_switchEthereumChain",&lt;br&gt;
    params: [{ chainId: "0x22" }], // SCAI Mainnet = 34&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;Deployment to SCAI Mainnet&lt;br&gt;
javascript// hardhat.config.js&lt;br&gt;
module.exports = {&lt;br&gt;
    solidity: "0.8.20",&lt;br&gt;
    networks: {&lt;br&gt;
        scai: {&lt;br&gt;
            url: "&lt;a href="https://mainnet-rpc.scai.network" rel="noopener noreferrer"&gt;https://mainnet-rpc.scai.network&lt;/a&gt;",&lt;br&gt;
            accounts: [process.env.PRIVATE_KEY],&lt;br&gt;
            chainId: 34&lt;br&gt;
        }&lt;br&gt;
    }&lt;br&gt;
};&lt;br&gt;
bashnpx hardhat run scripts/deploy.js --network scai&lt;/p&gt;

&lt;h1&gt;
  
  
  Contract deployed to: 0xCd279499974Ac556a7DA538e5F1f1B501E46c14c
&lt;/h1&gt;

&lt;p&gt;Challenges I Faced &amp;amp; How I Solved Them&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Invalid Contract Address
My first deployment had a 41-character address (should be 40). MetaMask flagged every transaction as suspicious. Fix: Always verify address length after deployment.&lt;/li&gt;
&lt;li&gt;Shared Loading State
All three buttons (Stake, Withdraw, Claim) showed "Processing..." simultaneously because they shared one loading state. Fix: Created separate stakeLoading, withdrawLoading, claimLoading states.&lt;/li&gt;
&lt;li&gt;Wrong Network
The app was initially deployed on local Hardhat — mentors couldn't test it. Fix: Deployed to SCAI Mainnet and added automatic network switching.&lt;/li&gt;
&lt;li&gt;Transaction History Not Persisting
Blockchain events (queryFilter) sometimes failed on SCAI RPC. Fix: Dual approach — immediate in-memory update + async blockchain event sync.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What I Learned&lt;br&gt;
✅ How DeFi staking protocols work under the hood&lt;br&gt;
✅ Writing production-safe Solidity with CEI pattern&lt;br&gt;
✅ Deploying to real mainnets (not just testnets)&lt;br&gt;
✅ Debugging MetaMask transaction issues&lt;br&gt;
✅ Building multi-page Web3 dApps with React&lt;/p&gt;

&lt;p&gt;Conclusion&lt;br&gt;
Building this DeFi staking platform gave me hands-on experience with the full blockchain development stack — from smart contract design to frontend deployment. The biggest takeaway: real-world blockchain development is 20% writing code and 80% debugging transactions, network issues, and wallet quirks.&lt;br&gt;
If you want to explore the code or try the live app:&lt;/p&gt;

&lt;p&gt;🔗 Live: &lt;a href="https://defi-staking-platform-wc8n.vercel.app" rel="noopener noreferrer"&gt;https://defi-staking-platform-wc8n.vercel.app&lt;/a&gt;&lt;br&gt;
📂 GitHub: &lt;a href="https://github.com/Tanisha-aggarwal1085/Defi-Staking-Platform" rel="noopener noreferrer"&gt;https://github.com/Tanisha-aggarwal1085/Defi-Staking-Platform&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Built during Blockchain Internship at EtherAuthority&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>defi</category>
      <category>solidity</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
