Decentralized AI Art Marketplace where Agents Negotiate, Pay and Fulfill On-chain via Arbitrum
TrufflePay demonstrates a paradigm shift in digital commerce: autonomous AI agents acting as economic actors. Unlike traditional e-commerce where humans initiate transactions, TrufflePay enables AI agents to independently discover services, negotiate prices using strategic reasoning, execute blockchain payments, and verify service delivery—all without human intervention.
This system combines three key technologies: AP2 (Agentic Payment Protocol) for blockchain-gated services, MCP (Model Context Protocol) for multi-round agent negotiation, and Arbitrum Layer 2 for cost-effective, real-time settlement. The result is a fully autonomous marketplace where GPT-4 agents transact at machine speed with sub-dollar transaction costs.
GPT-4o powered buyer and seller agents negotiate prices over 3 rounds using strategic tactics including anchoring, value justification, and calculated concessions.
Services are gated by on-chain payment verification using the AP2/x402 protocol, enabling trustless, permissionless payment enforcement.
ERC-20 token payments settled on Arbitrum Sepolia achieve ~$0.004 transaction costs and 750ms total payment time, enabling real-time micropayments.
GPT-4 Vision analyzes pet photos with high detail, extracting breed, colors, and distinctive features. DALL-E 3 generates custom 1024x1024px artwork in multiple styles.
Premium tier includes automatic ERC-721 NFT minting on successful payment, creating verifiable on-chain proof of purchase and ownership.
Buyer and seller interfaces show negotiation progress, payment status, and service fulfillment with 2-second polling for live updates.
TrufflePay implements a three-layer architecture: the AI Agent Layer where GPT-4o agents make autonomous decisions, the Blockchain Layer where payments settle on Arbitrum via smart contracts, and the Service Layer where AI-generated portraits are produced using GPT-4 Vision and DALL-E 3.
The buyer agent receives user requirements, semantically analyzes them to select the best matching seller from a marketplace of three artists (PetPainter at 3 ENC, CartoonPup at 5 ENC, and ModernArtist at 10 ENC with NFT certificate). Once selected, the agents negotiate a final price over three rounds using the Model Context Protocol.
The system deploys three smart contracts on Arbitrum Sepolia testnet:
createInvoice() for sellers to register payment requests, payInvoice() for buyers to transfer tokens to escrow, and withdraw() for sellers to claim funds after service delivery.AP2 leverages the HTTP 402 status code, defined in the HTTP/1.1 specification but historically unused due to lack of payment infrastructure. With blockchain verification, HTTP 402 becomes practical for AI-to-AI commerce.
The protocol flow works as follows:
POST /generate with pet photo)402 Payment Required including invoice details: invoiceId, amount, token address, registry address, and seller addressregistry.payInvoice(invoiceId), transferring funds to escrowinvoiceId parameterregistry.invoices(invoiceId) to verify paid = true200 OK with artwork URL and NFT details (if applicable)Sellers verify payments by querying the PaymentRegistry smart contract. The contract exposes a public invoices mapping that returns the invoice struct containing seller address, token address, amount, and paid status. This read-only operation costs zero gas and completes in milliseconds.
TrufflePay implements multi-round price negotiation where GPT-4o agents employ tactical reasoning rather than simple averaging. Both buyer and seller agents receive strategic directives based on negotiation research and game theory.
Each agent receives comprehensive context including current round, previous offers, tactical guidelines, and acceptance criteria. Agents generate structured JSON responses containing their offer/counter-offer, a natural language message explaining their reasoning, the tactic employed, and an acceptance boolean.
The negotiation history is displayed in real-time on the seller dashboard with buyer messages appearing on the left in white bubbles and seller messages on the right in orange gradient bubbles, creating a familiar chat interface aesthetic.
Arbitrum is an Ethereum Layer 2 optimistic rollup that provides 10-100x lower gas costs than Ethereum mainnet, sub-second confirmation times (~250ms block time), and full EVM compatibility. For AI-to-AI payments, these properties enable micropayments and real-time commerce.
| Metric | Ethereum Mainnet | Arbitrum Sepolia | Improvement |
|---|---|---|---|
| Gas Cost per Transaction | ~$1.50 | ~$0.001 | 1500x cheaper |
| Block Time | ~12 seconds | ~250ms | 48x faster |
| Total Payment Time | 15+ minutes | ~750ms | 1200x faster |
| Micropayment Viable? | ❌ No ($1.50 gas > $0.05 payment) | ✅ Yes ($0.004 gas < $2-10 payment) | Enabled |
The complete payment flow involves three on-chain transactions:
token.approve(registryAddress, amount) to authorize the registry to transfer tokens. Confirms in ~250ms with ~$0.001 cost.registry.payInvoice(invoiceId). The contract verifies the invoice exists and is unpaid, transfers tokens from buyer to registry (escrow), and marks invoice.paid = true. Confirms in ~250ms with ~$0.0015 cost.registry.withdraw(invoiceId). The contract verifies the caller is the registered seller and payment is complete, then transfers tokens from registry to seller wallet. Confirms in ~250ms with ~$0.0012 cost.Total: ~$0.004 USD transaction cost and ~750ms total time for a complete payment cycle including escrow and settlement.
TrufflePay employs a two-stage AI pipeline optimized for portrait accuracy and style consistency.
The system uploads the pet photo to GPT-4o with a detailed prompt requesting analysis of:
The model uses detail: "high" mode and generates up to 400 tokens of detailed description optimized for DALL-E 3 input.
The GPT-4 Vision description is combined with style-specific prompts tailored to each seller:
style: "natural" and quality: "standard".style: "vivid" and quality: "standard".style: "natural" and quality: "hd" for premium tier.All portraits are generated at 1024x1024px resolution. Generation time averages 15-30 seconds depending on OpenAI API load.
ModernArtist (10 ENC tier) automatically mints an ERC-721 NFT to the buyer's wallet upon successful payment and portrait generation. The mintPortrait() function stores on-chain metadata including:
The NFT serves as proof of purchase, ownership certificate, and value differentiation. Buyers can view their NFT on Arbiscan, import it to MetaMask, or view it on OpenSea testnet after ~10 minutes.
TrufflePay demonstrates a paradigm shift: AI agents as economic actors. GPT-4o agents make purchasing decisions, negotiate using strategic reasoning, execute blockchain payments, and verify service delivery—all without human input beyond initial requirement specification. This represents the first step toward an economy where AI agents transact independently at scale.
The HTTP 402 Payment Required status code, defined in 1997 but rarely implemented, becomes practical with blockchain verification. Services return structured invoice data, buyers pay on-chain, and sellers verify trustlessly via smart contract queries. This creates permissionless payment gates without PayPal, Stripe, or other centralized processors.
Arbitrum L2's 250ms block times and sub-cent transaction costs enable AI agents to transact at machine speed. The total payment cycle (approve, pay, withdraw) completes in under 1 second with $0.004 total cost, making micropayments economically viable for the first time in blockchain history.
Rather than simple price averaging, TrufflePay implements game-theoretic negotiation tactics: anchoring, value justification, strategic concessions, and final offers. Agents reason about budget constraints, market rates, and quality signals to reach mutually beneficial agreements. This demonstrates sophisticated AI reasoning beyond simple optimization.
ERC-721 NFTs serve triple purpose: on-chain receipt, transferable ownership certificate, and premium tier differentiator. This creates a digital provenance chain for AI-generated artwork, enabling secondary markets and verifiable authenticity.
git clone [repository] and npm install.env.example to .env and fill in RPC_URL, OPENAI_API_KEY, and wallet private keysnpx hardhat run scripts/deploy.js --network arbitrumSepolia.env (TOKEN_ADDRESS, PAYMENT_REGISTRY_ADDRESS, NFT_CONTRACT_ADDRESS)npx hardhat run scripts/fundWallets.js --network arbitrumSepoliahttp://localhost:3000/ for buyer interface and http://localhost:3000/seller for seller dashboardcontracts/ - Solidity smart contracts (EncodeToken, PaymentRegistry, PetPortraitNFT)scripts/ - Deployment and wallet funding scriptsbackend/sellers/ - Three seller services (petpainter, cartoonpup, modernartist)frontend/ - API server bridge and HTML interfacesAll contracts are deployed on Arbitrum Sepolia testnet and publicly verifiable on Arbiscan:
0x44a7435660D90889b218F7Bd0f21884aE01419Ac0x1c1fE24391D6BAdaBa753070469072aeD2C5C5FdTrufflePay demonstrates that autonomous AI-to-AI commerce is not only technically feasible but economically practical. By combining strategic agent negotiation (MCP), trustless payment gates (AP2/HTTP 402), and cost-effective blockchain settlement (Arbitrum L2), the system achieves real-time autonomous transactions at sub-cent costs.
This proof-of-concept opens pathways toward a future where AI agents operate as independent economic actors—discovering services, negotiating terms, executing payments, and verifying delivery at machine speed without human intermediation. The implications extend beyond pet portraits to any AI service marketplace: content generation, data analysis, API access, computational resources, and knowledge work.
As AI capabilities expand and blockchain infrastructure matures, systems like TrufflePay may become the foundation for a new internet economy where billions of AI agents transact autonomously, creating value and exchanging services at scales impossible for human-mediated commerce.