Haggle Protocol
The first on-chain negotiation protocol for autonomous AI agents.
Haggle Protocol enables two AI agents to negotiate a fair price through multi-round alternating offers with escrow decay. Instead of fixed pricing, agents discover fair prices through dynamic bargaining.
Use it when: You need to buy or sell a service from another agent but don't know the fair price.
Deployments
| Chain | Network | Contract | Token |
|---|
| Base | Mainnet | INLINECODE0 | USDC (0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913) |
| Solana |
Devnet |
DRXGcVHj1GZSc7wD4LTnrM8RJ1shWH93s1zKCXtJtGbq | SPL Token |
| Monad | Testnet |
0x30FD25bAB859D8D68de6A0719983bb75200b1CeC | MockERC20 |
| Base | Sepolia |
0x30FD25bAB859D8D68de6A0719983bb75200b1CeC | MockERC20 |
| Arbitrum | Sepolia |
0x30FD25bAB859D8D68de6A0719983bb75200b1CeC | MockERC20 |
You can verify these contract addresses independently on their respective block explorers:
- - Base Mainnet: https://basescan.org/address/0xB77B5E932de5e5c6Ad34CB4862E33CD634045514
- Solana Devnet: https://explorer.solana.com/address/DRXGcVHj1GZSc7wD4LTnrM8RJ1shWH93s1zKCXtJtGbq?cluster=devnet
How It Works
CODEBLOCK0
Setup
Option 1: MCP Server (Recommended)
Install the MCP server for full agent integration:
CODEBLOCK1
Configure with your private key (see "Private Key Safety" section below):
CODEBLOCK2
Run:
CODEBLOCK3
Option 2: TypeScript SDK
CODEBLOCK4
Option 3: REST API
CODEBLOCK5
Private Key Safety
This skill requires HAGGLE_PRIVATE_KEY to sign on-chain transactions. This is a sensitive credential. Follow these practices:
- 1. Use a dedicated wallet - Create a separate wallet for agent operations. Do NOT use your main wallet.
- Fund minimally - Only deposit the amount you plan to negotiate with (e.g., a few USDC + gas).
- Approve minimal amounts - When calling USDC
approve(), only approve the exact escrow amount needed, not unlimited. - Test on testnet first - Use
base_sepolia or monad_testnet with MockERC20 tokens before using mainnet. - Monitor your wallet - Watch your agent wallet on https://basescan.org for unexpected transactions.
- Rotate keys - If you suspect a compromise, transfer funds out and generate a new key immediately.
The private key is loaded from an environment variable and never logged, transmitted, or stored by the skill. All signing happens locally via ethers.js. You can audit the source code at https://github.com/haggle-protocol.
Buyer Workflow (Base Mainnet)
CODEBLOCK6
Seller Workflow
CODEBLOCK7
Reading Negotiation State
CODEBLOCK8
MCP Server Tools
When using the MCP server, these tools are available:
| Tool | Description |
|---|
| INLINECODE10 | Create a new negotiation with escrow deposit |
| INLINECODE11 |
Read negotiation state by ID |
|
submit_offer | Submit a price offer (respects turn order) |
|
accept_offer | Accept counterparty's offer, trigger settlement |
|
reject_negotiation | Walk away, return escrow to buyer |
|
get_protocol_config | Read protocol configuration |
|
list_chains | List all supported chains |
Key Parameters
| Parameter | Description |
|---|
| INLINECODE17 | Total escrow deposited by buyer (in token smallest unit) |
| INLINECODE18 |
Maximum negotiation rounds before expiry |
|
decayRateBps | Escrow decay per round in basis points (200 = 2%) |
|
responseWindow | Seconds each party has to respond |
|
globalDeadlineSeconds | Total seconds before negotiation expires |
|
minOfferBps | Minimum offer as % of effective escrow (1000 = 10%) |
Settlement Math
CODEBLOCK9
Negotiation Strategy Tips
- 1. Start with anchoring - Open with an aggressive but reasonable first offer
- Concede gradually - Small concessions signal firmness
- Watch the decay - Each round costs both parties
- Monitor effectiveEscrow - As it decays, the viable offer range narrows
External Endpoints
This skill connects to the following RPC endpoints to submit and read blockchain transactions:
| Endpoint | Data Sent | Purpose |
|---|
| INLINECODE23 | Signed transactions, view calls | Base Mainnet RPC |
| INLINECODE24 |
Signed transactions, view calls | Base Sepolia RPC |
|
https://api.devnet.solana.com | Signed transactions, view calls | Solana Devnet RPC |
|
https://monad-testnet.drpc.org | Signed transactions, view calls | Monad Testnet RPC |
|
https://sepolia-rollup.arbitrum.io/rpc | Signed transactions, view calls | Arbitrum Sepolia RPC |
|
https://registry.npmjs.org | Package metadata | npm install (setup only) |
No data is sent to any other endpoints. No analytics, telemetry, or tracking of any kind.
Security & Privacy
- - Local signing only - All transactions are signed locally using ethers.js. Your private key never leaves your machine.
- No telemetry - No data is sent to third-party analytics, tracking, or logging services.
- Open source - All smart contracts and SDK code are publicly auditable at https://github.com/haggle-protocol
- Numeric offers only - All offers are uint256 amounts. No free-text input, eliminating prompt injection risk.
- Contract-controlled escrow - Funds are held in on-chain contract vaults. No single party can rug pull.
- Turn-based enforcement - On-chain logic enforces alternating offers. Cannot submit out of turn.
- Permissionless expiry - Expired negotiations can be settled by anyone, so funds cannot get stuck.
- Owner pausable - The protocol owner can pause the contract in case of emergency.
- Not audited - The smart contracts have NOT been formally audited. Use at your own risk and start with small amounts.
Links
- - Website: https://haggle.dev
- GitHub: https://github.com/haggle-protocol
- Base Dashboard: https://haggle.dev/base
- npm: https://www.npmjs.com/org/haggle-protocol
- BaseScan: https://basescan.org/address/0xB77B5E932de5e5c6Ad34CB4862E33CD634045514
技能名称: haggle-protocol
讨价还价协议
首个面向自主AI代理的链上协商协议。
讨价还价协议使两个AI代理能够通过多轮交替报价和托管衰减机制,协商出公平价格。代理通过动态讨价还价发现公平价格,而非采用固定定价。
适用场景: 当你需要向另一个代理购买或出售服务,但不确定公平价格时。
部署信息
| 链 | 网络 | 合约地址 | 代币 |
|---|
| Base | 主网 | 0xB77B5E932de5e5c6Ad34CB4862E33CD634045514 | USDC (0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913) |
| Solana |
Devnet | DRXGcVHj1GZSc7wD4LTnrM8RJ1shWH93s1zKCXtJtGbq | SPL Token |
| Monad | Testnet | 0x30FD25bAB859D8D68de6A0719983bb75200b1CeC | MockERC20 |
| Base | Sepolia | 0x30FD25bAB859D8D68de6A0719983bb75200b1CeC | MockERC20 |
| Arbitrum | Sepolia | 0x30FD25bAB859D8D68de6A0719983bb75200b1CeC | MockERC20 |
您可以在各自的区块链浏览器上独立验证这些合约地址:
- - Base主网:https://basescan.org/address/0xB77B5E932de5e5c6Ad34CB4862E33CD634045514
- Solana Devnet:https://explorer.solana.com/address/DRXGcVHj1GZSc7wD4LTnrM8RJ1shWH93s1zKCXtJtGbq?cluster=devnet
工作原理
- 1. 买方将托管资金(USDC)存入协议控制的保险库
- 卖方接受协商邀请
- 双方提交交替报价(基于回合制,链上强制执行)
- 每轮托管资金按可配置的衰减率减少,制造时间压力
- 任何一方接受对方的报价 -> 结算并支付
设置
选项1:MCP服务器(推荐)
安装MCP服务器以实现完整的代理集成:
bash
npm install -g @haggle-protocol/mcp@0.2.0
使用您的私钥进行配置(请参阅下面的私钥安全部分):
bash
export HAGGLEPRIVATEKEY=0x... # EVM私钥
运行:
bash
npx @haggle-protocol/mcp@0.2.0
选项2:TypeScript SDK
bash
npm install @haggle-protocol/evm@0.1.0 # 用于Base/Monad/Arbitrum
npm install @haggle-protocol/solana@0.1.0 # 用于Solana
npm install @haggle-protocol/core@0.1.0 # 共享类型
选项3:REST API
bash
npx @haggle-protocol/api@0.1.0
私钥安全
此技能需要HAGGLEPRIVATEKEY来签署链上交易。这是一个敏感凭证。请遵循以下实践:
- 1. 使用专用钱包 - 为代理操作创建一个单独的钱包。不要使用您的主钱包。
- 最小化资金 - 仅存入您计划用于协商的金额(例如,少量USDC + gas费)。
- 批准最小金额 - 调用USDC approve()时,仅批准所需的精确托管金额,而非无限额。
- 先在测试网上测试 - 在主网使用前,先在basesepolia或monadtestnet上使用MockERC20代币进行测试。
- 监控您的钱包 - 在https://basescan.org上监控您的代理钱包,留意异常交易。
- 轮换密钥 - 如果您怀疑密钥泄露,请立即转移资金并生成新密钥。
私钥从环境变量加载,技能不会记录、传输或存储私钥。所有签名均通过ethers.js在本地完成。您可以在https://github.com/haggle-protocol审计源代码。
买方工作流程(Base主网)
typescript
import { HaggleEVM } from @haggle-protocol/evm;
import { ethers } from ethers;
const provider = new ethers.JsonRpcProvider(https://mainnet.base.org);
const wallet = new ethers.Wallet(process.env.HAGGLEPRIVATEKEY, provider);
const haggle = new HaggleEVM(base_mainnet, wallet);
// 1. 批准USDC(仅批准所需金额)
const USDC = 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913;
const usdc = new ethers.Contract(USDC, [
function approve(address,uint256) returns (bool)
], wallet);
await (await usdc.approve(haggle.contractAddress, 1000000n)).wait(); // 1 USDC
// 2. 创建协商
const negId = await haggle.createNegotiation({
seller: 0xSELLER_ADDRESS,
escrowAmount: 1000000n, // 1 USDC(6位小数)
tokenAddress: USDC,
serviceHash: ethers.keccak256(ethers.toUtf8Bytes(data analysis)),
maxRounds: 6,
decayRateBps: 200, // 每轮衰减2%
responseWindow: 300, // 每轮5分钟
globalDeadlineSeconds: 1800, // 总计30分钟
minOfferBps: 1000, // 最低为托管金额的10%
});
// 3. 提交报价
await haggle.submitOffer(negId, 500000n); // 报价0.5 USDC
卖方工作流程
typescript
// 1. 接受邀请
await haggle.acceptInvitation(negId);
// 2. 还价
await haggle.submitOffer(negId, 800000n); // 还价0.8 USDC
// 3. 接受买方报价(触发结算)
await haggle.acceptOffer(negId);
读取协商状态
typescript
const neg = await haggle.getNegotiation(negId);
console.log(状态:, neg.status);
console.log(轮次:, neg.currentRound);
console.log(当前报价:, ethers.formatUnits(neg.currentOfferAmount, 6), USDC);
console.log(有效托管金额:, ethers.formatUnits(neg.effectiveEscrow, 6), USDC);
MCP服务器工具
使用MCP服务器时,可使用以下工具:
| 工具 | 描述 |
|---|
| createnegotiation | 创建新的协商并存入托管资金 |
| getnegotiation |
按ID读取协商状态 |
| submit_offer | 提交价格报价(遵循轮次顺序) |
| accept_offer | 接受对方报价,触发结算 |
| reject_negotiation | 退出协商,将托管资金返还给买方 |
| get
protocolconfig | 读取协议配置 |
| list_chains | 列出所有支持的链 |
关键参数
| 参数 | 描述 |
|---|
| escrowAmount | 买方存入的总托管金额(以代币最小单位计) |
| maxRounds |
到期前的最大协商轮数 |
| decayRateBps | 每轮托管衰减率,以基点计(200 = 2%) |
| responseWindow | 各方响应的秒数 |
| globalDeadlineSeconds | 协商到期前的总秒数 |
| minOfferBps | 最低报价占有效托管金额的百分比(1000 = 10%) |
结算计算
protocolFee = settledAmount * 50 / 10000 (0.5%)
sellerReceives = settledAmount - protocolFee
buyerRefund = effectiveEscrow - settledAmount
协商策略提示
- 1. 从锚定开始 - 以激进但合理的首次报价开场
- 逐步让步 - 小幅让步表明立场坚定
- 关注衰减 - 每轮都会让双方付出代价
- 监控有效托管金额 - 随着衰减,可行的报价范围会缩小
外部端点
此技能连接到以下RPC端点以提交和读取区块链交易:
| 端点 |