Skip to main content
This page is for agent developers who want an agent to move money, not only to answer questions. On Celo an agent is an economic actor: it can quote and settle FX between local stablecoins through Textile, swap on Uniswap, supply to Aave or Morpho, and pay gas for all of it in the USD₮ or USDC it already holds through fee abstraction. Blocks are 1 second and a typical transaction costs below $0.01, so an agent can act often. ERC-8004 and Self Agent ID give the agent an identity counterparties can check, and an attribution tag credits its activity to your app. The page uses Textile’s FX API as the worked example. Swaps and lending follow the same loop with a different contract call.

Prerequisites

  • An account the agent signs with, funded on Celo mainnet (chain ID 42220) with a small amount of USDâ‚® or USDC. Give your agent a wallet covers key generation; fund the address from an exchange or bridge.
  • Node.js 20.6 or later and npm install viem.
  • For firm FX quotes, either a Textile API key or a wallet signature. Textile’s test keys work only on BNB Smart Chain testnet and Base Sepolia, not on Celo Sepolia, so FX runs on mainnet with small amounts. Indicative prices need no key.

How it works

  1. The agent reads a price: Textile’s price ladder for an FX pair, an oracle feed, or a DEX quote.
  2. It decides within limits you set in code: maximum size per trade, maximum spend per day, maximum slippage.
  3. It asks for a firm quote or builds the swap or supply transaction.
  4. It simulates the transaction, then signs it with its own key and sets feeCurrency so gas comes out of the stablecoin balance.
  5. It submits, waits for the receipt and records the result.
Nobody else can withdraw the agent’s funds: swaps settle atomically, and supplied assets stay in the protocol’s contracts until the agent withdraws them. A Morpho vault’s curator decides which markets the deposit is lent to.

Quote and settle FX with Textile

Textile FX is a request-for-quote market. Makers run bots that price each corridor from their own feeds; the agent asks for a quote on an exact size and receives one firm, all-or-nothing offer bound to its wallet, or no_quote. Live Celo corridors include cNGN, wARS, wBRL, wCOP, wMXN, IDRX, USDC, CELO and G$ against USD₮; the current list and the token addresses are in Textile’s address book. The v2 API lives at https://api.textilecredit.com/v2. Amounts are strings in base units, and rates are scaled by 1e27. The example below asks for an indicative price for 1 USD₮ into wARS on Celo mainnet. It runs without a key.
Run it with node textile-preview.mjs. A preview status prints the wARS amount in base units and the rate; no_quote means no maker is pricing that size right now. To trade, the agent calls /rfq/request with the same body plus its taker address. With an API key it sends Authorization: Bearer <key>; without one it signs a challenge and sends it as takerProof. The signed proof is valid for 60 seconds (5 minutes for an eip191 proof). Once it verifies, Textile records a grant that lets later requests for the same wallet and chain omit takerProof for about 12 hours; without an API key the grant is bound to the agent’s client IP. The response carries rfqId, a one-time claimToken, quote.takerPays, quote.reactor, quote.expiresAt and transactions.swap. Store the claimToken with the quote: it is returned once, and without an API key it is the only thing that authorizes submit and status for that RFQ. A missing or wrong token returns 404. The agent then:
  1. Checks the allowance of the sell token for quote.reactor and approves takerPays if it is short. For USDâ‚® reset a non-zero allowance to zero first.
  2. Confirms the current time is before expiresAt. Quotes live about 60 seconds.
  3. Sends transactions.swap from the taker wallet, with feeCurrency set so gas is paid in USDâ‚®.
  4. Posts the transaction hash to /rfq/{id}/submit and polls /rfq/{id} for the settled amounts, sending X-Rfq-Claim: <claimToken> on both calls (or the API key that created the RFQ).
Textile’s RFQ reference, authentication and API key pages have the field-level detail and a viem walkthrough.

Swap on Uniswap

Uniswap v4 is deployed on Celo mainnet and Celo Sepolia, and Uniswap v3 on Celo mainnet only; the router and pool manager addresses are on Uniswap contracts. An agent quotes through the Quoter contract, sets a slippage bound, and sends the swap through the Universal Router with feeCurrency set. Some Celo pools carry Merkl incentives; campaigns change, so check Merkl for the current list.

Lend and earn on Aave and Morpho

Aave v3 on Celo lets an agent supply USD₮ or USDC to earn interest, or borrow against collateral, by calling the Pool contract listed in Aave’s documentation. Morpho offers isolated markets and curated vaults; on Celo the vaults are curated by Feather, and an agent deposits into a vault with an ERC-4626 deposit call. In both cases read the health factor or vault share price before and after the call so the agent can stop when a position moves against it. If the agent is tool-driven rather than hand-coded, Celina exposes Uniswap v3 and v4, Aave v3, Mento and transfers as tools through an SDK, an MCP server and a REST API.

Pay gas in the stablecoin you hold

Every write above is a normal Celo transaction, so the agent sets feeCurrency to the adapter address of USDâ‚® or USDC and never needs CELO. The example on Build with AI on Celo shows the viem call, and Fee currencies lists the adapter addresses per network. Passing the token address instead of the adapter is the most common mistake.

Guardrails

  • Simulate before you sign. Run eth_call or viem’s simulateContract with the exact calldata. A revert in simulation costs nothing; a revert onchain costs gas and a quote.
  • Cap spend in code. Enforce a per-transaction maximum and a daily maximum on the agent side, independent of what the model decides. buy does this for x402 with --max-amount; do the same for DeFi calls.
  • Use a dedicated key with limited funds. The agent’s account holds what it may lose. Top it up from a treasury it cannot sign for.
  • Bound price and time. Reject a quote whose rate deviates more than your threshold from the preview or an oracle, and never broadcast after expiresAt.
  • Handle no_quote and partial liquidity. Textile quotes are all-or-nothing. Retry with a smaller size or split the order.
  • Give the agent an identity. Register it with ERC-8004 or Self Agent ID so services and counterparties can verify who is trading.
  • Tag the transactions. Append an attribution tag so the activity is credited to your app.

Troubleshooting

  • status: "no_quote" - No maker priced the size within the reply window. Check the pair’s minSellAmount and maxSellAmount on /rfq/levels, then retry smaller.
  • 429 rate_limited - More than 4 RFQs outstanding, or too many requests. If the response has a Retry-After header, wait that long. Otherwise you are at the cap: a slot frees when a quote fills or its latestOrderDeadline passes, and cancelling does not free it.
  • Quote expired - More than 60 seconds passed between /rfq/request and the broadcast. Request a new quote; approve the reactor ahead of time so the swap is the only transaction in the window.
  • 401 proof_of_control_stale - The takerProof was signed more than 60 seconds ago (5 minutes for eip191). Sign a fresh challenge and send it straight away.
  • 401 proof_of_control_required - The request has no takerProof and no live grant. The grant lasts about 12 hours and, without an API key, is tied to the client IP, so it also lapses when the agent’s IP changes. Sign a fresh challenge and resend.
  • 401 proof_of_control_invalid - The signature does not verify as the taker named in the request. Sign with the taker’s key.
  • fee currency not registered: 0x… from eth_estimateGas - feeCurrency holds the USDâ‚® or USDC token address instead of the adapter address, so the node refuses the transaction before it reaches the chain. Use the adapter from Fee currencies.

Resources