AI agent available on the base app w/ XMTP, shares data, and x402 income is used to buy&burn token
Stableburn: A helpful AI agent available on Base app (at agentprotocol.eth) with x402-powered USDC revenue going into the agent's treasury with buy&burn deflationary tokenomics.
Built on a platform of CoinbaseDev tools, XMTP, x402, and the new Opensea MCP server (MSeaP).
Core Components
XMTP Protocol Integration: The agent maintains a persistent presence on the XMTP decentralized messaging network, enabling direct conversations with users and other agents on the Base app beta and xmtp.chat. It uses the Coinbase AgentKit for enhanced capabilities including on-chain transactions. HTTP API Service: A Hono-based web server provides RESTful endpoints for programmatic access, with built-in x402 micropayment requirements for premium features.
OpenSea MCP Integration: Through the newly release MSeaP server beta, the agent has access to 17 specialized tools for NFT marketplace operations, including collection searches, floor price queries, trending data, swap quotes, and wallet balance checks.
The project implements Coinbase's x402 payment protocol to monetize API access:
A unique tokenomics model creates sustainable value accrual:
The agent serves as a value-add layer for blockchain data:
Technical Architecture Frontend Application (apps/web)
Agent Service (apps/agent-base-eth)
Smart Contracts
Shared Infrastructure
Use Cases
Core Technology Stack
Runtime & Framework Decisions
Bun + Node.js Hybrid Approach: We chose Bun as our primary runtime for its blazing-fast startup times and native TypeScript support, crucial for an always-on agent. However, we discovered certain XMTP SDK components required Node.js compatibility, leading to a hybrid approach where Bun handles the build process and package management while maintaining Node.js compatibility for execution.
Hono over Express: Initially built with Express, we migrated to Hono for its lightweight footprint (5KB vs Express's 500KB+) and native Web Standards API support. This was particularly important for edge deployment compatibility and reduced cold start times. The migration required rewriting middleware but resulted in 3x faster request handling.
TypeScript Everywhere: Full type safety across the monorepo with shared type definitions in packages/shared-types. This caught numerous potential runtime errors during development, especially around the complex MCP tool interfaces.
Blockchain Integration Architecture
Smart Contract Design Evolution.
Deployed Contract: https://basescan.org/address/0x76a6ed9dece032d227b713010022c5e43a307d8a
V1 → V3 Contract Rewrite: Our initial DataBurnReceiver contract used BaseSwap's router, but we discovered liquidity limitations. The V3 rewrite implements a two-step swap:
// Routing through multiple DEXsl to go from USDC to Eth (deep Uni v3 pool) to DATABURN (v4):
function _swapAndBurn(address tokenIn, uint256 amountIn) private { // Step 1: Leverage Uniswap V3's concentrated liquidity uint256 ethReceived = _swapToETH(tokenIn, amountIn);
// Step 2: Use Flaunch's meme token pools
uint256 databurnReceived = _swapETHToToken(ethReceived);
// Step 3: Permanent burn
_burn(databurnReceived);
}
Uniswap V3 Integration Challenges:
Flaunch Protocol Integration: We added Flaunch contracts as a git submodule and directly integrated with their pair contracts. This required reverse-engineering their swap interface since documentation was limited: // Had to decode Flaunch's swap mechanism const swapData = encodeFunctionData({ abi: FLAUNCH_PAIR_ABI, functionName: 'swap', args: [0, expectedTokenOut, receiverAddress, '0x'] })
XMTP Integration Deep Dive
Database Encryption Architecture: XMTP requires persistent storage for message history. We implemented SQLCipher encryption with a deterministic key derivation:
// Generate encryption key from wallet private key const encryptionKey = createHash('sha256') .update(privateKey) .digest('hex') .slice(0, 64)
Signer Creation Complexity: The XMTP SDK v4 migration broke our initial implementation. We had to create a custom signer wrapper:
// Complex signer initialization for XMTP v4 const signer = { getAddress: async () => wallet.address, signMessage: async (message: string | Uint8Array) => { const signature = await wallet.signMessage(message) return hexToBytes(signature) } }
Message Streaming Architecture: Built a robust message handler that prevents infinite loops: // Critical loop prevention if (message.senderInboxId === client.inboxId) return
OpenSea MCP Integration via AI SDK
Experimental Features Usage: We're using Vercel AI SDK's experimental MCP client, which required extensive workarounds:
// Had to patch the MCP client for SSE transport
const client = await experimental_createMCPClient({
transport: {
type: 'sse',
url: 'https://mcp-server-opensea-production.vercel.app/sse',
// Custom headers for beta access
headers: {
'Authorization': Bearer ${OPENSEA_ACCESS_TOKEN}
,
'anthropic-dangerous-direct-browser-access': 'true'
}
}
})
Tool Registration System: Dynamically registered 17 OpenSea tools with the AI SDK: // Dynamic tool mapping for (const tool of tools) { registry.register(tool.name, { description: tool.description, parameters: tool.inputSchema, execute: async (args) => { return await client.callTool(tool.name, args) } })
Hacky Solutions & Workarounds
// Hack to persist CDP wallet across hot reloads declare global { var __cdpWallet: any } global.__cdpWallet = wallet
The OpenSea MCP server only provides SSE transport, but we needed JSON-RPC. Built a custom proxy: // Convert SSE stream to JSON-RPC const sseToJsonRpc = (stream: ReadableStream) => { return new Response(stream).json() }
Foundry's latest version used "prague" EVM version which caused compilation errors. Had to downgrade: evm_version = "paris" # prague breaks OpenZeppelin
Partner Technology Benefits
Coinbase Developer Platform (CDP):
OpenSea's MCP Server:
Vercel AI SDK:
Base Network:
Performance Optimizations
Security Measures