Forge unique, soulbound ERC-721 NFT reputation badges on the BNB Chain! This project demonstrates a powerful fusion of onchain data analysis with generative AI (LLMs) to assess wallet activity, provide insightful explanations, and mint personalized, non-transferable NFT credentials. Metadata is stored off-chain on IPFS for maximum efficiency and low gas costs.
Elevate user engagement by offering meaningful, AI-driven insights into their onchain identity, captured forever as a unique digital asset.
Key Highlights:
- Analyzes basic onchain activity (transaction count) from the BNB Chain.
- Applies customizable scoring logic to categorize wallet reputation.
- Leverages LLM integration (easily adaptable for different providers like OpenAI, Anthropic, OpenRouter, Gemini) to generate unique, natural language explanations for each reputation level.
- Mints a soulbound (non-transferable) ERC-721 NFT badge representing the user's reputation.
- Stores NFT metadata off-chain on IPFS via Pinata, ensuring low gas fees for minting.
- Features a clean web interface (Flask) for analysis and minting.
- Built with Python, Solidity,
web3.py, and theopenailibrary client.
Core Concept: The project showcases the powerful pattern of combining blockchain data, adaptable analysis logic, AI-generated insights, and NFT minting with decentralized off-chain storage. This foundation is ready for expansion with more sophisticated data sources and scoring models.
- Vamshi Paili
- Wallet Input: Simple web UI (Flask) for address input.
- Onchain Data Analysis: Fetches transaction count via
web3.py. - Rule-Based Scoring: Categorizes wallets (Newcomer, Explorer, etc.) based on configurable thresholds.
- AI-Generated Rationale: Uses a configured LLM API to explain the assigned category.
- Reputation Display: Shows score, category, SVG preview, and the AI rationale.
- ERC-721 NFT Minting: Mints a non-transferable badge for all analyzed wallets (except on analysis error).
- Backend: Python, Flask
- LLM Integration: Configurable LLM API call using the
openailibrary client (Adaptable to providers like OpenAI, Anthropic, OpenRouter, etc.) - Blockchain Interaction:
web3.py - Smart Contract: Solidity (OpenZeppelin ERC-721 standard)
- Decentralized Storage: IPFS via Pinata for NFT metadata.
- Blockchain: BNB Smart Chain / opBNB (Testnet recommended)
- Dependencies:
pip/uv,python-dotenv
- Python: Version >=3.10, <3.13 recommended.
- Package Manager:
piporuv. - BNB Chain Wallet: e.g., MetaMask.
- Testnet BNB: Required in the deployer/minter wallet (see Step 5) for gas fees. Get from BNB Chain Testnet Faucet.
- LLM API Key: An API key for your chosen LLM service provider (e.g., OpenRouter, OpenAI, Anthropic).
- The default configuration uses OpenRouter. See Step 5 and
.env.examplefor details.
- The default configuration uses OpenRouter. See Step 5 and
- Pinata JWT Key: An API key from Pinata to store NFT metadata on IPFS.
- Go to the Pinata Keys page, create a new key, and ensure it has permission for
pinFileToIPFS. Copy the JWT (JSON Web Token) provided.
- Go to the Pinata Keys page, create a new key, and ensure it has permission for
- Core Libraries:
Flask,web3.py,python-dotenv,requests,openai(installed viarequirements.txt).
git clone <repository-url> # Replace if needed
cd example-hub-main/python/ai-reputation-badgeUsing a virtual environment is strongly recommended.
# 1. Create virtual environment
python3 -m venv .venv
# 2. Activate environment
# Linux/macOS: source .venv/bin/activate
# Windows: .\.venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# (Optional) Or using uv:
# uv syncDeploy your own contract. Follow these steps using Remix IDE to deploy the contract to a BNB Chain Testnet:
- Open Remix: https://remix.ethereum.org/
- Load Contract: Create
ReputationBadge.solin Remix, paste code from the localcontracts/ReputationBadge.solfile. - Compile Contract: Select compiler (e.g., 0.8.20), compile
ReputationBadge.sol. - Deploy Contract: Connect wallet (on Testnet), select
ReputationBadgecontract, deploy, confirm transaction. - Copy Contract Address: Get the newly deployed contract address from Remix's "Deployed Contracts" section. You will use this in Step 5 (Configure Environment Variables).
-
Create
.envfile (if it doesn't exist):cp .env.example .env
-
Edit
.env: Open your.envfile and configure the settings based on the instructions and examples in.env.example. Make sure to:- Set your
RPC_URL,CONTRACT_ADDRESS(from deploying your own contract), andTESTNET_SCAN_URL. - Set your
PRIVATE_KEY(ensure it corresponds to the owner of the chosenCONTRACT_ADDRESSfor backend minting). - Set your
OPENROUTER_API_KEY. - Set your
PINATA_JWTwith the key you generated from Pinata. - Adjust optional thresholds if desired.
CRITICAL: Secure your
PRIVATE_KEYand API keys. Never commit your.envfile. Ensure thePRIVATE_KEYwallet has Testnet BNB. - Set your
If you edited ReputationBadge.sol and deployed it yourself, you MUST copy the new ABI from Remix and paste it into contracts/ReputationBadge.abi.json, replacing the old content.
- Activate virtual environment:
source .venv/bin/activate(or equivalent) - Start Flask server:
flask --app src.app:app run --port 5001 - Access: Open
http://127.0.0.1:5001in your browser.
- Frontend Interaction: User provides wallet address in the web UI (
index.html). - Backend Analysis Request: Flask backend (
app.py) receives the address via/analyze. - Onchain Data & Scoring:
analyzer.pyconnects to the RPC, gets the transaction count, and applies local rules to assign a reputationcategoryandscore. - AI Rationale Generation:
analyzer.pyuses theopenailibrary client (configured for the LLM provider specified in.env/ code) to callgenerate_rationale_with_llm. This sends context to the chosen LLM and receives a natural languagerationale. - Response to Frontend: Backend sends the full analysis back to the UI.
- UI Update: JavaScript displays the results, including the AI-generated rationale.
- Badge Eligibility Check: If analysis succeeded, the frontend calls
/check_badgeto check the smart contract. - Minting: If eligible, the user clicks "Mint". The backend (
/mint) triggerscontract_interaction.py.- The backend generates the metadata and uploads it to IPFS via Pinata.
- It then builds, signs (using
PRIVATE_KEY), and sends thesafeMinttransaction containing the lightweight IPFS URI.
- Result Display: UI shows mint success or failure.
- Scoring: Enhance
simulate_ai_reputation_scoreinanalyzer.py. - LLM Integration: This is highly adaptable! Modify
generate_rationale_with_llmand the client setup inanalyzer.pyto use different LLMs (GPT-4, Claude, Gemini, etc.), prompts, or API providers. Ensure you update the API key environment variable name and value in your.envfile accordingly. - NFT Metadata/SVG: Update
generate_token_uriandgenerate_badge_svgincontract_interaction.py. - Smart Contract: Modify
contracts/ReputationBadge.sol. - Frontend: Edit
src/templates/index.html.
Contributions are welcome! Please feel free to submit issues or pull requests to the original repository.