Skip to content

Use Cases

Real-world implementation examples for Rach Wallet-as-a-Service.

1. Cryptocurrency Exchange

Build a full-featured exchange platform:

javascript
class CryptoExchange {
  async onUserRegistration(email, password) {
    // Create user account
    const user = await db.users.create({ email, password });
    
    // Create wallet for all supported networks
    const wallet = await rachAPI.createWallet(user.id, ['BSC', 'ETH', 'POL', 'TRX', 'SOL']);
    
    // Store wallet ID
    await db.users.update(user.id, { wallet_id: wallet.wallet_id });
    
    // Initialize zero balances
    for (const network of wallet.networks) {
      await db.balances.create({
        user_id: user.id,
        network: network,
        balance: '0.00'
      });
    }
    
    return { user, depositAddresses: wallet.addresses };
  }
  
  async handleDeposit(webhookEvent) {
    const { wallet_id, network, currency, amount } = webhookEvent;
    
    // Find user
    const user = await db.users.findByWallet(wallet_id);
    
    // Credit balance
    await db.balances.credit(user.id, network, currency, amount);
    
    // Notify user
    await notifications.send(user.id, {
      type: 'DEPOSIT_RECEIVED',
      amount, currency, network
    });
  }
  
  async processWithdrawal(userId, network, currency, amount, address) {
    // Verify sufficient balance
    const balance = await db.balances.get(userId, network, currency);
    if (parseFloat(balance) < parseFloat(amount)) {
      throw new Error('Insufficient balance');
    }
    
    // Deduct balance
    await db.balances.debit(userId, network, currency, amount);
    
    // Execute withdrawal (would use transfer API)
    const txn = await executeWithdrawal(network, currency, amount, address);
    
    return txn;
  }
}

2. Gaming Platform with NFTs

Manage player wallets and NFT inventory:

javascript
class GameWalletManager {
  async getOrCreateWallet(playerId) {
    let wallet = await db.wallets.findByPlayer(playerId);
    
    if (!wallet) {
      // Create wallet on first need
      const rachWallet = await rachAPI.createWallet(playerId, ['POL']); // Polygon for NFTs
      
      wallet = await db.wallets.create({
        player_id: playerId,
        wallet_id: rachWallet.wallet_id,
        polygon_address: rachWallet.addresses[0].address
      });
    }
    
    return wallet;
  }
  
  async awardPrize(playerId, prizeType, amount) {
    const wallet = await this.getOrCreateWallet(playerId);
    
    if (prizeType === 'NFT') {
      // Mint NFT to player's wallet
      await nftContract.mint(wallet.polygon_address, amount);
    } else if (prizeType === 'TOKEN') {
      // Transfer tokens
      await tokenContract.transfer(wallet.polygon_address, amount);
    }
    
    // Record in database
    await db.prizes.create({
      player_id: playerId,
      type: prizeType,
      amount: amount,
      wallet_address: wallet.polygon_address
    });
  }
  
  async getNFTInventory(playerId) {
    const wallet = await this.getOrCreateWallet(playerId);
    
    // Query NFTs owned by this address
    const nfts = await nftContract.tokensOfOwner(wallet.polygon_address);
    
    return nfts.map(tokenId => ({
      tokenId,
      metadata: await nftContract.tokenURI(tokenId)
    }));
  }
}

3. DeFi Integration Platform

Connect users to DeFi protocols:

javascript
class DeFiPlatform {
  async connectWallet(userId) {
    // Create wallet if doesn't exist
    let wallet = await db.wallets.findByUser(userId);
    
    if (!wallet) {
      const rachWallet = await rachAPI.createWallet(userId, ['BSC', 'ETH']);
      wallet = await db.wallets.create({
        user_id: userId,
        wallet_id: rachWallet.wallet_id,
        addresses: rachWallet.addresses
      });
    }
    
    return wallet;
  }
  
