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
- The agent reads a price: Textile’s price ladder for an FX pair, an oracle feed, or a DEX quote.
- It decides within limits you set in code: maximum size per trade, maximum spend per day, maximum slippage.
- It asks for a firm quote or builds the swap or supply transaction.
- It simulates the transaction, then signs it with its own key and sets
feeCurrencyso gas comes out of the stablecoin balance. - It submits, waits for the receipt and records the result.
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, orno_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.
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:
- Checks the allowance of the sell token for
quote.reactorand approvestakerPaysif it is short. For USDâ‚® reset a non-zero allowance to zero first. - Confirms the current time is before
expiresAt. Quotes live about 60 seconds. - Sends
transactions.swapfrom the taker wallet, withfeeCurrencyset so gas is paid in USDâ‚®. - Posts the transaction hash to
/rfq/{id}/submitand polls/rfq/{id}for the settled amounts, sendingX-Rfq-Claim: <claimToken>on both calls (or the API key that created the RFQ).
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 withfeeCurrency 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-4626deposit 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 setsfeeCurrency 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_callor viem’ssimulateContractwith 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_quoteand 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’sminSellAmountandmaxSellAmounton/rfq/levels, then retry smaller.429 rate_limited- More than 4 RFQs outstanding, or too many requests. If the response has aRetry-Afterheader, wait that long. Otherwise you are at the cap: a slot frees when a quote fills or itslatestOrderDeadlinepasses, and cancelling does not free it.- Quote expired - More than 60 seconds passed between
/rfq/requestand 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- ThetakerProofwas signed more than 60 seconds ago (5 minutes foreip191). Sign a fresh challenge and send it straight away.401 proof_of_control_required- The request has notakerProofand 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 thetakernamed in the request. Sign with the taker’s key.fee currency not registered: 0x…frometh_estimateGas-feeCurrencyholds 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
Related
- Build with AI on Celo - Where to start when building an agent on Celo
- Give your agent a wallet - Generate a key and get test funds
- Build with DeFi - Every DeFi protocol live on Celo
- Build with local stablecoins - The currencies an FX agent can trade
- x402 - Pay for the data and APIs an agent consumes
- ERC-8004 - Agent identity, reputation and validation registries
- Self Agent ID - Tie an agent to a verified human