Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# OpenAI API Configuration
OPENAI_API_KEY=your_openai_api_key_here

# Application Configuration
PORT=3000
NODE_ENV=development
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
*.agdai
MAlonzo/**

# Node.js
node_modules/
npm-debug.log
yarn-error.log
package-lock.json

# Environment variables
.env

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
venv/
env/
ENV/
*.egg-info/
dist/
build/
181 changes: 180 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,180 @@
# Web3AI
# Web3AI

Web3AI is an AI-powered blockchain and Web3 development toolkit that integrates OpenAI's capabilities with blockchain technologies.

## 🌟 Features

- **Node.js Backend**: Server-side JavaScript for Web3 applications
- **OpenAI Integration**: AI-powered smart contract analysis, code generation, and blockchain insights
- **Python AI Scripts**: Advanced AI capabilities for blockchain development
- **Modular Architecture**: Easy to extend with additional AI or blockchain features

## 📋 Prerequisites

Before you begin, ensure you have the following installed:

- **Node.js** (v14 or higher) - [Download here](https://nodejs.org/)
- **npm** (comes with Node.js)
- **Python** (v3.8 or higher) - [Download here](https://www.python.org/downloads/)
- **pip** (comes with Python)

## 🚀 Getting Started

### 1. Clone the Repository

```bash
git clone https://github.com/lippytm/Web3AI.git
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README references a specific GitHub repository URL (https://github.com/lippytm/Web3AI.git) which may not be correct for all users of this project. Consider using a placeholder like https://github.com/yourusername/Web3AI.git or removing the specific username to make the documentation more generic and reusable.

Suggested change
git clone https://github.com/lippytm/Web3AI.git
git clone https://github.com/yourusername/Web3AI.git

Copilot uses AI. Check for mistakes.
cd Web3AI
```

### 2. Set Up Node.js Environment

Install Node.js dependencies:

```bash
npm install
```

### 3. Set Up Python Environment (Optional)

For Python AI scripts, install required packages:

```bash
pip install -r requirements.txt
```

Or create a virtual environment (recommended):

```bash
# Create virtual environment
python -m venv venv

# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt
```

### 4. Configure OpenAI API Key

1. **Get your OpenAI API key**:
- Visit [OpenAI Platform](https://platform.openai.com/api-keys)
- Sign in or create an account
- Navigate to API Keys section
- Click "Create new secret key"
- Copy your API key (you won't be able to see it again!)

2. **Set up environment variables**:

```bash
# Copy the example environment file
cp .env.example .env

# Edit .env and add your API key
# Replace 'your_openai_api_key_here' with your actual API key
```

Your `.env` file should look like this:

```
OPENAI_API_KEY=sk-your-actual-api-key-here
PORT=3000
NODE_ENV=development
```

⚠️ **Important**: Never commit your `.env` file to version control. It's already included in `.gitignore`.

## 🎯 Usage

### Running the Node.js Application

Start the main application:

```bash
npm start
```

This will run the OpenAI integration demo and show you how to interact with AI models.

### Running Python AI Scripts

Execute the sample AI script:

```bash
python ai_scripts/sample_ai.py
```

This demonstrates:
- Explaining Web3 concepts using AI
- Analyzing smart contract code
- Integration with OpenAI's Python library

## 📁 Project Structure

```
Web3AI/
├── backend/ # Node.js backend code
│ └── openai.js # OpenAI API integration module
├── ai_scripts/ # Python AI scripts
│ └── sample_ai.py # Sample AI functionality demo
├── .env.example # Environment variable template
├── .gitignore # Git ignore rules
├── index.js # Main entry point
├── package.json # Node.js dependencies and scripts
├── requirements.txt # Python dependencies
└── README.md # This file
```

## 🔧 Available Scripts

- `npm start` - Run the main application
- `npm test` - Run tests (to be implemented)

## 🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## 📝 License

This project is licensed under the ISC License.

## 🆘 Troubleshooting

### "OpenAI API key not configured" Error

Make sure you have:
1. Created a `.env` file in the project root
2. Added your OpenAI API key to the `.env` file
3. The key starts with `sk-`

### "Module not found" Error

Run `npm install` to install Node.js dependencies or `pip install openai python-dotenv` for Python.

### Python Import Errors

Make sure you have activated your virtual environment (if using one) and installed all required packages.

## 🔮 Future Enhancements

- Integration with blockchain networks (Ethereum, Polygon, etc.)
- Smart contract deployment automation
- AI-powered security auditing
- Web3 wallet integration
- NFT generation and analysis
- DeFi protocol interaction

## 📚 Resources

- [OpenAI API Documentation](https://platform.openai.com/docs)
- [Node.js Documentation](https://nodejs.org/docs)
- [Python OpenAI Library](https://github.com/openai/openai-python)
- [Web3.js Documentation](https://web3js.readthedocs.io/)

---

Made with ❤️ for the Web3 and AI community
180 changes: 180 additions & 0 deletions ai_scripts/sample_ai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
#!/usr/bin/env python3
"""
Web3AI - Python AI Script Example

This script demonstrates how to use OpenAI's Python library to interact
with AI models for Web3 and blockchain-related tasks.

Requirements:
pip install openai python-dotenv
"""

import os
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()


def setup_openai():
"""
Initialize OpenAI client with API key from environment
"""
try:
from openai import OpenAI

api_key = os.getenv('OPENAI_API_KEY')

if not api_key or api_key == 'your_openai_api_key_here':
print('⚠️ Warning: OpenAI API key not configured!')
print('📝 Please set OPENAI_API_KEY in your .env file')
return None

client = OpenAI(api_key=api_key)
print('✅ OpenAI client initialized successfully\n')
return client

except ImportError:
print('❌ Error: openai package not installed')
print(' Install it with: pip install openai')
return None


def analyze_smart_contract(client, contract_code):
"""
Example function to analyze smart contract code using AI

Args:
client: OpenAI client instance
contract_code: Smart contract code to analyze

Returns:
AI analysis of the contract
"""
if not client:
return "Client not initialized"

try:
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "system",
"content": "You are an expert in blockchain and smart contract security. Analyze smart contracts for potential vulnerabilities and best practices."
},
{
"role": "user",
"content": f"Analyze this smart contract code:\n\n{contract_code}"
}
],
max_tokens=300,
temperature=0.5
)

return response.choices[0].message.content

except Exception as e:
return f"Error analyzing contract: {str(e)}"


def explain_web3_concept(client, concept):
"""
Get AI explanation of Web3 concepts

Args:
client: OpenAI client instance
concept: Web3 concept to explain

Returns:
AI explanation
"""
if not client:
return "Client not initialized"

try:
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "system",
"content": "You are a Web3 educator. Explain blockchain and Web3 concepts in simple, clear terms."
},
{
"role": "user",
"content": f"Explain: {concept}"
}
],
max_tokens=200,
temperature=0.7
)

return response.choices[0].message.content

except Exception as e:
return f"Error getting explanation: {str(e)}"


def run_demo():
"""
Run demonstration of AI capabilities
"""
print('🚀 Web3AI Python Demo')
print('=' * 50)
print()

# Initialize OpenAI client
client = setup_openai()

if not client:
print('\n💡 To run this demo:')
print(' 1. Install dependencies: pip install openai python-dotenv')
print(' 2. Set OPENAI_API_KEY in .env file')
print(' 3. Get API key from: https://platform.openai.com/api-keys')
return

# Demo 1: Explain a Web3 concept
print('📚 Demo 1: Explaining Web3 Concepts')
print('-' * 50)
concept = "What is a blockchain consensus mechanism?"
print(f'Question: {concept}\n')
print('Thinking... 🤔\n')

explanation = explain_web3_concept(client, concept)
print('AI Response:')
print(explanation)
print()

# Demo 2: Smart contract analysis
print('\n🔍 Demo 2: Smart Contract Analysis')
print('-' * 50)

sample_contract = """
pragma solidity ^0.8.0;

contract SimpleStorage {
uint256 private data;

function set(uint256 _data) public {
data = _data;
}

function get() public view returns (uint256) {
return data;
}
}
"""

print('Analyzing sample Solidity contract...\n')
print('Thinking... 🤔\n')

analysis = analyze_smart_contract(client, sample_contract)
print('AI Analysis:')
print(analysis)
print()

print('\n✅ Demo completed successfully!')
print('=' * 50)


if __name__ == '__main__':
run_demo()
Loading
Loading