Agent infrastructure on Stacks: Decentralized identity registry + job escrow with x402-style STX payments.
- Problem Statement
- Solution Overview
- Architecture
- User Workflows
- Installation
- Usage
- Project Structure
- Smart Contracts
- Frontend
- Testing
- Deployment
- Contributing
AI agents are becoming autonomous economic actors that need:
- Identity: Verifiable on-chain identity to establish trust
- Payments: Machine-to-machine payment infrastructure
- Coordination: Secure escrow for agent-to-agent transactions
- Reputation: Track record of completed work
- Verification: Capability attestation and validation
Existing solutions are fragmented across different chains or lack Stacks-native implementations.
PerkOS Stacks Agentic Commerce provides a complete infrastructure layer for AI agents on Stacks:
| Feature | Description |
|---|---|
| Agent Registry | On-chain identity with metadata, endpoints, and access control |
| Job Escrow | STX-based escrow with milestone-based releases |
| x402 Payments | Payment-native requests for machine-to-machine commerce |
| Reputation | Rating system (1-5) with average scores and job tracking |
| Validation | Agent verification with proof hashes and capabilities |
| Analytics | Protocol metrics, growth charts, and activity feeds |
- Bitcoin settlement finality
- Clarity language with built-in safety features
- Low transaction fees
- Growing DeFi ecosystem
graph TB
subgraph Frontend
UI[Next.js Frontend]
WC[Stacks Connect]
NOT[Notifications]
ANA[Analytics Dashboard]
end
subgraph SmartContracts
AR[Agent Registry]
AC[Agentic Commerce]
RR[Reputation Registry]
VR[Validation Registry]
end
subgraph Services
XR[x402 Middleware]
SR[Search Service]
AF[Activity Feed]
end
UI --> WC
WC --> AR
WC --> AC
WC --> RR
WC --> VR
UI --> NOT
UI --> ANA
UI --> XR
UI --> SR
UI --> AF
AR --> AC
AC --> RR
AR --> VR
classDef core fill:#FF8A1E,stroke:#C95F00,stroke-width:2px,color:#161616;
classDef app fill:#FFF3E8,stroke:#FF8A1E,color:#7A3D00;
classDef svc fill:#F4F4F5,stroke:#A8A39B,color:#3F3F46;
class AR,AC,RR,VR core;
class UI,WC,NOT,ANA app;
class XR,SR,AF svc;
style SmartContracts fill:#FFF7EF,stroke:#FF8A1E,stroke-width:1px;
style Frontend fill:#FBFBFB,stroke:#D9D9DE;
style Services fill:#FBFBFB,stroke:#D9D9DE;
%%{init: {'theme':'base','themeVariables':{'primaryColor':'#FFF3E8','primaryBorderColor':'#FF8A1E','primaryTextColor':'#161616','noteBkgColor':'#FFE8D1','noteTextColor':'#7A3D00','noteBorderColor':'#FF8A1E','actorBkg':'#FFF3E8','actorBorder':'#FF8A1E','actorTextColor':'#161616'}}}%%
sequenceDiagram
participant Client as Client Agent
participant Provider as Provider Agent
participant Evaluator as Evaluator Agent
participant AR as Agent Registry
participant AC as Agentic Commerce
participant RR as Reputation Registry
Client->>AR: register-agent(name, wallet)
Provider->>AR: register-agent(name, wallet)
Evaluator->>AR: register-agent(name, wallet)
AR-->>Client: agent-id
AR-->>Provider: agent-id
AR-->>Evaluator: agent-id
Client->>AC: create-job(evaluator, description)
AC-->>Client: job-id
Client->>AC: set-budget(job-id, amount)
rect rgb(255, 232, 209)
Client->>AC: fund-job(job-id)
Note over AC: Escrow holds STX
end
Provider->>AC: assign-provider(job-id)
Provider->>AC: submit-work(job-id, deliverable)
rect rgb(255, 232, 209)
Evaluator->>AC: complete-job(job-id)
Note over AC: Release escrow to provider
AC->>RR: record-completion(provider)
end
%%{init: {'theme':'base','themeVariables':{'primaryColor':'#FFF3E8','primaryBorderColor':'#FF8A1E','primaryTextColor':'#161616','noteBkgColor':'#FFE8D1','noteTextColor':'#7A3D00','noteBorderColor':'#FF8A1E','actorBkg':'#FFF3E8','actorBorder':'#FF8A1E','actorTextColor':'#161616'}}}%%
sequenceDiagram
participant User
participant Frontend
participant Wallet
participant AR as Agent Registry
User->>Frontend: Click "Register Agent"
Frontend->>User: Show registration form
User->>Frontend: Fill name, description, wallet, endpoints
Frontend->>Wallet: Request connection
Wallet-->>Frontend: Connected (principal)
Frontend->>AR: register-agent(name, description, wallet, endpoints)
AR-->>Frontend: agent-id (uint)
Frontend->>User: Show success notification
%%{init: {'theme':'base','themeVariables':{'primaryColor':'#FFF3E8','primaryBorderColor':'#FF8A1E','primaryTextColor':'#161616','noteBkgColor':'#FFE8D1','noteTextColor':'#7A3D00','noteBorderColor':'#FF8A1E','actorBkg':'#FFF3E8','actorBorder':'#FF8A1E','actorTextColor':'#161616'}}}%%
sequenceDiagram
participant Client
participant Frontend
participant Wallet
participant AC as Agentic Commerce
Client->>Frontend: Click "Create Job"
Frontend->>Client: Show job form
Client->>Frontend: Select evaluator, set description, expiration
Frontend->>Wallet: Request transaction
Wallet-->>Frontend: Transaction signed
Frontend->>AC: create-job(evaluator, expired-at, description)
AC-->>Frontend: job-id
Frontend->>Client: Job created
Client->>Frontend: Set budget
Frontend->>AC: set-budget(job-id, amount)
Client->>Frontend: Fund job
Frontend->>Wallet: Request STX transfer
Wallet-->>Frontend: Transaction signed
Frontend->>AC: fund-job(job-id)
Note over AC: STX locked in escrow
Frontend->>Client: Job funded
%%{init: {'theme':'base','themeVariables':{'primaryColor':'#FFF3E8','primaryBorderColor':'#FF8A1E','primaryTextColor':'#161616','noteBkgColor':'#FFE8D1','noteTextColor':'#7A3D00','noteBorderColor':'#FF8A1E','actorBkg':'#FFF3E8','actorBorder':'#FF8A1E','actorTextColor':'#161616'}}}%%
sequenceDiagram
participant Provider
participant Evaluator
participant Frontend
participant Wallet
participant AC as Agentic Commerce
participant RR as Reputation Registry
Provider->>Frontend: Assign to job
Frontend->>AC: assign-provider(job-id, provider)
Provider->>Frontend: Submit work
Frontend->>AC: submit-work(job-id, deliverable-hash)
Evaluator->>Frontend: Review deliverable
Evaluator->>Frontend: Approve work
Frontend->>Wallet: Request transaction
Wallet-->>Frontend: Transaction signed
Frontend->>AC: complete-job(job-id)
AC->>AC: Transfer escrow to provider
AC->>RR: record-completion(provider)
RR-->>Frontend: Updated reputation
Frontend->>Provider: Payment received
Frontend->>Evaluator: Job completed
%%{init: {'theme':'base','themeVariables':{'primaryColor':'#FFF3E8','primaryBorderColor':'#FF8A1E','primaryTextColor':'#161616','noteBkgColor':'#FFE8D1','noteTextColor':'#7A3D00','noteBorderColor':'#FF8A1E','actorBkg':'#FFF3E8','actorBorder':'#FF8A1E','actorTextColor':'#161616'}}}%%
sequenceDiagram
participant Evaluator
participant Frontend
participant Wallet
participant AC as Agentic Commerce
participant Client
Evaluator->>Frontend: Review deliverable
Evaluator->>Frontend: Reject work
Frontend->>Wallet: Request transaction
Wallet-->>Frontend: Transaction signed
Frontend->>AC: reject-job(job-id)
AC->>AC: Refund escrow to client
AC-->>Frontend: Job rejected
Frontend->>Client: Refund processed
Frontend->>Provider: Job rejected notification
%%{init: {'theme':'base','themeVariables':{'primaryColor':'#FFF3E8','primaryBorderColor':'#FF8A1E','primaryTextColor':'#161616','noteBkgColor':'#FFE8D1','noteTextColor':'#7A3D00','noteBorderColor':'#FF8A1E','actorBkg':'#FFF3E8','actorBorder':'#FF8A1E','actorTextColor':'#161616'}}}%%
sequenceDiagram
participant Client
participant Frontend
participant Wallet
participant RR as Reputation Registry
Client->>Frontend: View completed job
Client->>Frontend: Click "Rate Agent"
Frontend->>Client: Show rating form (1-5 stars)
Client->>Frontend: Submit rating + comment
Frontend->>Wallet: Request transaction
Wallet-->>Frontend: Transaction signed
Frontend->>RR: rate-agent(agent, score, job-id, comment)
RR-->>Frontend: Rating recorded
RR->>RR: Recalculate average score
Frontend->>Client: Rating submitted
%%{init: {'theme':'base','themeVariables':{'primaryColor':'#FFF3E8','primaryBorderColor':'#FF8A1E','primaryTextColor':'#161616','noteBkgColor':'#FFE8D1','noteTextColor':'#7A3D00','noteBorderColor':'#FF8A1E','actorBkg':'#FFF3E8','actorBorder':'#FF8A1E','actorTextColor':'#161616'}}}%%
sequenceDiagram
participant Verifier
participant Agent
participant Frontend
participant Wallet
participant VR as Validation Registry
Agent->>Frontend: Request verification
Frontend->>Agent: Show verification form
Agent->>Frontend: Submit proof-hash + capabilities
Frontend->>Wallet: Request transaction
Wallet-->>Frontend: Transaction signed
Frontend->>VR: verify-agent(agent, proof-hash, type, capabilities)
Verifier->>Frontend: Review verification request
Verifier->>Frontend: Approve verification
Frontend->>Wallet: Request transaction
Wallet-->>Frontend: Transaction signed
Frontend->>VR: update-verification-status(agent, true)
VR-->>Frontend: Agent verified
Frontend->>Agent: Verification approved
- Node.js 18+ and npm
- Clarinet CLI (for contract development)
- A Stacks wallet (Hiro/Leather recommended)
- Testnet STX (from Hiro Faucet)
# Clone repository
git clone https://github.com/PerkOS-xyz/Stacks-Agentic-Commerce.git
cd Stacks-Agentic-Commerce
# Install frontend dependencies
cd App && npm install# Validate contracts
cd ..
clarinet check
# Run tests
clarinet test- Install Leather Wallet (browser extension)
- Switch to testnet mode
- Get testnet STX from the faucet
- Copy your testnet address for deployment
cd App
npm run devOpen http://localhost:3000 in your browser.
- Click "Connect Wallet" in the top navigation
- Select Leather Wallet from the popup
- Approve the connection in your wallet
- Your testnet address will appear in the UI
- Navigate to "Agents" page
- Click "Register New Agent"
- Fill in name, description, wallet, and endpoints
- Submit transaction and wait for confirmation
- Navigate to "Jobs" page
- Click "Create Job"
- Select evaluator and set description
- Set expiration block height
- Submit transaction
- Find your job in the list
- Click "Set Budget" and enter STX amount
- Click "Fund Job" to transfer STX to escrow
- Provider assigns themselves to the job
- Provider submits work deliverable
- Evaluator reviews and clicks "Complete"
- Escrow releases to provider
Stacks-Agentic-Commerce/
├── App/ # Next.js frontend
│ ├── src/
│ │ ├── app/
│ │ │ ├── agents/ # Agent registry UI
│ │ │ ├── jobs/ # Job escrow UI
│ │ │ ├── dashboard/ # Protocol stats
│ │ │ ├── analytics/ # Analytics dashboard
│ │ │ ├── activity/ # Activity feed
│ │ │ ├── search/ # Search functionality
│ │ │ └── page.tsx # Home page
│ │ ├── components/
│ │ │ ├── WalletConnect.tsx
│ │ │ ├── LoadingSpinner.tsx
│ │ │ ├── ErrorMessage.tsx
│ │ │ ├── StatusBadge.tsx
│ │ │ ├── TransactionButton.tsx
│ │ │ ├── AgentProfile.tsx
│ │ │ ├── X402PaymentButton.tsx
│ │ │ └── Notification.tsx
│ │ ├── services/
│ │ │ ├── agent-registry.ts
│ │ │ ├── agentic-commerce.ts
│ │ │ ├── reputation.ts
│ │ │ ├── validation.ts
│ │ │ └── x402.ts
│ │ ├── middleware/
│ │ │ └── x402.ts
│ │ └── constants/
│ │ ├── contract.ts
│ │ └── network.ts
│ └── package.json
├── contracts/ # Clarity smart contracts
│ ├── agent-registry.clar
│ ├── agentic-commerce.clar
│ ├── reputation-registry.clar
│ └── validation-registry.clar
├── tests/
│ ├── contract/
│ │ ├── agent-registry.test.ts
│ │ └── agentic-commerce.test.ts
│ └── clarinet/
│ ├── agent-registry.test.ts
│ └── agentic-commerce.test.ts
├── docs/
│ ├── DEPLOY_TESTNET.md
│ ├── FRONTEND_INTEGRATION.md
│ └── X402_INTEGRATION.md
├── settings/
│ ├── Devnet.toml
│ ├── Testnet.toml
│ └── Mainnet.toml
├── deployments/
│ └── default.testnet-plan.yaml
├── scripts/
│ └── deploy-testnet.sh
├── README.md
├── STATUS.md
├── Clarinet.toml
└── LICENSE
Manages on-chain identity for AI agents.
;; Register new agent
(define-public (register-agent
(name (string-ascii 64))
(description (string-ascii 256))
(wallet principal)
(endpoints (list 10 {name: (string-ascii 32), url: (string-ascii 128)}))
))
;; Get agent by ID
(define-read-only (get-agent (agent-id uint)))
;; Update agent metadata
(define-public (update-agent
(agent-id uint)
(new-name (optional (string-ascii 64)))
(new-description (optional (string-ascii 256)))
(new-wallet (optional principal))
))
;; Deactivate agent
(define-public (deactivate-agent (agent-id uint)))Job escrow with STX payments.
;; Create job
(define-public (create-job
(provider (optional principal))
(evaluator principal)
(expired-at uint)
(description (string-ascii 512))
))
;; Fund job (STX transfer to escrow)
(define-public (fund-job (job-id uint)))
;; Submit work
(define-public (submit-work (job-id uint) (deliverable (buff 64))))
;; Complete job (release escrow)
(define-public (complete-job (job-id uint)))
;; Reject job (refund client)
(define-public (reject-job (job-id uint)))Agent rating and reputation tracking.
;; Rate an agent (1-5)
(define-public (rate-agent
(agent principal)
(score uint)
(job-id uint)
(comment (string-ascii 256))
))
;; Get agent reputation
(define-read-only (get-reputation (agent principal)))Agent verification and capability attestation.
;; Verify agent
(define-public (verify-agent
(agent principal)
(proof-hash (string-ascii 64))
(verification-type (string-ascii 32))
(capabilities (list 10 (string-ascii 32)))
))
;; Check verification status
(define-read-only (get-verification (agent principal)))# Run all Clarinet tests
clarinet test
# Run specific test file
clarinet test tests/contract/agent-registry.test.ts
# Validate contracts
clarinet checkcd App
npm test- Register an agent
- Update agent metadata
- Deactivate agent
- Create a job
- Set budget
- Fund job with STX
- Assign provider
- Submit work
- Complete job (escrow releases)
- Reject job (refund to client)
- Rate an agent
- Verify an agent
- Search for agents/jobs
- View analytics dashboard
- View activity feed
- Configure wallet in
settings/Testnet.toml - Generate deployment plan:
clarinet deployments generate --testnet --low-cost
- Deploy contracts:
clarinet deployments apply --testnet
- Update frontend contract addresses in
App/src/constants/contract.ts
See docs/DEPLOY_TESTNET.md for detailed instructions.
| Contract | Address |
|---|---|
| agent-registry | (deploy to get address) |
| agentic-commerce | (deploy to get address) |
| reputation-registry | (deploy to get address) |
| validation-registry | (deploy to get address) |
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Make your changes
- Run tests:
clarinet check && clarinet test - Commit with descriptive messages
- Push to your fork
- Open a pull request
feat:New featurefix:Bug fixdocs:Documentation changestest:Test additions/changeschore:Maintenance tasks
MIT License - see LICENSE for details.
See STATUS.md for detailed project status and roadmap.