Skip to content

myspace253/Casper-Interop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Casper Interop

Cross-Chain Bridge & Token Swap Platform for Casper Network

Built for Casper Network Hackathon Next.js TypeScript Testnet

Casper Interop is a comprehensive cross-chain interoperability platform built for the Casper Network Hackathon. It enables users to bridge assets between Casper and other blockchain networks, swap tokens, and manage their multi-chain DeFi activities seamlessly.

🌟 Features

πŸ”— Cross-Chain Bridge

  • Multi-Chain Support: Bridge assets between Casper and 7 major EVM networks
  • Supported Networks: Ethereum Sepolia, Arbitrum Sepolia, Optimism Sepolia, Base Sepolia, zkSync Era Sepolia, Linea Sepolia, Scroll Sepolia
  • Fast Transactions: Bridge completions typically under 5 minutes
  • Secure Transactions: Multi-signature validation and enterprise-grade security
  • Auto Network Detection: Automatic chain switching for connected wallets

πŸ”„ Token Swap

  • Instant Swaps: Swap CSPR, wETH, USDT, and USDC with minimal fees
  • Low Fees: Only 0.3% swap fee with optimized exchange rates
  • Slippage Control: Customizable slippage tolerance settings
  • Real-time Rates: Live price feeds and rate calculations

πŸ‘› Wallet Integration

  • Casper Wallets: Native support via CSPR.click SDK
    • Casper Wallet
    • Ledger Hardware Wallet
    • MetaMask Snap
  • EVM Wallets: Full MetaMask and EVM wallet support
  • Multi-Wallet Support: Connect multiple wallets simultaneously
  • Balance Auto-refresh: Real-time balance updates every 15 seconds

πŸ’§ Testnet Faucet

  • Free CSPR Tokens: Get testnet CSPR for development and testing
  • Rate Limited: Prevents abuse while enabling development
  • Instant Distribution: Quick token distribution for testing

πŸ“Š Transaction Management

  • Complete History: Track all bridge and swap transactions
  • Status Tracking: Real-time transaction status updates
  • Explorer Integration: Direct links to blockchain explorers
  • Export Data: Download transaction history for record keeping

πŸš€ Quick Start

Prerequisites

  • Node.js 16+
  • pnpm (recommended) or npm
  • MetaMask or compatible EVM wallet
  • Casper wallet (optional, can be created in-app)

Installation

  1. Clone the repository

    git clone https://github.com/myspace253/Casper-Interop.git
    cd casper-interop
  2. Install dependencies

    pnpm install
    # or
    npm install
  3. Set up environment variables

    cp .env.example .env.local

    Configure your environment variables:

    # Optional: CSPR.cloud API Key for enhanced balance fetching
    CSPR_CLOUD_API_KEY=your-cspr-cloud-api-key-here
    
    # Next.js Configuration
    NEXT_PUBLIC_APP_URL=http://localhost:3000
    NEXT_PUBLIC_CASPER_TESTNET_RPC=https://node.testnet.cspr.cloud/rpc
    NEXT_PUBLIC_CASPER_TESTNET_EXPLORER=https://testnet.cspr.live
  4. Run the development server

    pnpm dev
    # or
    npm run dev
  5. Open your browser Navigate to http://localhost:3000

πŸ—οΈ Architecture

Tech Stack

  • Frontend: Next.js 16, React 19, TypeScript
  • Styling: Tailwind CSS, shadcn/ui components
  • Blockchain Integration: CSPR.click SDK, EVM wallets
  • API: Next.js API routes with Casper RPC integration
  • Icons: Lucide React, custom icons

Project Structure

casper-interop/
β”œβ”€β”€ app/                    # Next.js App Router
β”‚   β”œβ”€β”€ api/               # API routes
β”‚   β”‚   └── casper/        # Casper blockchain API
β”‚   β”œβ”€β”€ bridge/            # Bridge interface page
β”‚   β”œβ”€β”€ swap/              # Swap interface page
β”‚   β”œβ”€β”€ faucet/            # Faucet page
β”‚   β”œβ”€β”€ history/           # Transaction history
β”‚   └── layout.tsx         # Root layout
β”œβ”€β”€ components/            # React components
β”‚   β”œβ”€β”€ ui/               # shadcn/ui components
β”‚   β”œβ”€β”€ bridge-card.tsx   # Bridge interface
β”‚   β”œβ”€β”€ swap-card.tsx     # Swap interface
β”‚   └── ...               # Other components
β”œβ”€β”€ lib/                   # Core utilities
β”‚   β”œβ”€β”€ casper-config.ts  # Casper network configuration
β”‚   β”œβ”€β”€ cspr-click-context.tsx  # Casper wallet context
β”‚   β”œβ”€β”€ evm-wallet-context.tsx  # EVM wallet context
β”‚   └── ...               # Other utilities
β”œβ”€β”€ hooks/                # Custom React hooks
└── public/               # Static assets

