Skip to content

Repository files navigation

Crypto Payment System

This project is a Crypto Payment System API built with FastAPI and Etherscan API. It allows creates wallets for users to make transactions to, submit transactions, and monitor transaction statuses. It only supports Ethereum at the moment. The project uses uv for fast and reliable Python package management.

Features

  • User registration and authentication
  • Wallet creation and management
  • Transaction submission and monitoring
  • Rate limiting to prevent abuse
  • CORS support for frontend integration

Requirements

  • Python 3.12+
  • PostgreSQL
  • Redis
  • Docker (for containerized deployment)
  • uv (Python package manager)

Architecture Diagrams

Component Diagram

Component Diagram


Sequence Diagrams

1. User Registration

User Registration


2. Wallet Creation

Wallet Creation


3. Transaction Submission

Transaction Submission


4. Transaction Monitoring (Celery Task)

Transaction Monitoring


Class Diagram

Class Diagram


Setup

Environment Variables

Create a .env file in the project root with the following variables:

DATABASE_URL=postgresql+asyncpg://user:password@db/crypto_payments
MNEMONIC=your_mnemonic_seed_phrase
CELERY_BROKER_URL=redis://redis:6379/0
CELERY_RESULT_BACKEND=redis://redis:6379/0
ETHERSCAN_API_KEY=your_etherscan_api_key

Docker

To run the project using Docker, use the following commands:

docker compose up --build

This will start the PostgreSQL, Redis, FastAPI, and Celery services. The application runs as a non-root user for security, and uses uv for fast Python package management.

Manual Setup

  1. Install uv (if not already installed):
curl -LsSf https://astral.sh/uv/install.sh | sh
  1. Install dependencies using uv:
uv sync
  1. To generate or update requirements.txt (for Docker builds):
uv pip freeze > requirements.txt

Then, add ; sys_platform == 'win32' after the pywin32 line in requirements.txt if it exists. so, it goes from something like

pywin32==310 

to

pywin32==310 ; sys_platform == 'win32'
  1. Run the FastAPI application:
uv run uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
  1. Start the Celery worker and beat:
uv run celery -A app.celery_app.celery worker --loglevel=info
uv run celery -A app.celery_app.celery beat --loglevel=info

Usage

API Endpoints

  • POST /users/: Register a new user
  • POST /auth/login: Login and obtain a token
  • POST /payments/initiate: Initiate a new wallet
  • POST /payments/submit: Submit a transaction
  • GET /payments/transactions/{transaction_id}: Get transaction status
  • GET /payments/my-wallets: Get all wallets for the current user

Running Tests

To run the tests, use the following command:

pytest

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License.

About

A simple Ethereum payment solution in Python FastAPI

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Contributors

Languages