Skip to content

A FastAPI backend that analyzes on chain user behavior... from transaction history to DeFi interactions to generate a transparent and trustable crypto credit score.

Notifications You must be signed in to change notification settings

pratyakshkwatra/cryptocredit_backend

Repository files navigation

CryptoCredit Backend API

CryptoCredit Backend is a FastAPI powered service that calculates a transparent and trustable crypto credit score by aggregating on chain user data.

The protocol enables decentralized accountability, empowering fairer financial decisions across the Web3 ecosystem.

Below is a breakdown of all the parameters currently considered in generating the Crypto Credit Score. These factors combine to form a transparent, trustable score that reflects on chain behavior.


1. Wallet & Account Parameters

  • Wallet Age – Time since the first recorded on chain transaction.
  • Number of Active Wallets – Count of wallets linked to the user.
  • Wallet Verification Status – Whether the wallet is verified by the user.

2. Transaction History

  • Total Transaction Count – All transactions across supported chains.
  • Transaction Volume (Native & USD) – Total transferred value.
  • Average Transaction Value – Mean value per transaction.
  • Frequency of Transactions – Weekly/monthly activity levels.
  • Incoming vs Outgoing Ratio – Balance of inflow vs outflow.
  • Stablecoin Transactions – Share of transactions in stablecoins.

3. Staking Habits

  • Total Assets Staked – Amount of assets locked in staking.
  • Staking Duration – How long assets remain staked.
  • Number of Staking Contracts – Diversity of staking sources.
  • Rewards Earned – Yield or rewards generated via staking.

4. DeFi Interactions

  • Number of Protocols Used – Unique DeFi protocols interacted with.
  • Liquidity Pool Contributions – Assets provided to LPs.
  • Yield Farming Participation – Frequency & scale of farming activities.
  • Borrowing & Lending History – Usage of decentralized lending platforms.

5. Token Portfolio Insights

  • Token Diversity – Number of unique tokens held.
  • Blue chip vs. High risk Ratio – Quality assessment of holdings.
  • Portfolio Volatility – Value fluctuations over time.

6. Risk Indicators

  • Rug Pull Exposure – Past interactions with suspicious projects.
  • High gas Transactions – Frequency of transactions with unusually high gas.
  • Contract Approval Count – Number of active token approvals.

7. Reputation & Engagement

  • NFT Ownership & Activity – Number and type of NFTs owned.
All parameters are normalized and weighted according to the scoring model, which outputs a final score between 0 and 900.

Features

  • User Authentication: Sign up, sign in, refresh, and revoke tokens.
  • Chain Management: Retrieve supported blockchain networks (76).
  • Wallet Tracking: Add, verify, list, and delete wallets.
  • Scoring Engine: Compute a 0 - 900 crypto credit score based on aggregated behavior.
  • Developer API: Generate and manage API keys for external integrations.
  • API Analytics: Track usage and performance of API keys.
  • RESTful API: Fully documented OpenAPI spec.

Authentication

The API supports two authentication methods:

  1. JWT Bearer Tokens — Used for authenticated user access. Include an Authorization: Bearer <token> header.
  2. API Keys — Used for developer integrations.

Endpoints

Auth

Method Endpoint Description
POST /auth/sign_up Create a new account.
POST /auth/sign_in Authenticate and receive access/refresh tokens.
POST /auth/refresh_token Refresh access token using refresh token.
POST /auth/sign_out Revoke tokens and sign out.

Chains

Method Endpoint Description
GET /chains/ Retrieve list of supported chains.

Wallets

Method Endpoint Description
GET /wallets/ Get all linked wallets for the user.
POST /wallets/ Add a new wallet to track.
POST /wallets/verify Verify ownership of a wallet.
DELETE /wallets/{wallet_id} Remove a linked wallet.

Score

Method Endpoint Description
POST /score/ Calculate the credit score for the linked wallets (JWT auth).
POST /score/by_key Calculate the credit score using an API key (for developers).

API Keys & Analytics

Method Endpoint Description
GET /api/keys List API keys for the user.
POST /api/keys Create a new API key.
DELETE /api/keys/{key_id} Delete an API key.
GET /api/analytics Retrieve global API analytics.
GET /api/analytics/{key_id} Retrieve analytics for a specific API key.

Default

Method Endpoint Description
GET / Root endpoint for health/status checks.

Schemas

Some key request/response models:

  • UserCreate — Sign up payload.
  • UserLogin — Sign in payload.
  • RefreshToken — Refresh token payload.
  • WalletCreate — Payload for adding wallets.
  • WalletOut — Wallet output model.
  • ScoreRequest — Request payload for score calculation.
  • HTTPValidationError / ValidationError — Standardized error formats.

Installation & Setup

Requirements

  • Python 3.10+
  • FastAPI
  • SQLAlchemy
  • PostgreSQL

Steps

# Clone repository
git clone https://github.com/pratyakshkwatra/cryptocredit_backend
cd cryptocredit_backend

# Install dependencies
pip install -r requirements.txt

# Configure environment variables
cp .env.example .env
# Edit .env with your database & secret config

# Run server
uvicorn main:app --reload
# or
fastapi dev main.py

API will be available at: http://localhost:8000 Docs will be available at: http://localhost:8000/docs


Problem Statement

Design and develop a protocol that aggregates on-chain user behavior such as transaction history, staking habits, and DeFi interactions into a transparent, trustable crypto credit score.

The system should encourage accountability and enable fairer financial decisions in the decentralized ecosystem.


Made with 💜 by Pratyaksh Kwatra & Aarav Rai Fueled by ☕, powered by 🚀, and sprinkled with a bit of ✨ magic.

About

A FastAPI backend that analyzes on chain user behavior... from transaction history to DeFi interactions to generate a transparent and trustable crypto credit score.

Topics

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages