AI-powered smart contract generation and deployment platform for Flow blockchain using Cadence programming language.
- Multi-modal Input Processing: Accepts contracts via .cdc/.sol files or natural language descriptions
- AI-Powered Generation: Uses OpenAI/Groq LLMs to generate and optimize Cadence smart contracts
- Flow Blockchain Integration: Seamless deployment to Flow testnet/mainnet using Flow CLI
- Real-time Learning: Captures deployment logs to improve future contract generation
- Documentation Intelligence: Vector-powered documentation search for Cadence development
- User Privacy Controls: GDPR-compliant data management and export capabilities
- Real-time Updates: WebSocket-powered progress tracking and notifications
- Web Interface: Complete frontend for contract management and deployment
- Firecrawl Integration: Seamless documentation indexing and search using Firecrawl
- Python 3.8+
- Flow CLI installed and configured
- OpenAI API key or Groq API key
- PostgreSQL (recommended) or SQLite for development
-
Clone the repository
git clone <repository-url> cd flowzmith
-
Set up environment
cp .env.example .env # Edit .env with your API keys and database settings -
Install dependencies
pip install -r requirements.txt
-
Initialize database
alembic upgrade head
-
Start the application
python src/main.py # Or use the start script ./start.sh -
Access the web interface Open your browser and navigate to
http://localhost:8000
The API uses JWT tokens for authentication. Include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>
Create User
POST /api/v1/users
Content-Type: application/json
{
"email": "user@example.com",
"password": "secure_password",
"persona_type": "DEVELOPER",
"full_name": "John Doe"
}User Login
POST /api/v1/users/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "secure_password"
}Generate Contract from Natural Language
POST /api/v1/contracts
Authorization: Bearer <token>
Content-Type: application/json
{
"input_type": "NATURAL_LANGUAGE",
"content": "Create a simple NFT contract with mint and transfer functions",
"pre_conditions": {
"accounts": {"user": "0x123"},
"tokens": {"initial_supply": 1000}
},
"post_conditions": {
"deployed_contracts": ["NFTContract"],
"created_resources": ["NFT"]
},
"network": "testnet"
}Upload Contract File
POST /api/v1/contracts/file
Authorization: Bearer <token>
Content-Type: multipart/form-data
file: <contract-file>.cdcDeploy Contract
POST /api/v1/contracts/{submission_id}/deploy
Authorization: Bearer <token>
Content-Type: application/json
{
"network": "testnet",
"config_id": "generated_config_id"
}Get Deployment Status
GET /api/v1/contracts/{submission_id}/deployments/{deployment_id}
Authorization: Bearer <token>Search Documentation
POST /api/v1/documentation/search
Content-Type: application/json
{
"query": "Cadence resources",
"limit": 10,
"use_semantic_search": true
}Get Documentation Statistics
GET /api/v1/documentation/statsScrape URL
POST /api/v1/firecrawl/scrape
Content-Type: application/json
{
"url": "https://developers.flow.com/cadence",
"formats": ["markdown", "html"],
"include_tags": ["main", "article"],
"exclude_tags": ["nav", "footer"]
}Crawl Website
POST /api/v1/firecrawl/crawl
Content-Type: application/json
{
"url": "https://developers.flow.com",
"limit": 100,
"include_paths": ["/cadence/*"],
"exclude_paths": ["/blog/*"]
}Check Crawl Status
GET /api/v1/firecrawl/crawl/{crawl_id}/statusGet Learning Insights
GET /api/v1/learning/insights
Authorization: Bearer <token>Get System Statistics
GET /api/v1/statistics
Authorization: Bearer <token>Connect to WebSocket for real-time updates:
ws://localhost:8000/ws
Create a .env file in the project root:
# Application
APP_NAME=Flowzmith
DEBUG=false
HOST=0.0.0.0
PORT=8000
# Database
DATABASE_URL=postgresql://user:password@localhost/smart_contract_llm
# For development: sqlite:///./smart_contract_llm.db
# LLM Providers
OPENAI_API_KEY=your_openai_api_key
GROQ_API_KEY=your_groq_api_key
DEFAULT_LLM_PROVIDER=OPENAI
# Flow Blockchain
FLOW_NETWORK=testnet
FLOW_ACCOUNT_ADDRESS=your_flow_account_address
FLOW_PRIVATE_KEY=your_flow_private_key
# Security
JWT_SECRET_KEY=your_jwt_secret_key
JWT_ALGORITHM=HS256
JWT_EXPIRATION_HOURS=24
# Firecrawl Configuration
FIRECRAWL_API_KEY=your_firecrawl_api_key_here
FIRECRAWL_BASE_URL=https://api.firecrawl.dev
FIRECRAWL_TIMEOUT=30000
FIRECRAWL_MAX_RETRIES=3
# CORS
ALLOWED_ORIGINS=["http://localhost:3000", "http://localhost:8000"]For production deployment with PostgreSQL:
-
Create database
CREATE DATABASE smart_contract_llm; CREATE USER smart_contract_user WITH PASSWORD 'your_password'; GRANT ALL PRIVILEGES ON DATABASE smart_contract_llm TO smart_contract_user;
-
Run migrations
alembic upgrade head
-
Install Flow CLI
sh -ci "$(curl -fsSL https://storage.googleapis.com/flow-cli/install.sh)" -
Configure Flow project
flow project init flow keys generate
python cli.py generate-from-context --stream --requirements "Create a simple NFT contract"Via API:
import requests
import json
# Login
login_response = requests.post('http://localhost:8000/api/v1/users/login', json={
'email': 'user@example.com',
'password': 'secure_password'
})
token = login_response.json()['access_token']
# Generate contract
headers = {'Authorization': f'Bearer {token}'}
contract_data = {
'input_type': 'NATURAL_LANGUAGE',
'content': 'Create a simple NFT contract with mint function that allows users to mint NFTs with unique IDs',
'network': 'testnet'
}
response = requests.post(
'http://localhost:8000/api/v1/contracts',
json=contract_data,
headers=headers
)
submission = response.json()
submission_id = submission['submission_id']
# Deploy contract
deploy_response = requests.post(
f'http://localhost:8000/api/v1/contracts/{submission_id}/deploy',
json={'network': 'testnet'},
headers=headers
)
deployment = deploy_response.json()
print(f"Contract deployed with transaction hash: {deployment['transaction_hash']}")Via Web Interface:
- Open
http://localhost:8000in your browser - Login or create a new account
- Navigate to "Contract Generation"
- Enter your contract requirements in natural language
- Select the target network (testnet/mainnet)
- Click "Generate Contract"
- Review the generated contract and configuration
- Click "Deploy" to deploy to Flow blockchain
Via API:
import requests
# Upload contract file
with open('my_contract.cdc', 'rb') as f:
files = {'file': f}
response = requests.post(
'http://localhost:8000/api/v1/contracts/file',
files=files,
headers={'Authorization': f'Bearer {token}'}
)
submission = response.json()
submission_id = submission['submission_id']
# Deploy
deploy_response = requests.post(
f'http://localhost:8000/api/v1/contracts/{submission_id}/deploy',
json={'network': 'testnet'},
headers=headers
)Via API:
import requests
# Search for documentation
search_data = {
'query': 'How to create resources in Cadence',
'limit': 5,
'use_semantic_search': True
}
response = requests.post(
'http://localhost:8000/api/v1/documentation/search',
json=search_data
)
results = response.json()
for doc in results:
print(f"{doc['title']}: {doc['content'][:100]}...")# Run all tests
pytest
# Run with coverage
pytest --cov=src
# Run specific test file
pytest tests/test_api.py
# Run tests with markers
pytest -m "not llm" # Skip LLM tests
pytest -m integration # Run only integration tests- Unit Tests: Test individual components and functions
- Integration Tests: Test service interactions and database operations
- API Tests: Test REST endpoints and WebSocket connections
- Performance Tests: Test system performance under load
-
Build Docker image
docker build -t flowzmith . -
Run with Docker Compose
docker-compose up -d
-
Install dependencies
pip install -r requirements.txt
-
Set up database
alembic upgrade head
-
Start application
gunicorn src.main:app -w 4 -k uvicorn.workers.UvicornWorker
Production Environment:
DEBUG=false
DATABASE_URL=postgresql://user:password@prod-db/smart_contract_llm
ALLOWED_ORIGINS=["https://yourdomain.com"]- JWT-based authentication
- Rate limiting on all endpoints
- Input validation and sanitization
- CORS configuration for cross-origin requests
- Secure password hashing with bcrypt
- GDPR-compliant data handling
- User data export functionality
- Configurable data retention periods
- Anonymization of learning data
- Secure storage of sensitive information
- Flow account key management
- Transaction validation
- Gas estimation and optimization
- Network-specific deployment configurations
- Audit logging for all blockchain operations
src/
├── main.py # FastAPI application entry point
├── config.py # Configuration management
├── models/ # Database models
│ ├── database.py # Database connection and session management
│ ├── user.py # User and data control models
│ ├── contract.py # Contract and configuration models
│ └── learning.py # Learning and documentation models
├── services/ # Business logic layer
│ ├── llm_service.py # LLM provider integration
│ ├── flow_service.py # Flow blockchain operations
│ ├── user_service.py # User management
│ └── learning_service.py # Learning and documentation
├── api/ # API layer
│ ├── routes.py # REST API endpoints
│ ├── websocket.py # WebSocket handlers
│ ├── auth.py # Authentication middleware
│ └── middleware.py # Request processing middleware
└── utils/ # Utility functions
├── validators.py # Input validation
├── security.py # Security functions
└── helpers.py # Helper functions
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
# Install development dependencies
pip install -r requirements-dev.txt
# Set up pre-commit hooks
pre-commit install
# Run linting
flake8 src/
black src/
isort src/
# Run type checking
mypy src/Flow CLI not found:
# Ensure Flow CLI is installed and in PATH
flow version
# Add to PATH if needed
export PATH=$PATH:/path/to/flow/cliDatabase connection issues:
# Check database service status
sudo systemctl status postgresql
# Verify connection string
psql $DATABASE_URL -c "SELECT 1"LLM API errors:
# Verify API keys are set
echo $OPENAI_API_KEY
echo $GROQ_API_KEY
# Test API connectivity
curl -H "Authorization: Bearer $OPENAI_API_KEY" https://api.openai.com/v1/models- Database indexing on frequently queried fields
- Connection pooling for database connections
- Caching for documentation search results
- Background job processing for long-running operations
- Efficient WebSocket connection management
Flowzmith includes a comprehensive CLI for developers who prefer command-line workflows. The CLI provides:
- Interactive Contract Creation: Step-by-step guided contract generation
- Real-time Documentation Search: Search and browse Cadence documentation
- Firecrawl Integration: Crawl and index external documentation sources
- Contract Deployment: Deploy contracts directly from the command line
- System Monitoring: Check system status and view statistics
# Setup environment
python cli.py setup
# Create a contract interactively
python cli.py create-contract
# Search documentation
python cli.py search-docs
# Crawl external documentation with Firecrawl
python cli.py crawl-docs
# Interactive Firecrawl documentation search
python cli.py firecrawl-search
# Deploy a contract
python cli.py deploy-contract
# Run the complete wizard
python cli.py wizardFor detailed CLI documentation, see CLI_README.md.
This project is licensed under the MIT License - see the LICENSE file for details.
For support, please:
- Check the documentation
- Search existing issues
- Create a new issue with detailed information
- Join our community discussions
- Support for additional blockchain platforms
- Advanced contract optimization features
- Multi-signature contract deployment
- Contract verification and auditing tools
- Mobile application development
- Enhanced learning algorithms
- Enterprise features and compliance tools
