π AI-powered starter template for building advanced Solidity analysis tools with Claude Sonnet 4
A production-ready starter template for building smart contract analysis tools powered by Claude AI. This project provides a solid foundation for developers who want to create their own customized security scanners, audit tools, or educational platforms for Solidity development.
This is a starter template - think of it as your foundation to build something bigger:
- β Ready-to-use: Works out of the box with basic vulnerability detection
- π οΈ Fully customizable: Modify prompts, add features, integrate with your tools
- π Learning resource: Understand how AI-powered code analysis works
- π Production-ready: Built with Next.js 15, TypeScript, and modern best practices
- π¨ Beautiful UI: Glassmorphic design you can adapt to your brand
Fork this template and create:
- Advanced Audit Platforms: Add multi-contract analysis, dependency scanning, or custom vulnerability detection
- Educational Tools: Build interactive learning platforms for smart contract security
- CI/CD Integration: Create GitHub Actions or GitLab CI plugins for automated security checks
- Specialized Scanners: Focus on specific protocols (DeFi, NFTs, DAOs) with custom detection rules
- Team Audit Tools: Add collaboration features, report generation, or integration with project management tools
- Custom Reporting: Generate PDF reports, integrate with Notion, or send Slack notifications
- Multi-Chain Support: Extend to analyze contracts on different EVM chains with chain-specific checks
This is a self-hosted application - you have complete control:
- π Full privacy: Your code and API key stay on your machine
- π° No shared costs: Use your own Anthropic credits
- β‘ No rate limits: No shared usage limits with other users
- π― Full control: Modify, extend, and adapt to your needs
- π§ Fork-friendly: MIT license - use it commercially or personally
- π Comprehensive Analysis: Detects 15+ vulnerability types including reentrancy, access control failures, and integer overflow
- π€ AI-Powered: Uses Claude Sonnet 4 for intelligent analysis beyond simple pattern matching
- β‘ Fast Results: Get detailed security reports in under 15 seconds
- π― Zero False Positives: Focused on real, exploitable vulnerabilities only
- π Detailed Reports: Interactive vulnerability cards with impact analysis and fix recommendations
- πΎ Export Reports: Download analysis results as JSON
- π¨ Modern UI: Clean, responsive interface built with Tailwind CSS
graph TB
A[User] --> B[Next.js Frontend]
B --> C[Code Editor]
C --> D[API Route /analyze]
D --> E[Claude Sonnet 4]
E --> F[JSON Response]
F --> D
D --> G[Results Page]
G --> H[Vulnerability Cards]
subgraph "Frontend Components"
C
G
H
end
subgraph "Backend Processing"
D
E
end
style A fill:#e1f5fe
style E fill:#fff3e0
style H fill:#f3e5f5
| Technology | Purpose | Version |
|---|---|---|
| Next.js | Full-stack React framework | 15.5.4 |
| TypeScript | Type safety and developer experience | 5.0+ |
| Claude Sonnet 4 | AI-powered security analysis | Latest |
| Tailwind CSS | Styling and responsive design | 3.4+ |
| Lucide React | Modern icon library | Latest |
| Monaco Editor | Code editor with Solidity syntax highlighting | Latest |
- Reentrancy: External calls before state updates
- Access Control: Missing admin function protection
- Delegatecall: Untrusted address delegation
- Selfdestruct: Unprotected contract destruction
- Unchecked Calls: External calls without return value checks
- tx.origin Auth: Phishing-vulnerable authentication
- Integer Overflow: Arithmetic issues in Solidity <0.8.0
- Timestamp Dependence: Block timestamp manipulation
- DoS Vectors: Unbounded loops and gas griefing
- Front-running: MEV exploitation opportunities
- Floating Pragma: Version range vulnerabilities
- Outdated Compiler: Missing security features
- Missing Events: Admin action transparency
- Gas Optimization: Efficiency improvements
- Node.js 18+
- npm/yarn/pnpm
- Anthropic API key (required - see below)
Before you start, you need your own Anthropic API key:
- Visit console.anthropic.com
- Sign up or log in to your account
- Navigate to API Keys section
- Click Create Key
- Copy your API key (starts with
sk-ant-api03-...) - Keep it safe - you'll need it in the next steps
Note: Anthropic offers free credits for new accounts. Check their pricing at anthropic.com/pricing
-
Clone the repository
git clone https://github.com/yourusername/smartcontract-security-scanner.git cd smartcontract-security-scanner -
Install dependencies
npm install
-
Set up your API key
Create a
.env.localfile in the root directory:# On Linux/Mac touch .env.local # On Windows (PowerShell) New-Item .env.local
Add your Anthropic API key to
.env.local:ANTHROPIC_API_KEY=sk-ant-api03-your-actual-key-here
β οΈ Important:- Replace
sk-ant-api03-your-actual-key-herewith your real API key - Never commit
.env.localto git (it's already in.gitignore) - Each user needs their own API key
- Replace
-
Run the development server
npm run dev
-
Open your browser
Navigate to http://localhost:3000
You should see the Smart Contract Scanner interface ready to use!
- Upload a
.solfile or paste Solidity code directly - Use the example contract for testing
- Click "Analyze Contract" to start the security scan
- Wait 10-15 seconds for AI analysis
- View security score (0-100)
- Examine vulnerability details
- Read impact descriptions and recommendations
- Download report as JSON
sequenceDiagram
participant U as User
participant F as Frontend
participant A as API Route
participant C as Claude AI
participant R as Results
U->>F: Upload Solidity code
F->>A: POST /api/analyze
A->>A: Validate code
A->>C: Send analysis prompt
C->>C: Analyze vulnerabilities
C->>A: Return JSON results
A->>A: Calculate security score
A->>F: Return analysis data
F->>R: Display results
R->>U: Show vulnerability cards
src/
βββ app/ # Next.js App Router
β βββ api/analyze/ # β API endpoint - customize analysis logic
β βββ results/ # Results display page
β βββ scan/ # Code upload page
β βββ page.tsx # Landing page
βββ components/ # React components
β βββ ui/ # Reusable UI components
β βββ CodeEditor.tsx # Monaco editor wrapper
β βββ VulnerabilityCard.tsx # β Customize vulnerability display
β βββ SeverityBadge.tsx
βββ lib/ # β Core logic - start customizing here
βββ claude.ts # Claude API client
βββ prompts.ts # β Analysis prompts - modify detection logic
βββ types.ts # TypeScript definitions
βββ utils.ts # Helper functions
Edit src/lib/prompts.ts to add your own detection rules:
// Add custom vulnerability types
export function buildAnalysisPrompt(solidityCode: string): string {
return `
... existing prompt ...
# CUSTOM DETECTION RULES
- Check for flash loan vulnerabilities
- Detect price oracle manipulation
- Analyze MEV opportunities
`;
}- Multi-file analysis: Modify
/api/analyzeto accept multiple files - Historical tracking: Add database to track vulnerability trends
- Custom scoring: Change the security score algorithm in
route.ts - Export formats: Add PDF, Markdown, or CSV export options
// Example: Integrate with Slither or Mythril
import { execSync } from 'child_process';
async function hybridAnalysis(code: string) {
const claudeResults = await analyzeContract(code, prompt);
const slitherResults = execSync('slither analyze.sol').toString();
// Combine results...
}- Add user authentication (NextAuth.js)
- Create shared workspaces
- Implement commenting on vulnerabilities
- Track remediation status
Here are some ideas to inspire you:
π Analysis Features:
- Multi-contract analysis (import resolution)
- Gas optimization suggestions
- Code quality metrics
- Comparison with best practices
- Historical vulnerability tracking
π Integrations:
- GitHub App for PR comments
- VS Code extension
- CI/CD pipeline integration
- Slack/Discord notifications
- Jira/Linear ticket creation
π Reporting:
- PDF report generation
- Executive summary creation
- Trend analysis dashboard
- Comparison between versions
- Custom branding
π Educational:
- Interactive tutorials
- Vulnerability examples library
- Fix suggestions with code
- Learning paths
- Certification system
π’ Enterprise:
- Team management
- Audit trail logging
- Compliance reports
- White-label options
- API for programmatic access
# Development
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
# Code Quality
npm run lint # Run ESLint
npm run type-check # Run TypeScript compiler- 100% Local: Everything runs on your machine - no data sent to external servers (except Anthropic API)
- No Storage: Your Solidity code is never stored anywhere
- Private API Key: Your API key stays in your
.env.localfile - No Tracking: No analytics, no telemetry, no data collection
- β
Store it in
.env.local(already in.gitignore) - β Keep it private and secure
- β Never commit it to GitHub
- β Never share it in Discord/Slack/etc.
- β Never hardcode it in your code
If you accidentally expose your API key:
- Go to console.anthropic.com
- Revoke the exposed key immediately
- Generate a new API key
- Update your
.env.localfile
- Each analysis costs approximately $0.01 - $0.03 in API credits
- You control your spending through your Anthropic account
- Set usage limits in your Anthropic console
- Monitor your usage at console.anthropic.com
| Metric | Value |
|---|---|
| Analysis Time | 10-15 seconds |
| Code Size Limit | 50KB |
| Supported Versions | Solidity 0.4.0+ |
| Vulnerability Types | 15+ categories |
| False Positive Rate | <5% |
Problem: You see an error message about missing API key.
Solution:
- Make sure you created
.env.localin the root directory (same level aspackage.json) - Check that your API key is correctly formatted:
ANTHROPIC_API_KEY=sk-ant-api03-... - Restart the development server after creating
.env.local:# Stop the server (Ctrl+C) npm run dev
Problem: The API key format is not recognized.
Solution:
- Verify your API key starts with
sk-ant- - Make sure there are no extra spaces or quotes in
.env.local - Copy the key directly from Anthropic console
Problem: Analysis takes longer than expected.
Solution:
- Check your internet connection
- Verify your Anthropic account has available credits
- Try with a smaller contract first to test
Problem: The file is hidden or not visible.
Solution:
- On Windows: Enable "Show hidden files" in File Explorer
- On Mac/Linux: The file starts with
.so it's hidden by default - Use your code editor (VS Code) to create the file - it will show hidden files
If you encounter other issues:
- Check the Anthropic Documentation
- Open an issue on GitHub
- Make sure you're using Node.js 18+
This is a starter template, so we encourage you to:
Have you built something cool with this template?
We'd love to see what you create! Consider:
- Opening a PR to add your project to a "Built with this template" section
- Sharing your fork on Twitter/X with #SmartContractScanner
- Writing a blog post about your customizations
Found ways to improve the base template?
- Open an issue with suggestions
- Submit a PR with improvements
- Share your custom prompts that worked well
Built an awesome project? Add it here:
Projects Built With This Template:
- Your project could be here! - Fork and customize this template
For Security Firms:
- Customize prompts for your specific audit methodology
- Add your branding and custom reporting
- Integrate with your internal tools
For DeFi Protocols:
- Create protocol-specific security scanners
- Add checks for your token standards
- Monitor deployed contracts continuously
For Educators:
- Build interactive security learning platforms
- Create challenges with automatic vulnerability detection
- Provide instant feedback to students
For Development Teams:
- Integrate into your CI/CD pipeline
- Create custom checks for your codebase style
- Track security improvements over time
After setting up your own instance:
- Experiment: Try analyzing different contracts to understand the baseline behavior
- Customize: Start with small prompt modifications in
prompts.ts - Extend: Add your first new feature (maybe a new export format?)
- Share: Consider open-sourcing your improvements
- Scale: Deploy to Vercel, Railway, or your own infrastructure
This project is licensed under the MIT License - see the LICENSE file for details.
What this means:
- β Use it commercially
- β Modify and distribute
- β Use it privately
- β No warranty provided
- Anthropic for Claude Sonnet 4 AI capabilities
- OpenZeppelin for security best practices reference
- Consensys for Solidity security guidelines
- SWC Registry for vulnerability classification
- The Web3 Security Community for continuous innovation
Built with β€οΈ as a starting point for the next generation of smart contract security tools
β Star this repo if you found it useful β’ π Fork it to build your own tool β’ π Report issues to help improve it