Skip to content

About

Backend for Zone tribe wallet

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

37 Commits

Folders and files

Repository files navigation

ZoneTribeWallet Backend

Table of Contents


Overview

ZoneTribeWallet is a secure, scalable, and containerized RESTful API for managing cryptocurrency wallets and transactions. It supports wallet creation, funding, transaction history (with search and export), and blockchain integration (Ethereum Sepolia testnet). The backend is built with ASP.NET Core, Entity Framework Core, and Nethereum, and is ready for deployment via Docker.


System Architecture

Key Components:

  • ASP.NET Core Web API: Main backend service.
  • Entity Framework Core: ORM for SQL Server.
  • Nethereum: Blockchain integration (Ethereum Sepolia).
  • JWT Authentication: Secure user authentication.
  • Docker: Containerization for backend and frontend.
  • Background Service: Listens for blockchain events and updates the database.

High-Level Diagram:

[Frontend (React)] <--REST--> [Backend API (ASP.NET Core)]
                                    |
                                    v
                            [SQL Server Database]
                                    |
                                    v
                        [Ethereum Sepolia Testnet]

Setup Instructions

Prerequisites

Local Development

  1. Clone the repository
    git clone <your-repo-url>
    cd zone-tribe-wallet-backend/ZoneTribeWallet.API
  2. Configure the database connection
  • Edit appsettings.Development.json or appsettings.json with your SQL Server connection string
  1. Apply Migrations
    dotnet ef database update
  2. Run the backend
    dotnet run
    The API will be available at http://localhost:5063/api.

Docker

  1. Build and run the Docker Compose
    docker compose up --build
    This will build the backend and frontend images and start the containers.
    • Backend: http//localhost:8080/
    • Frontend: http//localhost:3000/

API Reference

Authentication

  • POST /api/auth/register: Register a new user
  • POST /api/auth/login: Authenticate a user and return a JWT token

Wallets

  • POST /api/Wallet/create: Create a new wallet
  • GET /api/Wallet/gets-wallets: Get all wallets for the authenticated user

Transactions

  • POST /api/Transaction/send-fund: Send funds from one wallet to another
  • GET /api/Wallet/transactions/{walletAddress}: Get paginated transaction history for a wallet. Query parameters: -pageNumber: Page number for pagination (default: 1) -pageSize: Number of items per page (default: 20) -searchTerm: Search term to filter transactions by Transaction ID, date and Amount (optional)
  • GET /api/Wallet/transactions/{walletAddress}/all: Get all transactions for export functionality

Example Requests

See test.http for ready-to-us HTTP requests to test the API endpoints.

Database Schema

Wallets Table

Column Type Description
Id Guid Primary key
UserId string Owner (ASP.NET Identity)
Address string Ethereum wallet address
PrivateKey string Encrypted private key
Balance decimal Wallet balance
Network string Blockchain network
Currency string Currency (e.g., ETH)
WalletName string User-defined name
CreatedAt DateTime Creation timestamp

Transactions Table

Column Type Description
TransactionId Guid Primary key
WalletAddress string Associated wallet address
DateTime DateTime Transaction timestamp
Amount decimal Transaction amount
TransactionType string 'credit' or 'debit'
Status string 'successful', or 'failed'
BlockchainTransactionHash string Blockchain transaction hash

Blockchain Intergration

  • Uses Nethereum to interact with the Ethereum Sepolia testnet.
  • All successful transactions are logged on-chain and in the SQL database.
  • Private keys are encrypted before storage.
  • Background service (WalletEventListenerService) listens for new blocks and updates the database with received funds.

Docker & Deployment

Build and Run

docker compose up --build
  • The backend runs on port 8080 (see compose.yaml).
  • The frontend (if present) runs on port 3000.

Dockerfile

  • Multi-stage build for efficient image size.
  • Uses mcr.microsoft.com/dotnet/aspnet:8.0-alpine for runtime.

User Guide

1. Register and Login

  • Register a new user via /api/auth/register.
  • Login via /api/auth/login to receive a JWT token.

2. Create a Wallet

  • Use /api/Wallet/create with your user ID and desired wallet name.
  • The system generates an Ethereum wallet and stores the encrypted private key.

3. Fund and Transfer

  • Use /api/Wallet/send-fund to send funds from your wallet to another Ethereum address.
  • Transactions are logged in both the database and the blockchain.

4. View Transaction History

  • Use /api/Wallet/transactions/{walletAddress} for paginated results.
  • Use /api/Wallet/transactions/{walletAddress}/all to export all transactions (CSV/PDF).

5. Search Transactions

  • Add searchTerm as a query parameter to filter by date, amount, or transaction ID.

6. Export Transactions

  • Use the /all endpoint to fetch all transactions for export.

Extending the System

  • Real-Time Updates: Enable SignalR for live transaction notifications.
  • Additional Blockchains: Add support for other networks by extending the blockchain service.
  • Role-Based Access: Use ASP.NET Identity roles for admin/user separation.

Troubleshooting

  • DbContext concurrency errors: Ensure each async operation uses its own scoped DbContext.
  • Blockchain errors: Check your Infura or Ethereum node credentials and network status.
  • Docker issues: Ensure ports are not in use and environment variables are set correctly.

License

This project is licensed under the MIT License.


For questions or support, please contact the project maintainer.

About

Backend for Zone tribe wallet

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages