✓ Verified 💻 Development ✓ Enhanced Data

Haggle Protocol

On-chain negotiation protocol for AI agents.

Rating
4.9 (403 reviews)
Downloads
3,627 downloads
Version
1.0.0

Overview

On-chain negotiation protocol for AI agents.

Complete Documentation

View Source →

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

ChainNetworkContractToken
BaseMainnet0xB77B5E932de5e5c6Ad34CB4862E33CD634045514USDC (0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913)
SolanaDevnetDRXGcVHj1GZSc7wD4LTnrM8RJ1shWH93s1zKCXtJtGbqSPL Token
MonadTestnet0x30FD25bAB859D8D68de6A0719983bb75200b1CeCMockERC20
BaseSepolia0x30FD25bAB859D8D68de6A0719983bb75200b1CeCMockERC20
ArbitrumSepolia0x30FD25bAB859D8D68de6A0719983bb75200b1CeCMockERC20
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

text
1. Buyer deposits escrow (USDC) into protocol-controlled vault
2. Seller accepts the negotiation invitation
3. Both parties submit alternating offers (turn-based, enforced on-chain)
4. Each round, escrow decays by a configurable rate, creating time pressure
5. Either party accepts the counterparty's offer -> settlement and payout

Setup

Option 1: MCP Server (Recommended)

Install the MCP server for full agent integration:

bash
npm install -g @haggle-protocol/[email protected]

Configure with your private key (see "Private Key Safety" section below):

bash
export HAGGLE_PRIVATE_KEY="0x..."   # EVM private key

Run:

bash
npx @haggle-protocol/[email protected]

Option 2: TypeScript SDK

bash
npm install @haggle-protocol/[email protected]    # For Base/Monad/Arbitrum
npm install @haggle-protocol/[email protected]  # For Solana
npm install @haggle-protocol/[email protected]    # Shared types

Option 3: REST API

bash
npx @haggle-protocol/[email protected]

Private Key Safety

This skill requires HAGGLE_PRIVATE_KEY to sign on-chain transactions. This is a sensitive credential. Follow these practices:

  • 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)

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.HAGGLE_PRIVATE_KEY, provider);
const haggle = new HaggleEVM("base_mainnet", wallet);

// 1. Approve USDC (approve only what you need)
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. Create negotiation
const negId = await haggle.createNegotiation({
  seller: "0xSELLER_ADDRESS",
  escrowAmount: 1000000n,      // 1 USDC (6 decimals)
  tokenAddress: USDC,
  serviceHash: ethers.keccak256(ethers.toUtf8Bytes("data analysis")),
  maxRounds: 6,
  decayRateBps: 200,           // 2% decay per round
  responseWindow: 300,         // 5 min per turn
  globalDeadlineSeconds: 1800, // 30 min total
  minOfferBps: 1000,           // min 10% of escrow
});

// 3. Submit offer
await haggle.submitOffer(negId, 500000n); // Offer 0.5 USDC

Seller Workflow

typescript
// 1. Accept invitation
await haggle.acceptInvitation(negId);

// 2. Counter-offer
await haggle.submitOffer(negId, 800000n); // Counter at 0.8 USDC

// 3. Accept buyer's offer (triggers settlement)
await haggle.acceptOffer(negId);

Reading Negotiation State

typescript
const neg = await haggle.getNegotiation(negId);

console.log("Status:", neg.status);
console.log("Round:", neg.currentRound);
console.log("Current Offer:", ethers.formatUnits(neg.currentOfferAmount, 6), "USDC");
console.log("Effective Escrow:", ethers.formatUnits(neg.effectiveEscrow, 6), "USDC");

MCP Server Tools

When using the MCP server, these tools are available:

ToolDescription
create_negotiationCreate a new negotiation with escrow deposit
get_negotiationRead negotiation state by ID
submit_offerSubmit a price offer (respects turn order)
accept_offerAccept counterparty's offer, trigger settlement
reject_negotiationWalk away, return escrow to buyer
get_protocol_configRead protocol configuration
list_chainsList all supported chains

Key Parameters

ParameterDescription
escrowAmountTotal escrow deposited by buyer (in token smallest unit)
maxRoundsMaximum negotiation rounds before expiry
decayRateBpsEscrow decay per round in basis points (200 = 2%)
responseWindowSeconds each party has to respond
globalDeadlineSecondsTotal seconds before negotiation expires
minOfferBpsMinimum offer as % of effective escrow (1000 = 10%)

Settlement Math

text
protocolFee    = settledAmount * 50 / 10000  (0.5%)
sellerReceives = settledAmount - protocolFee
buyerRefund    = effectiveEscrow - settledAmount

