Decentralized marketplace for AI agent services using Chainlink CRE workflows, an on-chain workflow registry, and x402-style micropayment execution through a payment vault.
- What is AgentMarket?
- Architecture
- Repository Structure
- Tech Stack
- How the End-to-End Flow Works
- Prerequisites
- Configuration
- Quick Start (Local Demo)
- On-Chain Deployment & Seeding
- Running the CRE Workflows
- Frontend Usage Guide
- Backend API Reference
- Smart Contracts
- Development Commands
- Troubleshooting
- Security Notes
- Deployed Addresses
- Chainlink Usage
- Roadmap Ideas
AgentMarket enables an autonomous buyer agent to:
- Discover available services (workflows) from an on-chain registry
- Select one service based on task + budget using an LLM
- Execute a payment through a vault contract
- Call the selected service endpoint with payment proof
- Return final response back to the caller
Core idea: programmable service discovery + programmable payment + verifiable on-chain accounting.
sequenceDiagram
participant User as User / Agent Client
participant FE as Next.js Frontend
participant BE as Express Backend
participant ORCH as CRE Orchestrator
participant REG as WorkflowRegistry (Sepolia)
participant VAULT as AgentPaymentVault (Sepolia)
participant SVC as CRE Service Workflow
participant LLM as OpenRouter
User->>FE: Open marketplace / run task
FE->>BE: API request
BE->>REG: listActive() / publishWorkflow()
User->>BE: POST /api/agent/run
BE->>ORCH: Forward request (if configured)
ORCH->>REG: listActive()
ORCH->>LLM: select best workflow
ORCH->>BE: POST /api/x402/initiate
BE->>VAULT: executePayment(workflowId, agent)
VAULT->>REG: recordInvocation(...)
ORCH->>SVC: invoke selected endpoint + receipt
SVC->>LLM: solve task
SVC-->>ORCH: result
ORCH-->>BE: result + tx hash
BE-->>FE: response payload
.
├── contracts/ # Solidity contracts
│ ├── WorkflowRegistry.sol
│ └── AgentPaymentVault.sol
├── scripts/ # Hardhat scripts for deploy/seed
│ ├── deploy.ts
│ └── seed-registry.ts
├── backend/ # Express API (registry, x402, agent)
│ └── src/routes/
├── frontend/ # Next.js 15 marketplace UI
│ └── app/
└── cre-workflows/ # Chainlink CRE workflows
├── orchestrator/
├── example-service/
└── test-workflow/
- Contracts: Solidity 0.8.24, OpenZeppelin v5, Hardhat
- Backend: Node.js, TypeScript, Express, ethers v6
- Frontend: Next.js 15, React 19, Tailwind CSS, wagmi/viem
- Workflow Runtime: Chainlink CRE SDK (
@chainlink/cre-sdk) - LLM Provider: OpenRouter (Gemini model configured in workflows)
- Network: Ethereum Sepolia
- Frontend calls
POST /api/registry/publish - Backend calls
WorkflowRegistry.publishWorkflow(...) - Contract emits
WorkflowPublished
- Frontend posts to
POST /api/agent/run - If
CRE_ORCHESTRATOR_URLis set: backend forwards request to orchestrator - If not set: backend returns simulation response
- Reads active workflows on-chain via
EVMClient - Filters by
maxBudgetUSDC - Uses LLM to choose
selectedId
- Orchestrator calls backend
POST /api/x402/initiate - Backend signer invokes
AgentPaymentVault.executePayment - Vault transfers USDC and calls
recordInvocationin registry
- Orchestrator invokes selected endpoint with
X-Payment-Receipt - Service workflow processes task and returns answer payload
- Node.js 20+
- npm 10+
- Git
- Wallet/private key for Sepolia deployment
- Sepolia ETH for gas
- Sepolia USDC (for deposit/payment testing)
- Chainlink CRE CLI (
cre)
Install CRE CLI (see official docs for latest installer):
curl -sSL https://cre.chain.link/install.sh | bashCreate a root .env file (do not commit real secrets):
# Wallet / chain
PRIVATE_KEY=0x...
OWNER_ADDRESS=0x...
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/...
ETHERSCAN_API_KEY=...
USDC_SEPOLIA=0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238
# Contract addresses (fill after deploy)
WORKFLOW_REGISTRY_ADDRESS=0x...
AGENT_PAYMENT_VAULT_ADDRESS=0x...
# Backend/frontend wiring
BACKEND_URL=http://localhost:3001
CRE_ORCHESTRATOR_URL=
NEXT_PUBLIC_BACKEND_URL=http://localhost:3001
NEXT_PUBLIC_REGISTRY_ADDRESS=0x...
NEXT_PUBLIC_CHAIN_ID=11155111
# Model provider
OPENROUTER_API_KEY=sk-or-...
GEMINI_API_KEY=...Also mirror required runtime values into package-level env files used by each app process:
backend/.env(for Express server)frontend/.env.local(for Next.js, especiallyNEXT_PUBLIC_*values)cre-workflows/.env(for workflow simulation/deploy scripts)
cre-workflows/ uses:
cre.yamlproject.yamlsecrets.yaml- per-workflow
workflow.yaml+workflow.ts
Ensure owner address, RPC URL, and secret mappings are aligned with your environment before simulation/deployment.
This path gives you a full UI + backend + contract interactions locally, with simulation fallback if orchestrator URL is not set.
# root (hardhat + scripts)
npm install
# backend
cd backend && npm install
# frontend
cd ../frontend && npm install
# cre workflows
cd ../cre-workflows && npm installcd ..
npm run compilecd backend
npm run devBackend runs on http://localhost:3001 by default.
cd ../frontend
npm run devFrontend runs on http://localhost:3000.
- Open marketplace (
/) - Connect wallet (Sepolia)
- Publish a workflow (
/publish) - Run agent task (
/agent)
If CRE_ORCHESTRATOR_URL is unset, /api/agent/run returns simulation output so UI flow still works.
From repository root:
npm run deployScript actions:
- Deploys
WorkflowRegistry - Deploys
AgentPaymentVaultwithUSDC_SEPOLIA+ registry address - Sets registry payment vault
- Sets vault CRE relayer to deployer
- Writes
deployments.json
npm run seedThis publishes sample rows in scripts/seed-registry.ts to your deployed registry.
From cre-workflows/:
npm run simulate:orchestratornpm run simulate:servicecre login
npm run deploy:all-
orchestrator/workflow.ts
- Reads on-chain registry
- Uses LLM to select best workflow within budget
- Initiates payment via backend x402 endpoint
- Invokes selected workflow endpoint
-
example-service/workflow.ts
- Accepts task input (+ optional payment receipt header)
- Uses confidential HTTP call to LLM provider
- Returns generated answer payload
- Reads from
GET /api/registry - Shows workflow metadata (price, reputation, invocations)
- Requires connected wallet
- Sends
name,description,endpoint,priceUSDC - Displays tx hash and workflow ID on success
- Fetches balance from
/api/x402/balance/:agentAddress - Sends task + max budget to
/api/agent/run - Displays selected workflow, quality score, cost, and result
Base URL: http://localhost:3001
-
GET /api/registry- Returns all active workflows from contract
-
GET /api/registry/:id- Returns single workflow by ID
-
POST /api/registry/publish- Body:
{ "name": "DeFi Yield Summarizer", "description": "Fetches APYs", "endpoint": "http://localhost:3001/api/agent/cre-service-mock", "priceUSDC": 0.01 }
- Body:
-
GET /api/x402/balance/:agentAddress- Reads vault deposit balance for address
-
POST /api/x402/initiate- Body:
{ "workflowId": "0x...", "agentAddress": "0x..." } - Executes
executePaymentas backend signer/relayer
- Body:
-
POST /api/agent/run- Body:
{ "task": "Find top DeFi opportunities", "agentAddress": "0x...", "maxBudgetUSDC": 0.05 } - Forwards to orchestrator if configured, else simulation payload
- Body:
-
POST /api/agent/log-invocation- In-memory invocation logging
-
GET /api/agent/history- Returns latest in-memory invocation logs
-
POST /api/agent/cre-service-mock- Mock service endpoint that requires
x-payment-receiptheader
- Mock service endpoint that requires
- Publishes workflow metadata with unique workflow ID
- Stores owner, endpoint, price, reputation, invocation count
- Lists active workflows
- Accepts invocation recording only from configured payment vault
- Stores user deposits in USDC
- Allows deposit and withdrawal
- Restricts payment execution to
creRelayer - Deducts workflow price from agent deposit
- Transfers owner payout + protocol fee (2% to contract owner)
- Calls registry
recordInvocation(workflowId, true)
npm run compile # hardhat compile
npm run test # hardhat test
npm run deploy # deploy to sepolia
npm run seed # seed registry entriescd backend
npm run dev
npm run build
npm run startcd frontend
npm run dev
npm run build
npm run start
npm run lintcd cre-workflows
npm run build
npm run simulate:orchestrator
npm run simulate:service
npm run deploy:all- Increase
maxBudgetUSDC - Seed/publish workflows with lower price
- Verify registry address points to populated contract
- Deposit USDC into vault for
agentAddress - Confirm
workflow.priceUSDCand deposit units (micro-USDC) are correct - For local demo, owner address may receive a dummy tx hash in demo-mode path
- Check backend is running on
:3001 - Set
FRONTEND_URLin backend environment if not usinghttp://localhost:3000 - Verify
NEXT_PUBLIC_BACKEND_URLin frontend environment
- Ensure
creCLI is installed and authenticated - Verify
OPENROUTER_API_KEY/secret mapping - Confirm workflow YAML paths and target IDs are valid
- Never commit real private keys or API keys.
- Rotate any secrets that were ever committed to source control.
- Restrict backend signer privileges and separate hot/cold wallets.
- Add request authentication and rate limiting to backend routes before production.
- Validate workflow endpoints and add allowlists to reduce SSRF risk.
- Consider replacing in-memory history with durable audited storage.
| Contract | Network | Address |
|---|---|---|
| WorkflowRegistry | Sepolia | 0x5d019f68DCD9792afb242eec64074558fBd6b10B |
| AgentPaymentVault | Sepolia | 0x19840C7000a49f2CeeffC9A14a47A8CfA979e479 |
| USDC (Mock) | Sepolia | 0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238 |
This project leverages Chainlink CRE (Confidential Runtime Environment) as the backbone for its autonomous agent orchestration and service execution.
| Usage Type | Description | Link to Code |
|---|---|---|
| On-Chain Discovery | Using EVMClient within CRE to fetch available services from the registry contract. |
cre-workflows/orchestrator/workflow.ts#L85 |
| Verifiable Orchestration | Using consensusIdenticalAggregation to coordinate LLM-based service selection across CRE nodes. |
cre-workflows/orchestrator/workflow.ts#L131 |
| Confidential APIs | Utilizing ConfidentialHTTPClient to securely interact with LLM providers without exposing API keys. |
cre-workflows/example-service/workflow.ts#L59 |
Built for autonomous agent commerce on Chainlink CRE + Sepolia.