A minimal working Python prototype that anchors community proposals to the Cardano blockchain using Blockfrost and PyCardano. The system uploads proposals to Arweave for permanent storage, computes SHA256 hashes, and anchors them as metadata in Cardano transactions on the testnet.
- Key Features
- Architecture
- Quick Start
- Usage
- How It Works
- Troubleshooting
- Project Structure
- Useful Links
- π Immutable Anchoring - Proposals permanently stored on Cardano blockchain
- π Permanent Storage - Arweave integration for decentralized, permanent data storage
- π Verifiable Integrity - SHA256 hashing ensures data hasn't been tampered with
- β‘ Simple CLI - Easy-to-use command-line interface for anchoring and verification
- π Secure Wallets - Built-in wallet generation and management
- π Metadata Support - Rich metadata stored on-chain for easy retrieval
- π Testnet Ready - Works with Cardano preview and preprod testnets
- π― Production Ready - Fully tested and operational with comprehensive error handling
Proposal JSON β Arweave Upload β Hash Computation β Cardano Transaction β Blockchain
β β β β β
JSON File Arweave TX ID SHA256 Hash Metadata On-chain
π‘ Tip: Always use the wrapper scripts (
anchor_proposal.py,verify_proposal.py,wallet_utils.py) from the project root - they handle all paths automatically!
# Clone the repository
git clone <repository-url>
cd AI-Blockchain-Prototype
# Create virtual environment (recommended)
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Run setup script to verify installation
python setup.pyCopy the environment template and configure your API keys:
cp env.example .envEdit .env with your credentials:
# Blockfrost API Configuration
BLOCKFROST_API_KEY=your_blockfrost_api_key_here
BLOCKFROST_NETWORK=preview
# Arweave Configuration
ARWEAVE_GATEWAY_URL=https://arweave.net
ARWEAVE_KEY_FILE=your_arweave_wallet_key.json
ARWEAVE_NETWORK=mainnet
# Cardano Network Configuration
CARDANO_NETWORK=preview
METADATA_LABEL=1337- Visit Blockfrost.io
- Sign up for a free account
- Create a new project for Cardano (choose mainnet, preview, or preprod)
- Copy your API key to
.env - Set
BLOCKFROST_NETWORKto match your project (mainnet/preview/preprod)
- Visit Arweave.org
- Download the Arweave wallet or use ArConnect
- Create a new wallet and download the key file (e.g.,
your_arweave_wallet_key.json) - Save the key file in your project directory
- Update
.envwith your key file name:ARWEAVE_KEY_FILE=your_arweave_wallet_key.json - Fund your wallet with AR tokens (see funding instructions below)
π For detailed Arweave setup, see ARWEAVE_SETUP.md
# Generate a new testnet wallet
python wallet_utils.py --generateThis will create:
wallet.json- Wallet keys (keep secure!)wallet_mnemonic.txt- Recovery phrase (keep secure!)
- Copy the payment address from the wallet generation output
- For preview/preprod networks: Visit the Cardano Testnets Faucet
- For mainnet: Transfer ADA from an exchange or wallet
- Request testnet ADA for your address (preview/preprod only)
- Wait for the transaction to confirm
- Get AR tokens from exchanges like KuCoin, Gate.io, or Binance
- Transfer AR to your Arweave wallet address
- You need approximately 0.1-0.5 AR for each upload (cost varies with data size)
python anchor_proposal.py --example# Create a proposal file
cat > my_proposal.json << EOF
{
"title": "Community Garden Initiative",
"description": "Proposal to establish a community garden in the local park",
"proposer": "Alice Johnson",
"timestamp": 1703001600,
"category": "community_development",
"budget": 5000,
"duration_months": 12
}
EOF
# Anchor the proposal
python anchor_proposal.py --file my_proposal.jsonecho '{"title": "Test Proposal", "description": "A test proposal", "proposer": "Test User"}' | python anchor_proposal.py --stdin# Verify using transaction ID
python verify_proposal.py <transaction_id>
# Show full proposal content
python verify_proposal.py <transaction_id> --show-proposal
# Save results to file
python verify_proposal.py <transaction_id> --output verification_results.jsonThe system accepts proposals with the following structure:
{
"title": "string (required)",
"description": "string (required)",
"proposer": "string (required)",
"timestamp": "number (optional)",
"category": "string (optional)",
"budget": "number (optional)",
"duration_months": "number (optional)",
"beneficiaries": "array (optional)"
}# Generate new wallet
python wallet_utils.py --generate
# Show wallet info
python wallet_utils.py --info# Anchor from file
python anchor_proposal.py --file proposal.json
# Anchor from stdin
python anchor_proposal.py --stdin
# Use example proposal
python anchor_proposal.py --example
# Save results to file
python anchor_proposal.py --file proposal.json --output results.json# Basic verification
python verify_proposal.py <tx_id>
# Show proposal content
python verify_proposal.py <tx_id> --show-proposal
# Save results
python verify_proposal.py <tx_id> --output results.json- Proposal Input: Accept JSON proposal via file, stdin, or example
- Hash Computation: Compute SHA256 hash of normalized JSON
- Arweave Upload: Upload proposal to Arweave for permanent storage
- Transaction Building: Create Cardano transaction with metadata
- Blockchain Submission: Submit transaction to Cardano testnet
- Confirmation: Return transaction ID and Arweave permanent URL
- Transaction Lookup: Fetch transaction metadata from Blockfrost
- Arweave Retrieval: Download proposal using stored Arweave transaction ID
- Hash Comparison: Compute hash of retrieved proposal
- Verification: Compare computed hash with on-chain hash
- Result: Report success/failure with details
- Testnet Only: This prototype is designed for Cardano testnet only
- Wallet Security: Keep your wallet files and mnemonics secure
- API Keys: Don't commit API keys to version control
- Environment Variables: Use
.envfile for sensitive configuration
# Use python3 instead of python
python3 wallet_utils.py --generate
python3 anchor_proposal.py --example
python3 verify_proposal.py <tx_id>
# Or create an alias in your shell
echo 'alias python=python3' >> ~/.zshrc
source ~/.zshrc# Generate a wallet first
python wallet_utils.py --generate# Fund your wallet with ADA
# Preview/Preprod: https://docs.cardano.org/cardano-testnets/tools/faucet
# Mainnet: Transfer ADA from exchange or wallet# Download your Arweave wallet key file from Arweave.org or ArConnect
# Save it in the project directory
# Update .env with the exact filename:
# ARWEAVE_KEY_FILE=your_arweave_wallet_key.json
# Check if the file exists
ls -la *.json# Check your AR balance
python check_arweave_balance.py
# Or use arweave_utils directly
python arweave_utils.py --check-balance --key-file your_arweave_wallet_key.json
# Fund your Arweave wallet with AR tokens
# You need approximately 0.1-0.5 AR per upload# Check your Blockfrost API key
# Ensure you have sufficient ADA in your wallet
# Verify network configuration (mainnet/preview/preprod)
# Ensure your API key matches the selected networkEnable verbose logging by setting environment variable:
export PYTHONPATH=.
python -v anchor_proposal.py --exampleAI-Blockchain-Prototype/
βββ README.md # This file
βββ requirements.txt # Python dependencies
βββ setup.py # Package setup script
βββ .env.example # Environment template
βββ .gitignore # Git ignore rules
β
βββ src/ # π§ Source Code
β βββ config.py # Configuration management
β βββ core/ # Core functionality
β β βββ wallet_utils.py # Cardano wallet operations
β β βββ arweave_utils.py # Arweave operations
β βββ commands/ # CLI commands
β βββ anchor_proposal.py # Proposal anchoring
β βββ verify_proposal.py # Proposal verification
β
βββ scripts/ # π¨ Helper Scripts
β βββ check_status.py # System status checker
β βββ check_arweave_balance.py # Check Arweave balance
β βββ test_blockfrost.py # Test Blockfrost API
β
βββ docs/ # π Documentation
β βββ ARWEAVE_SETUP.md # Arweave wallet guide
β βββ ARCHITECTURE.md # System architecture
β βββ API.md # API reference
β βββ TROUBLESHOOTING.md # Troubleshooting guide
β
βββ examples/ # π Usage Examples
β βββ example_proposal.json # Sample proposal
β βββ anchor_example.py # Example script
β
βββ tests/ # π§ͺ Tests
β βββ (test files here)
β
βββ wallet/ # πΌ Wallet Storage
βββ wallet.json # Generated wallet (keep secure!)
βββ wallet_mnemonic.txt # Recovery phrase (keep secure!)
βββ your_arweave_wallet_key.json # Arweave key (keep secure!)
Note: For backwards compatibility, wrapper scripts exist in the root directory that call the organized code in src/.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
This is a prototype for educational and testing purposes only. Do not use for production applications without proper security audits and testing.