Negotiation Strategy Tips

  • 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:

EndpointData SentPurpose
https://mainnet.base.orgSigned transactions, view callsBase Mainnet RPC
https://sepolia.base.orgSigned transactions, view callsBase Sepolia RPC
https://api.devnet.solana.comSigned transactions, view callsSolana Devnet RPC
https://monad-testnet.drpc.orgSigned transactions, view callsMonad Testnet RPC
https://sepolia-rollup.arbitrum.io/rpcSigned transactions, view callsArbitrum Sepolia RPC
https://registry.npmjs.orgPackage metadatanpm 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

Installation

Terminal bash

openclaw install haggle-protocol
    
Copied!

💻Code Examples

5. Either party accepts the counterparty's offer -> settlement and payout

5-either-party-accepts-the-counterpartys-offer---settlement-and-payout.txt
## Setup

### Option 1: MCP Server (Recommended)

Install the MCP server for full agent integration:

npx @haggle-protocol/[email protected]

npx-haggle-protocolapi010.txt
## 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.
2. **Fund minimally** - Only deposit the amount you plan to negotiate with (e.g., a few USDC + gas).
3. **Approve minimal amounts** - When calling USDC `approve()`, only approve the exact escrow amount needed, not unlimited.
4. **Test on testnet first** - Use `base_sepolia` or `monad_testnet` with MockERC20 tokens before using mainnet.
5. **Monitor your wallet** - Watch your agent wallet on https://basescan.org for unexpected transactions.
6. **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)

console.log("Effective Escrow:", ethers.formatUnits(neg.effectiveEscrow, 6), "USDC");

consolelogeffective-escrow-ethersformatunitsnegeffectiveescrow-6-usdc.txt
## MCP Server Tools

When using the MCP server, these tools are available:

| Tool | Description |
|------|-------------|
| `create_negotiation` | Create a new negotiation with escrow deposit |
| `get_negotiation` | 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 |
|-----------|-------------|
| `escrowAmount` | Total escrow deposited by buyer (in token smallest unit) |
| `maxRounds` | 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
example.txt
1. Buyer deposits escrow (USDC) into protocol-controlled vault
2. Seller accepts the negotiation invitation
3. Both parties submit alternating offers (turn-based, enforced on-chain)
4. Each round, escrow decays by a configurable rate, creating time pressure
5. Either party accepts the counterparty's offer -> settlement and payout
example.sh
npm install @haggle-protocol/[email protected]    # For Base/Monad/Arbitrum
npm install @haggle-protocol/[email protected]  # For Solana
npm install @haggle-protocol/[email protected]    # Shared types
example.ts
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.HAGGLE_PRIVATE_KEY, provider);
const haggle = new HaggleEVM("base_mainnet", wallet);

// 1. Approve USDC (approve only what you need)
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. Create negotiation
const negId = await haggle.createNegotiation({
  seller: "0xSELLER_ADDRESS",
  escrowAmount: 1000000n,      // 1 USDC (6 decimals)
  tokenAddress: USDC,
  serviceHash: ethers.keccak256(ethers.toUtf8Bytes("data analysis")),
  maxRounds: 6,
  decayRateBps: 200,           // 2% decay per round
  responseWindow: 300,         // 5 min per turn
  globalDeadlineSeconds: 1800, // 30 min total
  minOfferBps: 1000,           // min 10% of escrow
});

// 3. Submit offer
await haggle.submitOffer(negId, 500000n); // Offer 0.5 USDC
example.ts
// 1. Accept invitation
await haggle.acceptInvitation(negId);

// 2. Counter-offer
await haggle.submitOffer(negId, 800000n); // Counter at 0.8 USDC

// 3. Accept buyer's offer (triggers settlement)
await haggle.acceptOffer(negId);
example.ts
const neg = await haggle.getNegotiation(negId);

console.log("Status:", neg.status);
console.log("Round:", neg.currentRound);
console.log("Current Offer:", ethers.formatUnits(neg.currentOfferAmount, 6), "USDC");
console.log("Effective Escrow:", ethers.formatUnits(neg.effectiveEscrow, 6), "USDC");
example.txt
protocolFee    = settledAmount * 50 / 10000  (0.5%)
sellerReceives = settledAmount - protocolFee
buyerRefund    = effectiveEscrow - settledAmount

Tags

#ai_and-llms

Quick Info

Category Development
Model Claude 3.5
Complexity Multi-Agent
Author eijiac24
Last Updated 3/10/2026
🚀
Optimized for
Claude 3.5
🧠

Ready to Install?

Get started with this skill in seconds

openclaw install haggle-protocol