Skip to content

codebanditssss/chainspec

Repository files navigation

ChainSpec

Spec-First Smart Contract Framework Powered by Kiro IDE

Generate production-ready, secure Solidity contracts from markdown specifications using AI agents.

Built with Kiro License: MIT Ethereum


The Problem

Smart contract development is:

  • Time-consuming: 3-4 hours for a simple ERC20 token
  • Error-prone: Security vulnerabilities cost billions annually
  • Tedious: 200+ lines of boilerplate for basic functionality

The Solution

ChainSpec enables spec-first development:

  1. Write contract requirements in markdown
  2. AI generates secure, tested Solidity
  3. Deploy to Ethereum in minutes

Result: 98% reduction in development time, zero vulnerabilities.


Features

Kiro IDE Integration

  • Native MCP (Model Context Protocol) server
  • Invoke tools directly from Kiro chat
  • Autonomous file management

Security-First

  • Template-enforced access control
  • OpenZeppelin contract inheritance
  • Automated vulnerability prevention

Lightning Fast

  • Spec Solidity in <30 seconds
  • AI-powered test generation (GPT-4)
  • One-click deployment to Sepolia

Beautiful Dashboard

  • Real-time code generation
  • Project management UI

Quick Start

Prerequisites

  • Node.js 20+
  • Kiro CLI (optional, for MCP integration)
  • OpenAI API key (for AI test generation)

Installation

# Clone repository
git clone https://github.com/YOUR_USERNAME/chainspec.git
cd chainspec

# Install dependencies
npm install
cd dashboard && npm install && cd ..
cd contracts && npm install && cd ..

# Configure environment
cp dashboard/.env.example dashboard/.env
# Add your OPENAI_API_KEY to dashboard/.env

Run Dashboard

cd dashboard
npm run dev

Visit http://localhost:3000

Use with Kiro IDE

# Install Kiro CLI
curl -fsSL https://cli.kiro.dev/install | bash

# Login
kiro-cli login

# Register ChainSpec MCP
kiro-cli mcp add \
  --name chainspec \
  --command node \
  --args "/path/to/chainspec/dashboard/node_modules/.bin/tsx,/path/to/chainspec/dashboard/lib/mcp-server.ts" \
  --env "OPENAI_API_KEY=your-key" \
  --scope global

# Start Kiro chat
kiro-cli chat

In Kiro, try:

Use generate_solidity to create an ERC20 token called MyToken with owner-only minting

Usage

Option 1: Web Dashboard

  1. Open http://localhost:3000
  2. Click "New Project" or select existing spec
  3. Click "Generate Code"
  4. Review generated Solidity
  5. Deploy: cd contracts && npx hardhat run scripts/deploy.cjs

Option 2: Kiro IDE

  1. Open Kiro chat: kiro-cli chat
  2. Write spec or invoke tool:
    Generate a Solidity contract for an ERC20 token with these requirements:
    - Name: SecureToken
    - Symbol: STK
    - Only owner can mint
    
  3. Kiro calls ChainSpec MCP and returns Solidity
  4. Deploy from terminal

Architecture

Kiro IDE  MCP Protocol  ChainSpec Server
                              
                    
                                       
              Spec Parser         Code Generator
                                       
                    
                              
                      Solidity Contract
                              
                    Hardhat Deployment
                              
                      Ethereum Network

Key Components:

  • MCP Server (lib/mcp-server.ts): Kiro integration layer
  • Spec Parser (lib/engine/parser): Markdown JSON
  • Code Generator (lib/engine/generator): JSON Solidity
  • Templates (contracts/templates): ERC20, DAOVault, Custom
  • AI Agent (OpenAI GPT-4): Test generation

Project Structure

chainspec/
 dashboard/              # Next.js web app
    app/               # Pages and API routes
    lib/
       mcp-server.ts  # Kiro MCP server
       engine/        # Parser & Generator
    components/        # UI components
 contracts/             # Hardhat project
    generated/         # Output directory
    templates/         # Solidity templates
    scripts/           # Deployment scripts
 kiro/                  # Kiro specs & docs
    HERO/             # Hackathon submission
    01_erc20.md       # Example specs
    06_mcp_design.md  # MCP architecture
 README.md

Live Examples

Input Spec (kiro/01_erc20.md):

# ERC20 Token Specification

## Contract Name
MyToken

## Security Requirements
- Access control: Only owner can mint tokens

## Function: mint(address to, uint256 amount)
- Precondition: Caller is owner
- Postcondition: Balance of 'to' increases by amount

Generated Solidity (30 seconds later):

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyToken is ERC20, Ownable {
    constructor() ERC20("MyToken", "MTK") Ownable(msg.sender) {}
    
    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }
}

Deployment Result:

 MyToken deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3

Testing

# Compile contracts
cd contracts
npx hardhat compile

# Run tests (once generated)
npx hardhat test

# Deploy to local network
npx hardhat node              # Terminal 1
npx hardhat run scripts/deploy.cjs  # Terminal 2

# Deploy to Sepolia
npx hardhat run scripts/deploy.cjs --network sepolia

Tech Stack

Layer Technology
Frontend Next.js 16, React 19, ShadCN UI, Tailwind CSS
Backend TypeScript, Node.js
MCP Integration @modelcontextprotocol/sdk
AI OpenAI GPT-4
Blockchain Solidity 0.8.20, Hardhat, Ethers.js
Templates OpenZeppelin Contracts
Deployment Hardhat Deploy, Etherscan Verify

Roadmap

Phase 1: Core Engine (Completed)

  • Spec parser with regex extraction
  • Template-based code generator
  • ERC20 & DAOVault templates

Phase 2: Kiro Integration (Completed)

  • MCP server implementation
  • 3 tools: parse, generate, test
  • OpenAI integration for AI tests

Phase 3: Dashboard (Completed)

  • Next.js web interface
  • Split-view editor
  • Real-time generation

Phase 4: Security (In Progress)

  • Slither integration
  • Automated audits
  • Gas optimization suggestions

Phase 5: Multi-Chain (Planned)

  • Polygon support
  • Arbitrum support
  • Cross-chain deployment

Phase 6: Advanced Features (Planned)

  • Custom template builder
  • Formal verification
  • Community template marketplace

License

MIT License


Hackathon

Built at HackXios 2K25 for the Kiro Prize Track.

Tracks:

  • Most Creative Use of Kiro IDE
  • Best Innovation
  • AWS Track

Acknowledgments

  • Kiro IDE for the MCP framework
  • OpenZeppelin for secure contract templates
  • Hardhat for development tooling
  • HackXios organizers and sponsors

Documentation


About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors