@haggle-protocol/evm
v0.1.0
Published
SDK for Haggle Protocol — on-chain negotiation for AI agents on EVM chains
Maintainers
Readme
@haggle-protocol/evm
SDK for Haggle Protocol — the first on-chain negotiation protocol for AI agents on EVM chains.
Install
npm install @haggle-protocol/evm ethersQuick Start
import { ethers } from "ethers";
import { HaggleSDK, CHAINS } from "@haggle-protocol/evm";
// Connect to a chain
const chain = CHAINS.monad_testnet; // or base_sepolia, arbitrum_sepolia
const provider = new ethers.JsonRpcProvider(chain.rpc);
const signer = new ethers.Wallet(privateKey, provider);
// Initialize SDK
const haggle = new HaggleSDK(chain.contractAddress, signer);
// Create a negotiation
const { negotiationId } = await haggle.createNegotiation({
seller: "0x...",
escrowAmount: 1000000n,
tokenAddress: chain.mockToken,
serviceHash: ethers.keccak256(ethers.toUtf8Bytes("my-service")),
});
// Submit an offer
await haggle.submitOffer(negotiationId, 550000n);
// Accept the current offer
await haggle.acceptOffer(negotiationId);
// Read negotiation state
const neg = await haggle.getNegotiation(negotiationId);
console.log(neg.status, neg.currentOfferAmount);Supported Chains
| Chain | Key | Network |
|-------|-----|---------|
| Monad | monad_testnet | Testnet |
| Base | base_sepolia | Sepolia |
| Arbitrum | arbitrum_sepolia | Sepolia |
Use CHAINS.monad_testnet, CHAINS.base_sepolia, or CHAINS.arbitrum_sepolia for pre-configured chain settings.
Custom Chain
const haggle = new HaggleSDK("0xYourContract", signer);API
Write Operations
| Method | Description |
|--------|-------------|
| createNegotiation(params) | Create a new negotiation with escrow deposit |
| acceptInvitation(id) | Seller accepts the negotiation invitation |
| submitOffer(id, amount) | Submit an offer (turn-based) |
| acceptOffer(id) | Accept the counterparty's current offer → settlement |
| rejectNegotiation(id) | Reject and refund escrow to buyer |
| expireNegotiation(id) | Expire a timed-out negotiation (permissionless) |
Read Operations
| Method | Description |
|--------|-------------|
| getNegotiation(id) | Get full negotiation state |
| isActive(id) | Check if negotiation is still active |
| getEffectiveEscrow(id) | Get current escrow after decay |
| getConfig() | Get protocol configuration |
Helpers
| Method | Description |
|--------|-------------|
| isMyTurn(negotiation, myAddress) | Check if it's your turn to act |
| calculateDecay(escrow, bps) | Calculate escrow decay amount |
| calculateMinOffer(escrow, bps) | Calculate minimum offer threshold |
| calculateProtocolFee(amount, bps) | Calculate protocol fee |
Event Listeners
haggle.onOfferSubmitted(negotiationId, (offerer, amount, round, effectiveEscrow) => {
console.log(`Round ${round}: ${offerer} offered ${amount}`);
});
haggle.onSettled(negotiationId, (buyer, seller, settledAmount, totalRounds, fee) => {
console.log(`Settled at ${settledAmount} after ${totalRounds} rounds`);
});License
BSL 1.1 — see LICENSE