  async stake(userId, network, token, amount) {
    const wallet = await this.connectWallet(userId);
    const address = wallet.addresses.find(a => a.network === network);
    
    // Approve token spending
    await tokenContract.approve(stakingContract.address, amount, {
      from: address.address
    });
    
    // Stake tokens
    await stakingContract.stake(amount, {
      from: address.address
    });
    
    // Track staking position
    await db.stakes.create({
      user_id: userId,
      network, token, amount,
      staked_at: new Date()
    });
  }
  
  async getPortfolio(userId) {
    const wallet = await db.wallets.findByUser(userId);
    
    const portfolio = [];
    
    for (const addr of wallet.addresses) {
      // Get balances
      const balance = await rachAPI.getBalance(wallet.wallet_id, addr.network);
      
      // Get staking positions
      const stakes = await db.stakes.find({ user_id: userId, network: addr.network });
      
      portfolio.push({
        network: addr.network,
        balances: balance.balances,
        stakes: stakes
      });
    }
    
    return portfolio;
  }
}

4. E-commerce Crypto Payments

Accept crypto for products:

javascript
class CryptoEcommerce {
  async createCustomerWallet(customerId) {
    // Create wallet for customer rewards/refunds
    const wallet = await rachAPI.createWallet(customerId, ['BSC']);
    
    await db.customers.update(customerId, {
      wallet_id: wallet.wallet_id,
      refund_address: wallet.addresses[0].address
    });
    
    return wallet;
  }
  
  async processRefund(orderId, amount) {
    const order = await db.orders.findById(orderId);
    const customer = await db.customers.findById(order.customer_id);
    
    if (!customer.wallet_id) {
      await this.createCustomerWallet(customer.id);
    }
    
    const customer = await db.customers.findById(order.customer_id);
    
    // Send refund to customer wallet
    await sendCrypto(customer.refund_address, 'USDT', 'BSC', amount);
    
    // Update order
    await db.orders.update(orderId, {
      refund_amount: amount,
      refund_status: 'completed',
      refunded_at: new Date()
    });
  }
  
  async loyaltyReward(customerId, points) {
    const customer = await db.customers.findById(customerId);
    
    if (!customer.wallet_id) {
      await this.createCustomerWallet(customerId);
    }
    
    const customer = await db.customers.findById(customerId);
    
    // Convert points to USDT (e.g., 100 points = $1)
    const usdtAmount = points / 100;
    
    // Send reward
    await sendCrypto(customer.refund_address, 'USDT', 'BSC', usdtAmount);
    
    await db.loyaltyRewards.create({
      customer_id: customerId,
      points, usdtAmount
    });
  }
}

5. P2P Marketplace

Enable peer-to-peer crypto trading:

javascript
class P2PMarketplace {
  async createEscrowWallet(tradeId) {
    // Create temporary wallet for escrow
    const wallet = await rachAPI.createWallet(`trade_${tradeId}`, ['BSC']);
    
    await db.trades.update(tradeId, {
      escrow_wallet_id: wallet.wallet_id,
      escrow_address: wallet.addresses[0].address
    });
    
    return wallet;
  }
  
  async initiateTrade(sellerId, buyerId, amount, currency) {
    const trade = await db.trades.create({
      seller_id: sellerId,
      buyer_id: buyerId,
      amount, currency,
      status: 'pending'
    });
    
    // Create escrow wallet
    const escrowWallet = await this.createEscrowWallet(trade.id);
    
    // Buyer sends to escrow
    return {
      tradeId: trade.id,
      escrowAddress: escrowWallet.addresses[0].address,
      instructions: `Send ${amount} ${currency} to ${escrowWallet.addresses[0].address}`
    };
  }
  
  async completeTrade(tradeId) {
    const trade = await db.trades.findById(tradeId);
    const seller = await db.users.findById(trade.seller_id);
    
    // Transfer from escrow to seller
    await transferFromEscrow(
      trade.escrow_wallet_id,
      seller.wallet_address,
      trade.amount,
      trade.currency
    );
    
    await db.trades.update(tradeId, {
      status: 'completed',
      completed_at: new Date()
    });
  }
}

Next Steps

Built with ❤️ by Rach Finance