Skip to content

Repository files navigation

DeFi Staking dApp (Flutter)

A production-grade Flutter mobile dApp for DeFi staking, built with Clean Architecture, BLoC, WalletConnect, and web3dart.

Highlights

  • Clean Architecture (presentation, domain, data) with inward dependencies.
  • Wallet connection flow via WalletConnect (MetaMask and Trust Wallet deep links).
  • ERC-20 token balance + pending rewards retrieval from EVM network.
  • Staking, unstaking, and claiming rewards with contract function calls.
  • Transaction status handling (pending, success, failed) and explorer links.
  • Dark fintech UI, loading skeletons, localized strings, and robust error handling.

Tech Stack

  • Flutter (null-safe)
  • flutter_bloc for state management
  • dio for networking / RPC health verification
  • web3dart for contract reads and ABI encoding
  • walletconnect_flutter_v2 for wallet session + signing requests
  • get_it for dependency injection

Project Structure

lib/
  core/
    constants/
    di/
    error/
    logging/
    network/
    services/
  data/
    datasources/
    models/
    repositories/
  domain/
    entities/
    repositories/
    usecases/
  presentation/
    bloc/
    pages/
    widgets/
  l10n/

Web3 Flow Overview

  1. User taps Connect Wallet.
  2. App creates WalletConnect session and opens available wallet app.
  3. Session returns selected account (eip155 namespace).
  4. Read-only calls fetch token balance and pending rewards.
  5. Write calls (stake, unstake, claimRewards) are ABI-encoded and sent via wallet.
  6. UI displays transaction hash and links to explorer.

Configuration

Update runtime constants in:

  • lib/core/constants/app_constants.dart

Required values:

  • wcProjectId
  • chainId, rpcUrl, explorerBaseUrl
  • stakingContractAddress
  • tokenContractAddress
  • tokenDecimals

Default network is Sepolia. Replace with your target chain parameters for production.

ABI

Mock staking ABI is located at:

  • assets/abi/mock_staking_abi.json

Functions currently used:

  • pendingRewards(address user)
  • stake(uint256 amount)
  • unstake(uint256 amount)
  • claimRewards()

Getting Started

Prerequisites

  • Flutter SDK >=3.4.0
  • Android Studio / Xcode toolchain
  • A real wallet app for testing WalletConnect on device

Install

flutter pub get

Run

flutter run

Quality & Safety Notes

  • Mutation calls are guarded to prevent overlapping transactions.
  • Repository layer maps exceptions into domain Failure objects.
  • Stale refresh responses are ignored in BLoC using request id tracking.
  • Logging is centralized in AppLogger.

Troubleshooting

  • If wallet does not open, install MetaMask or Trust Wallet on the test device.
  • On Android emulator, WalletConnect deep linking may fail if no supported wallet exists.
  • Ensure your RPC endpoint is reachable and chain id matches wallet network.

License

This project is licensed under the MIT License. See LICENSE for details.

Releases

Packages

Contributors

Languages