ββββββββββ ββββββ βββ βββββββββββββββββββ ββββββ βββ
βββββββββββ βββββββββββ ββββββββββββββββββββββββββββββ
βββ βββ βββββββββββ βββββββββββββββββ βββββββββββ
βββ βββ βββββββββββ βββββββββββββββββ βββββββββββ
βββββββββββββββββββ βββββββββββββββββββββββββββββββ ββββββ
ββββββββββββββββββ βββ βββββββ βββββββββββββββββββ ββββββ
The Legal Layer for Bitcoin
Natural Language β Bitcoin-Enforced Smart Contracts
"Write your deal in plain English. AI makes it airtight. Bitcoin holds the money. Nobody can cheat."
Every day, millions of people make deals that get broken.
- Clients refuse to pay after work is delivered
- Freelancers disappear after receiving upfront payment
- Multi-phase projects have no trustless payment enforcement
- Disputes have no neutral, fast resolution system
- Legal contracts are complex, costly, and inaccessible globally
Traditional escrow services solve some of these problems β but introduce centralized control, high fees (10β20% cuts), single points of failure, and days-long processing times.
Courts are slow. Lawyers are expensive. Trust fails.
ClauseAI turns plain English agreements into Bitcoin-secured smart contracts on the Stacks blockchain.
Instead of trusting a middleman, parties rely on:
- π€ AI-parsed terms β describe your deal in plain English, AI extracts every field
- π― Milestone-based escrow β funds release per deliverable, not all-or-nothing
- βοΈ AI-assisted arbitration β neural dispute resolution with human arbitrator override
- βΏ Bitcoin finality β every state change settled via Proof of Transfer
User types: "Pay Alex $2,000 for a website β 30% on wireframes, 40% on
development, 30% on final delivery. Dispute goes to John."
ClauseAI: β Parties extracted β payer: you, receiver: Alex
β Milestones parsed β 3 phases, exact percentages
β Arbitrator set β John's wallet
β Smart contract ready β deploy in 60 seconds
β sBTC locked on-chain β Bitcoin-enforced
Full flow in under 5 minutes:
- Describe your deal in plain English
- AI parses it into a structured contract
- Share a link with your counterparty
- Both parties approve via Leather wallet
- Party A locks sBTC into escrow
- Milestones release funds on completion
- Dispute? AI arbitrates. Arbitrator decides on-chain.
Users describe their deal in plain English. ClauseAI uses Groq + LLaMA 3.3 70B to extract:
| Field | Example |
|---|---|
| Payer | SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7 |
| Receiver | SP1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE |
| Total Amount | $2,000 USD β X sBTC |
| Milestones | [{30%, wireframes}, {40%, development}, {30%, delivery}] |
| Arbitrator | SP3FGQ8Z7JY9BWYZ5WM53E0M9NK7WHJF0691NZ159 |
Real deals have phases. ClauseAI supports multi-milestone conditional payments β the first Bitcoin-native escrow protocol to parse them directly from plain English.
Input: "30% on wireframes, 50% on development, 20% on launch day"
Output: Milestone 0 β 30% ($600) β status: locked
Milestone 1 β 50% ($1000) β status: locked
Milestone 2 β 20% ($400) β status: locked
Each milestone is an independent Clarity contract state.
If milestone 1 is disputed β only that $1000 is frozen.
Milestones 0 and 2 proceed independently.
ClauseAI uses actual sBTC (SIP-010 fungible token) β not STX, not a wrapper label.
Every agreement locks real sBTC. Every release moves real sBTC. Every dispute freezes real sBTC.
"Escrow in actual Bitcoin" is a fundamentally different product than "escrow on a Bitcoin layer."
When a dispute opens, both parties submit their case as plain text. The AI engine:
- Reads the original parsed contract terms
- Reads Party A's statement + evidence links
- Reads Party B's statement + evidence links
- Outputs a structured, reasoned verdict
{
"verdict": "release_to_receiver",
"confidence": 84,
"reasoning": "The contract required logo delivery by March 15. Party B
submitted final files on March 13 with confirmation link
provided. Party A's objection references color preferences
not specified in the original agreement terms.",
"key_factors": [
"Delivery confirmed before deadline",
"Objection outside contract scope",
"Evidence submitted by receiver"
]
}The human arbitrator reviews this and can follow or override with a single on-chain call. The AI is a legal analyst β the human retains final authority.
This is the first AI judge on Bitcoin.
Both parties see live updates without polling:
- Party B opens the link β Party A's screen updates instantly
- Party B approves β Party A gets notified in real time
- Funds locked β Party B's dashboard activates immediately
- Milestone completed β both dashboards update simultaneously
- Dispute resolved β arbitrator's decision propagates to all parties
ClauseAI removes trust from the equation entirely.
| Guarantee | Mechanism |
|---|---|
| Funds locked on-chain | sBTC transferred to contract on deposit |
| Neither party can withdraw unilaterally | Clarity post-conditions enforce this |
| Milestone-level granularity | Each tranche tracked independently |
| Arbitrator decisions are final | On-chain resolution calls |
| Timeout protection | Auto-refund if arbitrator is inactive 48hrs |
| Bitcoin finality | Every state change settled via Proof of Transfer |
Timeout Logic:
- If deadline passes with no
complete-milestone()call β payer triggers auto-refund - If arbitrator doesn't resolve within 48 hours β anyone calls
trigger-arb-timeout()β payer refunded
- Stacks β Bitcoin's smart contract layer
- Clarity β Deterministic, decidable smart contracts (no rug pulls possible)
- sBTC (SIP-010) β Actual Bitcoin as escrow currency
- Proof of Transfer β Bitcoin-finalized settlement
- Groq inference API
- LLaMA 3.3 70B β Contract parsing + dispute arbitration
- Natural language β structured contract schema
- Multi-milestone extraction from plain English
- AI arbitration engine with confidence scoring
- Next.js 14 + React
- Tailwind CSS
- Redux Toolkit (full async thunk architecture)
- Socket.io client β real-time presence & milestone updates
- Server-Sent Events β live counterparty detection
- Express + TypeScript
- MongoDB (agreement + dispute persistence)
- Redis (presence store, 24hr TTL)
- Socket.io (agreement rooms + dispute rooms with ack sync)
- SSE (Server-Sent Events for approval flow)
- Leather Wallet (non-custodial)
- Stacks Connect
- stacks.js
ClauseAI/
βββ frontend/ # Next.js app
β βββ app/
β β βββ page.tsx # Party A landing + flow
β β βββ agreement/[id]/ # Party B review + approval flow
β βββ components/
β β βββ partyA/ # Screens: Describe β Parse β Share β Lock
β β βββ partyB/ # Screens: Review β Connect β Approve β Wait
β βββ store/
β β βββ slices/
β β βββ partyASlice.ts # Full Party A state machine + thunks
β β βββ partyBSlice.ts # Full Party B state machine + thunks
β βββ lib/
β β βββ contractCalls.ts # Clarity contract interactions
β β βββ contractReads.ts # On-chain reads (milestone amounts, status)
β β βββ hiroWallet.ts # Leather wallet connection
β β βββ socket.ts # Socket.io singleton + room management
β β βββ stacksConfig.ts # Network config (mainnet/testnet)
β βββ api/
β βββ parseApi.ts # AI parsing endpoint calls
β βββ approvalApi.ts # Presence + approval API calls
β
βββ backend/ # Express + TypeScript
β βββ routes/
β β βββ parse.ts # POST /parse β AI contract extraction
β β βββ agreement.ts # Agreement presence, approvals, milestones
β β βββ arbitrate.ts # Dispute open/submit/verdict/resolve
β βββ models/
β β βββ Agreement.ts # MongoDB schema
β β βββ Dispute.ts # Dispute schema + mem-store fallback
β βββ lib/
β βββ groq-client.ts # Groq API client
β βββ ai-config.ts # Model configuration
β βββ redis.ts # Redis presence store
β βββ db.ts # MongoDB connection
β
βββ contracts/ # Clarity smart contracts
βββ escrow.clar # Main escrow contract
βββ sip010-trait.clar # sBTC token trait
- Node.js 18+
- Leather Wallet browser extension
- MongoDB (local or Atlas)
- Redis (local or Upstash)
- Groq API key β console.groq.com
git clone https://github.com/AymaanPathan/ClauseAI.git
cd ClauseAIcd backend
npm install
# Create .env
cp .env.example .envPORT=8000
MONGODB_URI=mongodb://localhost:27017/clauseai
REDIS_URL=redis://localhost:6379
GROQ_API_KEY=your_groq_api_key
STACKS_NETWORK=testnet
FRONTEND_URL=http://localhost:3000npm run devcd frontend
npm install
# Create .env.local
cp .env.example .env.localNEXT_PUBLIC_BACKEND_URL=http://localhost:8000
NEXT_PUBLIC_STACKS_NETWORK=testnetnpm run dev# Install Clarinet
curl -L https://github.com/hirosystems/clarinet/releases/download/v2.0.0/clarinet-linux-x64.tar.gz | tar xz
# Deploy to testnet
clarinet deployments apply --testnetThe Clarity escrow contract manages the full lifecycle:
States: PENDING β ACTIVE β COMPLETE / REFUNDED
β β
DISPUTED (per milestone)
Milestone States: PENDING β ACTIVE β COMPLETE
β DISPUTED β COMPLETE / REFUNDED
β REFUNDED (timeout)
Core Functions:
| Function | Who calls it | What it does |
|---|---|---|
create-agreement |
Party A | Deploys contract with all terms |
deposit |
Party A | Locks sBTC, activates milestones |
complete-milestone |
Party A | Releases tranche to Party B |
dispute-milestone |
Either party | Freezes milestone, opens arbitration |
resolve-to-receiver |
Arbitrator | Releases disputed funds to Party B |
resolve-to-payer |
Arbitrator | Refunds disputed funds to Party A |
trigger-milestone-timeout |
Anyone | Auto-refund after deadline passes |
trigger-arb-timeout |
Anyone | Auto-refund if arbitrator inactive 48hrs |
| Segment | Market Size |
|---|---|
| Global Freelance Market | $1.5 Trillion |
| Real Estate Deposits | $500B+ |
| Trade Finance | $9 Trillion |
| Prediction Markets | $100B+ |
ClauseAI is infrastructure β the legal layer that Bitcoin has never had. Not DeFi speculation. Actual economic activity, enforced by the most secure blockchain on earth.
Anyone with a Leather wallet and 60 seconds can create a legally-structured, Bitcoin-enforced escrow. No lawyers. No platforms. No trust required.
This project was built for the Stacks BUIDL Battle #2 Hackathon β The Bitcoin Builders Tournament.
Why ClauseAI wins on judging criteria:
- Innovation β First AI-parsed, milestone-based escrow on Bitcoin. First AI judge on Stacks.
- Technical Depth β Clarity contracts + sBTC + LLM parsing + Socket.io + SSE + Redis. Full stack.
- Stacks Alignment β Uses Clarity, sBTC, Proof of Transfer, Stacks.js, Leather wallet.
- UX β Plain English in. Bitcoin-enforced contract out. Zero crypto knowledge required.
- Impact β Unlocks Bitcoin for real commerce. $1.5T addressable market on day one.
Pull requests are welcome. For major changes, please open an issue first.
- Fork the repo
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
ClauseAI β Smart contracts for everyone, enforced by Bitcoin.
Live Demo Β· GitHub Β· Report Bug
Built with βΏ on Stacks