Core Components

Wallet Integration (lib/cspr-click-context.tsx)

  • CsprClickProvider: React context for Casper wallet management
  • Features: Connection status, balance tracking, transaction signing
  • Auto-refresh: Real-time balance updates with 15-second intervals
  • Multi-provider: Support for multiple Casper wallet providers

EVM Wallet Integration (lib/evm-wallet-context.tsx)

  • EVMWalletProvider: React context for EVM wallet management
  • Chain Support: 7 testnet chains with automatic configuration
  • Network Switching: Automatic chain detection and switching
  • Balance Tracking: Real-time ETH and token balance monitoring

Cross-Chain Bridge (components/bridge-card.tsx)

  • Dual Wallet Support: Works with both Casper and EVM wallets
  • Smart Address Management: Auto-fill destination addresses
  • Fee Estimation: Real-time gas and bridge fee calculations
  • Status Tracking: Comprehensive transaction status updates

Token Swap (components/swap-card.tsx)

  • Multi-Token Support: CSPR, wETH, USDT, USDC
  • Rate Calculation: Real-time exchange rate calculations
  • Slippage Settings: Customizable slippage tolerance
  • Gas Estimation: Automatic gas cost calculations

πŸ”§ API Routes

Casper Blockchain APIs

  • /api/casper/balance: Fetch account balance from Casper testnet
  • /api/casper/account: Get account information
  • /api/casper/deploys: Submit and track deploys
  • /api/casper/transfers: Handle token transfers
  • /api/casper/status: Get network status

API Features

  • Fallback Support: Automatic fallback to RPC if API key unavailable
  • Error Handling: Comprehensive error handling and logging
  • Rate Limiting: Built-in rate limiting to prevent abuse
  • Caching: Smart caching for improved performance

🌐 Supported Networks

Casper Network

EVM Networks (Testnets)

Network Chain ID Explorer Status
Ethereum Sepolia 11155111 Sepolia Etherscan βœ…
Arbitrum Sepolia 421614 Sepolia Arbiscan βœ…
Optimism Sepolia 11155420 Sepolia Optimism βœ…
Base Sepolia 84532 Sepolia Basescan βœ…
zkSync Era Sepolia 300 Sepolia zkSync Explorer βœ…
Linea Sepolia 59141 Sepolia LineaScan βœ…
Scroll Sepolia 534351 Sepolia Scrollscan βœ…

πŸ’° Supported Tokens

Token Symbol Decimals Type Icon
Casper CSPR 9 Native πŸ”΄
Wrapped Ether wETH 18 ERC-20 πŸ”·
Tether USD USDT 6 ERC-20 πŸ’΅
USD Coin USDC 6 ERC-20 πŸ’²

πŸ› οΈ Development

Available Scripts

# Development
pnpm dev          # Start development server
pnpm build        # Build for production
pnpm start        # Start production server
pnpm lint         # Run ESLint

# Type Checking
pnpm type-check   # Run TypeScript compiler check

Environment Setup

  1. Install Required Wallets

  2. Configure Testnet Networks

    • Add Casper testnet to your wallet
    • Configure EVM testnets in MetaMask
  3. Get Testnet Tokens

    • Visit the built-in faucet at /faucet
    • Request CSPR from official testnet faucets

Key Configuration Files

  • lib/casper-config.ts: Network and token configurations
  • next.config.mjs: Next.js configuration
  • tailwind.config.ts: Tailwind CSS configuration
  • components.json: shadcn/ui configuration

πŸ”’ Security Features

  • Wallet Integration: Secure wallet connections only
  • Transaction Validation: Client-side transaction validation
  • Error Handling: Comprehensive error handling and user feedback
  • Rate Limiting: API rate limiting to prevent abuse
  • Network Verification: Automatic network verification
  • Slippage Protection: Configurable slippage tolerance

πŸ“ˆ Performance

  • Fast Loading: Next.js static generation where possible
  • Efficient Updates: Smart balance refresh with 15-second intervals
  • Optimized Images: Next.js image optimization
  • Tree Shaking: Automatic bundle optimization
  • Caching: Strategic API response caching

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Style

  • Use TypeScript for all new code
  • Follow existing naming conventions
  • Add JSDoc comments for complex functions
  • Ensure all tests pass before submitting

πŸ“„ License

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

πŸ™ Acknowledgments

  • Casper Network for the innovative blockchain technology
  • CSPR.click for wallet integration SDK
  • shadcn/ui for beautiful UI components
  • Next.js team for the excellent framework
  • Tailwind CSS for the utility-first CSS framework

πŸ“ž Support

πŸ“Š Statistics

GitHub stars GitHub forks GitHub watchers


Built with ❀️ for the Casper Network Hackathon 2024

Disclaimer: This is a demonstration application for the Casper Network Hackathon. Do not use for mainnet transactions.

About

Cross-Chain Bridge and swap

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published