โก AbaPay Protocol
AbaPay is a decentralized, Web3-native utility payment platform built on Base (the default chain) and Celo. It lets users pay for real-world bills โ Airtime, Mobile Data, Electricity, Cable TV, Bank Transfers, Education PINs, and International Airtime/Data โ using on-chain stablecoins (USDT, USDC, USAT), with instant fiat settlement handled server-side via the VTpass API. Payments can be made directly in the web app, or hands-free through a conversational, autonomous AI agent ("DeAI") on Telegram, WhatsApp, and X โ a real on-chain identity under ERC-8004, discoverable on 8004scan.io โ that can pay bills unattended, run recurring/scheduled autopay, and settle multi-recipient batch payments, all spending from a bounded, user-revocable on-chain allowance โ no custody, no server-side keys.
Designed for low fees, cross-border utility vending (Nigeria + every country VTpass's live international catalogue returns), and mobile-first accessibility โ MiniPay, Valora, Farcaster Mini Apps, Coinbase Smart Wallet / Base Account, MetaMask, and any other WalletConnect-compatible wallet (see Supported Wallets & Environments).
Operator: Masonode Technologies Limited (RC 9524980), Nigeria.
๐ Key Features
- Multi-Chain Payments: Pay bills directly with USDT, USDC, or USAT on Base (Mainnet/Sepolia) or Celo (Mainnet/Alfajores). Base is the default chain; Celo remains fully supported and switchable. The app auto-detects the connected chain and filters/reorders available stablecoins accordingly โ USDC leads on Base, USDโฎ leads on Celo, and USAT is Celo-mainnet-exclusive.
- Live VTpass Catalogue โ nothing about a provider is hardcoded any more: every provider name, logo, and amount limit for airtime, data, electricity, cable and education is fetched live from VTpass (
src/lib/vtpassCatalog.ts, served to the browser by /api/providers) rather than from four separate hardcoded lists. The app, chat, MCP and the admin dashboard all read the same in-process cache, so there is exactly one source of truth. See Live provider catalogue below.
- Per-Provider Amount Limits, Enforced Live: the ceiling is VTpass's real published
minimium_amount/maximum_amount per provider, not one flat number per service โ airtime alone ranges MTN โฆ200,000 / Glo โฆ100,000 / Airtel โฆ50,000 / 9mobile โฆ50,000, and electricity minimums range โฆ100 (Ikeja, Aba) to โฆ2,000 (Ibadan). A flat cap either wrongly refused a valid MTN top-up or wrongly accepted an Airtel one that VTpass rejects after the user has already paid on-chain.
- International Bill Pay: Users can select a country and pay for foreign airtime/data in that country's own currency and rate โ transaction history and receipts reflect the local currency, not just Naira. The country list is fetched live from VTpass (
/get-international-airtime-countries) on every channel, so the app, chat and MCP can never disagree about which countries are covered.
- Instant Vending: Automated API integration with VTpass for instant token generation, airtime top-ups, and data bundle delivery.
- Education PINs in every channel: WAEC result-checker and WAEC registration PINs are buyable from the app, from chat (Telegram/WhatsApp/X/in-app), and over MCP โ not app-only. โ ๏ธ JAMB is a deliberate honesty caveat: the code path exists end-to-end (intent parsing, profile-ID verification,
variation_code handling), but jamb is not enabled on the current VTpass merchant account โ VTpass answers {"code":"011","content":{"errors":"Service is Not Valid"}} โ so it does not appear in the live catalogue and cannot currently be sold. If the account is enabled for it, it appears automatically with no code change.
- Smart Merchant Verification: Validates electricity meters, smartcard/IUC numbers, and account details before accepting crypto payments, eliminating user errors and failed vends.
- AbaPoints Loyalty System: Users earn points pegged 1:1 to stablecoin value spent, trackable via the in-app points badge and a dedicated API endpoint.
- Automatic Refund Safety Net: Failed vends after confirmed on-chain payment are automatically flagged, verified, and refunded on-chain to the user's wallet.
- DND-Fallback SMS: Automated SMS delivery of electricity tokens/PINs, bypassing the Nigerian Do-Not-Disturb (DND) registry for critical transaction alerts.
- Multi-Channel Support & Notifications: Built-in support ticketing, plus webhook integrations for Telegram, WhatsApp, and X (Twitter) so users and admins can transact/get notified from their preferred channel.
- Conversational AI Agent ("DeAI"): A natural-language assistant (
/api/deai) that lets users check balances and pay bills via chat-style commands, backed by Claude (Anthropic). Reachable via Telegram, WhatsApp, X, and an in-app chat widget (src/components/AIChat.tsx) on the storefront itself. Understands intent, not just menu numbers โ replying "Celo" or "usdt" works exactly like replying "1" or "2" โ and shows the live balance and approved agent limit for every token at the moment you're asked to pick one, so you're never choosing blind. If a session goes cold (network drop, abandoned mid-flow) it's recognised and cleaned up automatically rather than left dangling; and if a network hiccup happens right after you enter your PIN, the payment is never silently lost or double-spent โ it's tracked through to a confirmed on-chain outcome before the agent reports back.
- Agent-Initiated Payments (AbaPayV3): Users can grant the DeAI agent a bounded, on-chain, revocable spending allowance (
setSpendingAllowance) โ chosen independently per chain and per stablecoin from the Agent Hub tab โ so it can pay bills on their behalf from Telegram/WhatsApp/X with no wallet signature needed at payment time and no custody of user funds. If no allowance is approved for the chain/token a chat payment needs, the agent detects that up front and offers a straight choice: approve it now, or complete this one payment via a signed deep link instead. See AbaPayV3 โ agent allowances below.
- Autonomous Scheduling & Autopay Agent: Beyond one-off chat payments, users can ask the DeAI agent to set up recurring bills (monthly/weekly/daily), a one-time future payment ("pay this in 10 minutes"), or a single request covering multiple recipients/accounts at once โ the agent groups them by chain/token and settles each leg through the same allowance-bounded relayer, unattended, on schedule, with zero further interaction required from the user.
- On-Chain Attribution: Celo transactions carry an ERC-8021 attribution tag (
src/lib/attribution.ts) crediting the Celo Builders program; a no-op on Base.
- On-Chain Agent Identity (ERC-8004): AbaPay's DeAI agent is registered as a real on-chain identity on both Celo and Base via the ERC-8004 "Trustless Agents" registry, so it's discoverable on 8004scan.io / AgentScan โ independent of, and unrelated to, how it moves money. See ERC-8004 agent identity below.
- MCP Server (AI Agent Payments): AbaPay is reachable by any MCP-speaking AI client (Claude, or any other agent that supports the Model Context Protocol) as a real tool server โ
describe_capabilities, check_balance, list_plans, pay_bill, multi-recipient pay_bill_batch, and recurring/one-off schedule_bill/list_schedules/cancel_schedule โ over Streamable HTTP JSON-RPC at /api/mcp. This is a fourth channel alongside Telegram/WhatsApp/X, not a new trust boundary: it runs through the exact same allowance-bounded, kill-switch-gated, discount-aware execution pipeline as the chat channels, on either Celo or Base depending on what the linking wallet approved. See MCP Server below.
- MCP OAuth 2.1 (authorize once, not once per conversation): the connector supports a full OAuth 2.1 authorization-code + PKCE (S256) flow with Dynamic Client Registration (
/api/oauth/register, /api/oauth/authorize, /api/oauth/token, discovery under /.well-known/). A user authorizes once in a browser โ proving their API key and PIN on AbaPay's own hand-rendered consent page โ and every future conversation reconnects with a Bearer token instead of retyping an API key. OAuth never authorizes a spend: the PIN is still required on every single pay_bill call, and a Bearer token alone can only read a balance. The api_key tool argument remains the fallback for clients that can't do OAuth.
list_plans โ real VTpass plan codes and prices, never guessed: for DATA/CABLE/EDUCATION, list_plans returns the currently purchasable plans with their exact variation_codes and live VTpass prices, and both the tool description and the server instructions tell the client to call it before pay_bill rather than guessing.
- x402 Settlement (main app, both chains): Payments made directly in the web app settle via the x402 HTTP-payment protocol โ Celo's own facilitator for USDC/USDโฎ/USAT on Celo, the Coinbase CDP facilitator for USDC on Base โ so they're genuinely indexed on x402scan, not relabeled contract calls. Anything without EIP-3009 uses the on-chain
payBill flow, including Base's sponsored-gas path. โ ๏ธ x402 needs an EIP-3009 transferWithAuthorization signature, which is structurally what a drainer asks for, so some wallet scanners flag it as risky โ a known, deliberate trade for x402scan visibility; NEXT_PUBLIC_X402_ENABLED=false opts out. The signature-free agent-initiated flow is untouched either way. See x402 settlement below.
- Dynamic Exchange Engine: Live market rate conversions with admin-configurable exchange rate and automated profit spread calculation, verified server-side to prevent underpayment exploits.
- Executive Admin Dashboard: Real-time monitoring of VTpass fiat balance, on-chain vault balances per token/chain, transaction analytics, manual refund tools, and CSV export โ protected behind admin auth.
- Kill Switches That Actually Stop Every Channel: the dashboard's "pause a service" toggles are a two-level model โ a per-service master (
MASTER_AIRTIME, MASTER_INTERNET, MASTER_ELECTRICITY, MASTER_CABLE, MASTER_EDUCATION, MASTER_INTERNATIONAL) plus a per-provider switch keyed by VTpass serviceID (AIRTIME_mtn, INTERNET_airtel-data, ELEC_ikeja-electric, CABLE_dstv, EDU_waec). A payment is refused when either level is off. src/lib/serviceRules.ts's killSwitchKeysFor() maps an agent intent (+ provider, normalised through resolveServiceId so ELEC_ikeja can't miss ELEC_ikeja-electric) onto exactly those keys, so chat, MCP and the autonomous scheduler now honour the same switches the web app does. See Kill switches below.
- Sponsored Gas on Base: Coinbase Smart Wallet / Base Account users can pay with zero gas fees โ the app detects paymaster support via EIP-5792 and batches approval + payment into a single sponsored transaction. Wallets without this capability (MetaMask, WalletConnect, Valora, etc.) transparently fall back to the normal self-paid flow.
- Shareable & Downloadable Receipts: Every receipt can be shared as an image straight to WhatsApp/Telegram/etc. via the device's native share sheet, or saved directly as a PNG or PDF.
- Farcaster Mini App Ready: Ships with Farcaster frame metadata so AbaPay can be launched directly inside Farcaster clients.
๐ ๏ธ Tech Stack
- Frontend: Next.js 16 (App Router, React 19), Tailwind CSS 4, Lucide Icons, next-themes (dark mode)
- Web3 / Wallets: Wagmi, Viem (incl. EIP-5792
sendCalls for sponsored transactions), WalletConnect Modal, Base Account SDK, Solidity smart contract (Hardhat)
- Backend: Next.js Route Handlers (serverless functions)
- Receipts: html2canvas (image capture), jsPDF (PDF export)
- AI: Claude (Anthropic API) for the DeAI conversational agent and in-app chat widget
- Agent Identity & Payments: ERC-8004 (on-chain agent identity, Celo + Base) and x402 (signed in-house with the connected wallet โ
src/lib/x402Pay.ts) for HTTP-native, facilitator-settled payments in the main app
- Agent Tool Access: MCP (Model Context Protocol) โ Streamable HTTP/JSON-RPC server at
/api/mcp exposing balance-check and bill-pay tools to any MCP client โ and A2A (Agent2Agent) at /api/a2a, card at /.well-known/agent-card.json, exposing the same tools to peer agents. The x402 endpoint is also listed in an x402 discovery manifest at /.well-known/x402 ({ version: 1, resources: [...] }), the file x402 indexers such as agent402.tools read before probing the live 402 challenge. Cursor: a marketplace plugin lives in integrations/cursor-plugin/ (.cursor-plugin/plugin.json + mcp.json pointing at https://agents.abapays.com/api/mcp, registered for the marketplace by the repo-root .cursor-plugin/marketplace.json); OAuth accepts Cursor's native callback (cursor://anysphere.cursor-mcp/oauth/callback, exact match only, PKCE required) and its newer loopback one. Grok: add it at grok.com/connectors โ New Connector โ Custom with the same URL
- Utility Provider: VTpass API (bills, airtime, data, education, international airtime)
- Bank Transfer Provider: Monnify API (Moniepoint Inc.) โ account auto-detect, Name Enquiry verification, and the real NUBAN payout, debited from a Moniepoint Microfinance Bank business account
- Database / Ledger: Supabase (PostgreSQL) โ transactions, platform settings, points, refunds
- Email: Resend (transactional receipt emails)
- Notifications & Bots: Telegram Bot API, WhatsApp Cloud API, X (Twitter) API, VTpass Messaging API (SMS)
๐ Supported Wallets & Environments
AbaPay runs in three distinct runtime environments, detected at load in src/app/page.tsx
(environment = MINIPAY | FARCASTER | WEB, with LOADING as the pre-detection state and a
2-second timeout that falls back to WEB). Wallet connectivity for the WEB case comes from
src/config/wagmi.ts, which registers exactly three connectors: injected(), baseAccount(),
and walletConnect().
| Wallet / environment | How it connects | Notes |
|---|
| MiniPay (Opera Mini's built-in Celo wallet) | Detected directly via window.ethereum.isMiniPay; the app builds its own viem wallet client and locks to Celo | Gas is paid in a stablecoin (txConfig.feeCurrency), so users need no CELO. Network switching is intentionally disabled here. |
| Farcaster Mini App | Detected via @farcaster/miniapp-sdk's sdk.context; uses sdk.wallet.ethProvider, locked to Base | Addresses are read with a silent getAddresses() so opening the app never forces a wallet popup. Frame metadata ships in public/.well-known/farcaster.json. Has its own Exit button next to the (non-interactive) network badge. |
| Valora | WalletConnect only โ the injected path is deliberately skipped inside Valora's in-app browser (isValoraBrowser()) | Pinned to the top of the WalletConnect modal's recommended list via explorerRecommendedWalletIds. Celo-only, which the app follows automatically (walletApprovedChainIds()). See "Valora is WalletConnect-only" below for why the injected path is off. |
| MetaMask and other injected browser wallets | Whichever EIP-6963-discovered connector the wallet announced, falling back to the generic injected() one | wagmi discovers one connector per installed wallet (multiInjectedProviderDiscovery, on by default). See "How the Connect button chooses" below for why this, rather than reading window.ethereum directly, is what keeps web3-browser users off a QR code. |
| Coinbase Smart Wallet / Base Account | baseAccount() connector | The only wallets that get sponsored gas โ the app probes EIP-5792 paymaster capability and batches approve + pay into one sponsored call. Everything else falls back to the normal self-paid flow. |
Base App (the site opened inside Base App's own in-app browser, detected via isBaseAppBrowser()) | Same baseAccount() connector as above, but auto-connected like MiniPay/Farcaster (see the allowlist below) and locked to Base in the UI โ the network switcher, footer network text and token picker all show Base only, with no Celo to switch to | Distinct from the general "Coinbase Smart Wallet" row above: picking that connector from an ordinary browser still gets both chains: this row is only when the page itself is running inside Base App. Has its own Exit button next to the (non-interactive) network badge, same as Farcaster. |
| Any other WalletConnect v2 wallet (Trust, Rainbow, Ledger Live, โฆ) | walletConnect() connector with the QR modal | Nothing wallet-specific in the code โ if it speaks WalletConnect and supports Celo or Base, it works. |
An injected wallet is always preferred: it touches no third-party host, which is why it keeps
working on networks that filter the WalletConnect relay. WalletConnect is the fallback for a
browser that has no wallet in it โ a plain desktop browser, or a phone browser pairing with
a wallet app.
Which wallets exist is established by asking, never by reading window.ethereum:
probeInjectedConnectors() (src/lib/walletEnv.ts) takes wagmi's discovered connectors, gets
each one's own provider, and sends it a timed-out eth_accounts โ a call that never prompts, so
it is safe on every page load. Each wallet comes back authorized (already approved this site),
available (real, not yet approved) or none (absent, or a stub that never answered).
- Any wallet
authorized โ nothing happens on its own. authorized decides which wallets the
chooser can offer without a permission popup, not whether to connect. See "Auto-connect is an
allowlist" below.
- The chooser lists every usable injected wallet plus Base Account plus WalletConnect, each
with its own EIP-6963 logo and a status badge (
Recent for a wallet that already approved this
site, Installed otherwise). Cancelling ends the attempt rather than falling through to a QR
code. One extension that is both EIP-6963-announced and parked on window.ethereum is
de-duplicated, so it can't appear twice.
- Base Account is offered alongside injected wallets. The connector lives in
src/config/wagmi.ts; probeInjectedConnectors() returns injected-type connectors, and Base
Account (its own connector type) is added to the option list separately. It matters most on
Base, the default chain, where it is the smart-account experience carrying sponsored gas;
verifySignatureAcrossChains validates the ERC-1271 signatures it produces.
- Because those two are always present, the chooser always appears โ a browser with no extension
still gets a real choice between signing in with Base Account and pairing a phone wallet,
rather than being dropped straight onto a QR code.
๐ต WalletConnect is always an option, never only a fallback. The chooser's option list is
built first and the chooser itself is decided from that list's length โ so even the common
"one extension installed" case still offers WalletConnect as a real route to pairing a phone
wallet, not just a fallback for zero-extension browsers.
๐ต Why not window.ethereum: under EIP-6963 a wallet announces itself over an event rather
than claiming that global โ which is how several extensions coexist without fighting over one
slot. Probing the EIP-6963-announced connectors (rather than the bare global) means a browser
with a perfectly good wallet is never reported as walletless just because window.ethereum is
unset or points at a different wallet.
Prompts also say where to approve. Over WalletConnect the request lands in a separate app
that nothing brings to the foreground, so the copy says to open it (walletApprovalPrompt).
Valora is WalletConnect-only
๐ต Why the injected path is skipped inside Valora. Inside Valora's in-app browser, the page
can see something that answers eth_accounts โ real enough to report a wallet, real enough for
auto-connect to fire, real enough for the UI to look connected. Not real enough to pay with:
Valora's injected provider takes a payment authorization request as a connection handshake,
consumes it, and returns nothing to the page โ so the request never resolves.
Valora's supported rail is WalletConnect, and over WalletConnect it behaves normally: a real
session request with a real response. So the injected path is skipped inside Valora โ
isValoraBrowser() suppresses auto-connect and empties the Connect button's injected candidate
list, dropping the click through to WalletConnect.
๐ต Detecting Valora needs the WalletConnect session, not the page's own globals.
isValoraBrowser() looks for an isValora flag or the name in the user agent, and in Valora's
in-app browser neither is present: it injects no provider and its webview reports a stock
Android Chrome user agent. The only thing that names the wallet is the session โ WalletConnect
exchanges peer metadata on connect, and session.peer.metadata.name is the wallet's own name
for itself.
So connectedWalletIsValora() reads that instead, and a restored Valora session is dropped on
mount so the user pairs fresh. That is deliberately narrow, because the friction only buys
something in one place:
- Valora only โ every other wallet keeps its restored session.
- Restored sessions only โ a connection the user just asked for is never yanked away
(
userInitiatedConnect).
- Once per mount, so it can't fight a connect that's mid-flight.
The trade-off is that peer metadata only exists after connecting, so this shapes what happens
next rather than pre-empting the connection. Both detectors are word-bounded โ a false positive
would drop a working session (or strip a real in-browser wallet off the rail it should use), which
is the more expensive mistake. Covered in tests/walletEnv.test.ts.
Cancelling in a wallet is not always an answer
Every cancellation path assumes the wallet reports the rejection โ EIP-1193 says it should, and
injected wallets do. Valora over WalletConnect does not: dismissing its sheet sends nothing
back over the relay, so there is no rejection to catch, no error and no event. The request stays
open and the page waits on a decision that was already made.
withWalletTimeout fires at 90s โ that budget has to stay 90s, because it is also how long
someone gets to read a prompt before approving. So after 15s of processing the status banner
grows a STOP WAITING control. It cannot abort the in-flight request (nothing on this side
can) and deliberately does not claim the payment was cancelled: if the user approves a
moment later it still settles, and saying otherwise is how someone pays twice.
Auto-connect is an allowlist: MiniPay, Base App, Farcaster โ and nothing else
On the web, the Connect button is the only way in. No wallet is connected until the user asks
for it, even one whose extension approved this site months ago.
๐ต reconnectOnMount={false} is set deliberately in Providers.tsx. wagmi's default
reconnectOnMount persists the connector and silently re-establishes it on every page load โ
inside the provider, before any effect in page.tsx runs. Setting it false means only an
explicit connect() call ever establishes a session.
Auto-connect itself is an allowlist (AUTO_CONNECT_SURFACES), not a rule that connects any
previously-authorized wallet by default and carves out exceptions by name โ an allowlist is
the shape that keeps a silent connect from reappearing under a different wallet's name later.
Those three are different in kind, not degree: the app is running inside the wallet, so there
is exactly one account it could mean, the user chose it by opening AbaPay there, and no chooser is
being suppressed because there is nothing to choose between. MiniPay and Farcaster are connected
by their own SDKs and never touch wagmi; Base App arrives through wagmi and is matched by
looksLikeBaseApp() โ which deliberately refuses the Coinbase desktop extension, since that
sets the same isCoinbaseWallet flag while being an ordinary injected wallet on an ordinary page.
โ ๏ธ The trade: a refresh ends a web session and the user presses Connect again. Being asked
is the point, but it is a real cost on a page people reload.
A connection the page did not establish is not a connection
reconnectOnMount={false} stops wagmi re-establishing the connector. It does not stop it
rehydrating: the config persists to cookieStorage with ssr: true, so on load wagmi
restores connections/current from the cookie and useAccount() reports isConnected with an
address โ while no provider has been set up and no relay socket exists.
๐ต A rehydrated cookie session and a live session look identical from useAccount() โ both
report isConnected with an address โ so a connection this page did not itself establish is
dropped on mount (userInitiatedConnect is what separates the two). Base App is unaffected โ
its silent connect calls connect() explicitly.
Proving the wallet is yours, once per session
๐ต A filter written by the client is not a permission. History is never read straight from
the browser with the anon key scoped by an address parameter โ a client-supplied filter like
.ilike('wallet_address', address) is only as trustworthy as the client, and a wallet address is
public information anyone could pass.
After connecting, the wallet signs a plainly-worded ownership message (src/lib/walletSession.ts
โ shared by browser and server, because two copies of that string means one stray character
failing every signature as "invalid signature"). GET /api/history derives the address from
that signature and queries with the service-role client, so no parameter remains that could
point at another person's records.
verifySignatureAcrossChains already covers EOAs and ERC-1271/6492 smart accounts, so Base
Account and Safe are not locked out by the signature being a shape we could not check.
- A rejection disconnects โ the user declined to prove the address is theirs.
- Any other failure leaves them connected but unproven: they can still pay, because paying is
authorised by the payment signature itself, and only history is withheld โ never a hard lockout
over a signature shape this endpoint didn't need to check.
- Read-only, and for a session rather than five minutes, because a wallet popup on every History
refresh trains people to sign whatever they are shown. It is a bearer credential for that
window; mutations keep their own fresh, per-action signatures (
verifyWalletOwnership).
A restored WalletConnect session is not a live one
๐ต wagmi persists the WalletConnect session (cookieStorage) and restores it on load, producing
an address โ and an address is all the UI needs to look connected: balances render (they come
from a public RPC and never touch the wallet), the pay button enables, everything reads as
normal.
But a WalletConnect request only reaches the phone if the relay socket is open. Over a dead
socket, eth_sendTransaction is written to a closed pipe: no prompt appears in the wallet,
nothing comes back, and there is no error to catch, because nothing rejected โ the request
simply goes nowhere, indistinguishable from a user who hasn't looked at their wallet yet.
walletConnectSessionLive() (src/lib/walletEnv.ts) checks the relay before any wallet
interaction; a dead session is reported in one sentence and disconnected so Connect pairs
fresh instead of restoring the same corpse. A missing socket internal is treated as live โ
a false negative would disconnect working wallets on every payment. Injected wallets return
null: they are in-process and have no socket to lose.
Every wallet call also has a timeout now, including the chain-switch handshake and the Base
sendTransaction, which had none. On a wallet app, a timeout is reported as "your wallet never
received the request" with a reconnect, since that is what it almost always means.
walletApprovedChainIds() is a related guard: a WalletConnect wallet silently drops requests for
a chain outside its approved session, so if the connected wallet never approved the active chain
the app follows it to one it did.
The default chain is Base
DEFAULT_CHAIN in src/constants/index.ts is BASE, and everything forward-looking reads
from it: the chain a freshly connected wallet lands on, the token picker's seed before a wallet
is connected, and the chain an agent link approves when the caller doesn't name one. Celo is
fully supported and switchable โ nothing was dropped, it just isn't where you start.
Chains registered in wagmi.ts, in order: Base, Base Sepolia, Celo, Celo Alfajores. wagmi
treats chains[0] as the default and offers the rest as optional WalletConnect namespaces, so
a Celo-only wallet still connects fine (see the Valora row above). Note the app's own non-wagmi
paths (src/lib/chain.ts, page.tsx) use viem's celoSepolia as the Celo testnet, while
wagmi.ts still lists celoAlfajores; mainnet is unaffected, but they should be reconciled if
testnet WalletConnect flows are exercised.
LEGACY_RECORD_CHAIN is the deliberate counterpart, and it stays CELO. It is how a
stored row with an empty blockchain column is read โ such rows predate the column being
written and were all on Celo. It must not follow DEFAULT_CHAIN: reading an old Celo payment as
Base would send the webhook hunting for a receipt on the wrong chain and strand a real payment
as unvended.
Stablecoins: USDโฎ and USDC on both chains, plus USAT on Celo mainnet only. Which token
a chain leads with, and in what order the rest follow, is TOKEN_ORDER_BY_CHAIN in
src/constants/index.ts โ Base: USDC then USDโฎ; Celo: USDโฎ, USDC, USAT. One
tokensForChain() serves the Pay tab, the Agent Hub, the chat agent and the MCP tools โ one
function, so all four always agree on which tokens a chain offers.
๐ Project Structure
src/
โโโ app/
โ โโโ page.tsx # Main storefront (pay flow, wallet connect, history, env detection)
โ โโโ admin/page.tsx # Admin ops dashboard (incl. the kill-switch toggles)
โ โโโ docs/page.tsx # Docs & FAQ page
โ โโโ terms/, privacy/ # Legal pages (standalone routes; the in-app modals live in components/Modals.tsx)
โ โโโ .well-known/ # OAuth discovery metadata, incl. the RFC path-insertion variants
โ โ โโโ oauth-authorization-server/{route.ts, api/mcp/route.ts}
โ โ โโโ oauth-protected-resource/{route.ts, api/mcp/route.ts}
โ โโโ api/
โ โโโ pay/ # Core payment + vending endpoint (pay/x402/ is the x402 rail)
โ โโโ paymaster/ # Server-side proxy for Base gas-sponsorship (keeps the CDP paymaster key off the client)
โ โโโ providers/ # Live VTpass provider catalogue for the browser's pickers
โ โโโ requery/ # Delayed/timeout transaction requery
โ โโโ rate/, admin/rate/ # Exchange rate endpoints
โ โโโ variations/ # VTpass service variation lookups
โ โโโ intl/, foreign/ # International bill pay (countries/products/operators/rates)
โ โโโ verify/ # Meter/account/customer verification
โ โโโ admin/ # Admin data, actions, refunds, health
โ โโโ discounts/ # Discount campaign lookup
โ โโโ schedules/ # Recurring + one-off scheduled bill execution
โ โโโ user/points/ # AbaPoints balance
โ โโโ agent/ # Agent link/allowance management (Agent Hub)
โ โโโ deai/ # Conversational AI agent
โ โโโ mcp/ # MCP server (describe_capabilities, check_balance, list_plans, pay_bill, pay_bill_batch, schedule_bill, list_schedules, cancel_schedule)
โ โโโ oauth/{register,authorize,token}/ # OAuth 2.1 (DCR, consent page, token endpoint) for MCP
โ โโโ cleanup/ # Stale pre-flight intent sweeper
โ โโโ webhook/, webhook/vtpass/ # VTpass + on-chain webhooks
โ โโโ monnify/ # Moniepoint bank list, account resolve/verify, transfer webhook
โ โโโ telegram/webhook/, whatsapp/webhook/, x/webhook/ # Bot channel webhooks
โ โโโ support/ # Support ticket submission
โโโ components/ # Shared UI (AppFooter, Modals โ Terms/Privacy/FAQ/Receipt โ, tabs, AIChat, AgentHub, Admin panels)
โโโ config/wagmi.ts # Wallet/chain configuration (injected, Base Account, WalletConnect)
โโโ constants/ # Supported tokens, services, initial country list
โโโ lib/
โ โโโ vtpassCatalog.ts # โญ Live VTpass provider catalogue + per-provider amount limits
โ โโโ providerFallback.ts # Offline seed used only when VTpass is unreachable
โ โโโ monnify.ts # Moniepoint (Monnify) API client โ banks, verify, transfer
โ โโโ monnifyVend.ts # Bank transfer vend + finalize (success/failure/refund)
โ โโโ serviceRules.ts # Kill switches, operator agent caps, min/max amounts
โ โโโ refunds.ts # Refund queue (enqueue on vend failure + user notification)
โ โโโ vend.ts # Shared vend execution for the contract and x402 rails
โ โโโ attribution.ts # Celo Builders on-chain attribution tag (ERC-8021 dataSuffix)
โ โโโ parity.ts # Shared validation so chat/MCP match the web form
โ โโโ deai/ # Intent parsing, capabilities, selection, relayer (payBillFor),
โ โ # mcpAuth.ts (API key), mcpOAuth.ts (OAuth token lifecycle)
โ โโโ ... # VTpass, Telegram, WhatsApp, scheduler, discount helpers
โโโ utils/ # Supabase client, admin auth, PIN hashing
contracts/
โโโ AbaPay.sol # V1 โ original escrow/vault smart contract
โโโ AbaPayV2.sol # V2 โ hardened (see below)
โโโ AbaPayV3.sol # V3 โ adds agent-initiated payments (โ ๏ธ NOT AUDITED)
scripts/
โโโ deployV4.ts # Deploy V4 (whitelists tokens, sets relayer + per-tx caps)
โ๏ธ Environment Variables
Create a .env.local file in the project root. Never commit this file to GitHub.
App / Network Config
NEXT_PUBLIC_APP_MODE=sandbox # sandbox | production
NEXT_PUBLIC_NETWORK=celo-sepolia # celo-sepolia | celo | base | base-sepolia
NEXT_PUBLIC_FIXED_RATE=1550.00 # Fallback NGN exchange rate
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_walletconnect_project_id
NEXT_PUBLIC_WC_RELAY_URL= # Optional. Override the WalletConnect relay โ see "Blocked networks" below
Blocked networks
Connecting an external wallet depends on third-party hosts that some networks filter โ
chiefly relay.walletconnect.org (the WalletConnect relay) and api.web3modal.org (the
wallet chooser). Because the relay is a WebSocket, a block produces silence rather than
an error, which reads to the user as "the Connect button is broken".
This is confirmed on at least one carrier โ the connect flow works over a VPN and hangs
without one โ but we have no data on how many networks or regions are affected. No
user-facing copy names a carrier or country, deliberately: telling someone their problem is
carrier X when they are not on carrier X just makes them distrust the message. /network-check
reports what is actually blocked for the user in front of it.
Two things address this:
/network-check โ a page any user can open that probes each dependency from their own
connection and names the ones that fail. It is linked from the connect-failure banner and
from the FAQ, and doubles as the evidence to quote in a complaint to whichever carrier or
regulator turns out to be involved.
NEXT_PUBLIC_WC_RELAY_URL โ point this at a WebSocket reverse proxy on a domain of
yours that isn't filtered (e.g. wss://relay.abapays.com forwarding to
wss://relay.walletconnect.org) and WalletConnect wallets start working on those networks.
Relay traffic is end-to-end encrypted, so the proxy is a pipe, not a man-in-the-middle.
Note that Vercel functions cannot proxy long-lived WebSockets โ host it on Cloudflare
Workers, Fly.io, or a VPS running nginx with proxy_pass and the Upgrade headers.
MiniPay, Base App and Farcaster need none of these hosts โ the first two inject a provider
straight into the page and Farcaster supplies its own wallet through the Mini App SDK. They
stay reliable on a filtered network, and are what the app recommends when a connect fails
(RELAY_FREE_SURFACES in src/lib/walletEnv.ts).
Smart Contracts (per chain)
NEXT_PUBLIC_ABAPAY_ADDRESS=0xYourDefaultContractAddress
NEXT_PUBLIC_ABAPAY_CELO_ADDRESS=0xYourCeloContractAddress
NEXT_PUBLIC_ABAPAY_BASE_ADDRESS=0xYourBaseContractAddress
ADMIN_WALLET_ADDRESSES=0xYourOpsWallet # optional; admins for /admin (never the vault owner). See ENV_SETUP.md
CELO_PRIVATE_KEY=your_deployer_private_key # Used only by Hardhat for deployment โ never expose client-side
PAYMASTER_URL=https://api.developer.coinbase.com/rpc/v1/base/your_cdp_api_key # Server-only โ never NEXT_PUBLIC. The app proxies wallet paymaster requests through /api/paymaster so this key never reaches the browser.
โ ๏ธ Two things this env var alone won't cover, both configured in external dashboards:
- Coinbase Developer Platform: create a Paymaster Policy allowlisting your
NEXT_PUBLIC_ABAPAY_BASE_ADDRESS contract (and ideally the specific payBill/approve selectors), with a funded/budgeted balance to sponsor from.
- Alchemy webhook config: make sure the "Token" activity category is enabled on your Base webhook (not just "External"). Under gas sponsorship, the top-level transaction's
to is the bundler/EntryPoint contract, not your AbaPay contract directly โ only Token-category (ERC-20 Transfer log) monitoring reliably fires regardless of call depth.
VTpass (Bill Payment Provider)
VTPASS_API_KEY=your_api_key
VTPASS_PUBLIC_KEY=PK_your_public_key
VTPASS_SECRET_KEY=SK_your_secret_key
VTPASS_MSG_TOKEN=VT_PK_your_token
VTPASS_MSG_SECRET=VT_SK_your_secret
Monnify (Moniepoint's API โ Bank Transfer Provider)
MONNIFY_API_KEY=MK_your_api_key
MONNIFY_SECRET_KEY=your_secret_key
MONNIFY_CONTRACT_CODE=your_contract_code
MONNIFY_SOURCE_ACCOUNT_NUMBER=your_wallet_account_number
See ENV_SETUP.md ยง9b for where to find these and the MFA/webhook setup steps.
Supabase (Database)
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key # Server-side only โ full DB access
Email (Resend)
RESEND_API_KEY=re_your_resend_key
AI Agent (DeAI)
ANTHROPIC_API_KEY=sk-ant-... # Claude powers the DeAI intent engine (replaced Gemini).
DEAI_INTERNAL_SECRET=any_long_random_string # Optional. Signs internal calls to the DeAI brain so /api/deai/* can't be hit directly from the internet, AND signs the agent's payment deep links. Falls back to SUPABASE_SERVICE_ROLE_KEY if unset.
How DeAI actually pays (non-custodial): there is no server-side key for the user (there
must never be one; that would make AbaPay a custodian), so the agent does everything except
hold keys. Two paths exist:
- Deep link (V1/V2 contracts, or a user without an allowance): the agent parses the
request with Claude, verifies the meter/account against real VTpass, confirms details in
chat, then returns a signed, 15-minute deep link that opens the app pre-filled. The user
taps, their own wallet signs, and the payment runs through the same verified pipeline as the
web app.
- Delegated allowance (AbaPayV3,
src/lib/deai/relayer.ts): if the user has granted an
on-chain spendingAllowance (see AbaPayV3
below), the relayer calls payBillFor() directly โ no deep link, no signature at payment
time โ bounded entirely by the allowance the user set and revocable by them at any moment.
Before broadcasting, a preflight_<wallet>_<timestamp> transaction row is written (the same
idea as the web app's server-issued preflight_<uuid> intent ahead of a signature), then renamed to the real tx hash once
confirmed โ so the payment is vended through the exact same verified pipeline as every other
rail, and a stale/abandoned attempt is swept automatically rather than left dangling. If the
RPC can't confirm the receipt in time (a network hiccup right after broadcast โ including
right after the user enters their PIN), the agent reports it as pending, not failed, and
will never hand out a duplicate payment link for that same intent โ avoiding both a lost
payment and a double-charge. If no allowance is approved for the chain/token a payment needs,
the agent detects that before ever attempting the relay and offers a choice: approve it now
in the Agent Hub, or complete just this one payment via a signed deep link.
Telegram
TELEGRAM_BOT_TOKEN=your_admin_bot_token
TELEGRAM_ADMIN_CHAT_ID=your_admin_chat_id
TELEGRAM_CHAT_ID=your_default_chat_id
TELEGRAM_WEBHOOK_SECRET=your_webhook_secret
SUPPORT_TELEGRAM_BOT_TOKEN=your_support_bot_token
DEAI_TELEGRAM_BOT_TOKEN=your_deai_bot_token
WhatsApp Cloud API
WHATSAPP_ACCESS_TOKEN=your_whatsapp_access_token
WHATSAPP_PHONE_NUMBER_ID=your_phone_number_id
WHATSAPP_VERIFY_TOKEN=your_verify_token
WHATSAPP_APP_SECRET=your_meta_app_secret # โ ๏ธ REQUIRED. Verifies the X-Hub-Signature-256 on inbound webhooks so senders can't be spoofed.
WHATSAPP_SCHEDULE_TEMPLATE_NAME=schedule_update # Approved utility template used when the 24h window has closed. Unset = scheduled payments go unreported on WhatsApp.
WHATSAPP_SCHEDULE_TEMPLATE_LANG=en # Must match the template's language exactly ('en' and 'en_US' are different templates).
The 24-hour window, and why the scheduler needs a template
๐ต WhatsApp lets a business send free-form text only within 24 hours of the user's last
message. Outside that window Meta rejects the send with error 131047 and the only thing
that gets through is a pre-approved template.
Business Verification does not lift this. Verification governs how many unique people you
may message outside a window (250 โ 1,000 โ higher); it has no bearing on what you may send
them. The two are independent.
src/lib/scheduler.ts is the caller this affects: a payment scheduled for tomorrow reports back
long after the chat that created it went quiet โ outside the 24h window by design, which is why
that report always goes through the approved WHATSAPP_SCHEDULE_TEMPLATE_NAME template instead
of free-form text.
sendWhatsAppMessage() now sends text first (free, and correct while the window is open) and
retries through the template only on 131047. Any other failure โ expired token, blocked
recipient โ is not retried, since re-sending costs quality rating for nothing.
To make it work, create the template in WhatsApp Manager โ Templates, category Utility,
with exactly one body variable:
AbaPay scheduled payment update:
{{1}}
Open AbaPay to see the full receipt in your History.
Then set WHATSAPP_SCHEDULE_TEMPLATE_NAME to its name. Utility templates sent inside an open
window are free, so the fallback costs nothing in the common case.
โ ๏ธ Template body parameters may not contain newlines, tabs, or 4+ consecutive spaces โ Meta
rejects the whole send. Every scheduler message is multi-line, so toTemplateParameter()
flattens them (paragraph breaks become โ) and truncates at Meta's 1024-character cap. Covered
in tests/whatsapp.test.ts.
โ ๏ธ WHATSAPP_APP_SECRET is required, not optional. The webhook fails closed: with it
unset, POST /api/whatsapp/webhook returns 503 Webhook not configured and every delivery
from Meta is rejected โ the bot goes completely silent with no other symptom. That's deliberate:
without the secret there's no way to verify the X-Hub-Signature-256 on an inbound webhook,
which would otherwise let anyone impersonate any sender. It does mean forgetting to set it
looks exactly like the bot being broken.
To check a live deployment, POST an unsigned body at the webhook and read the status:
503 = the secret is missing; 401 Invalid signature = the secret is set and the gate is
working. Find the value in Meta App Dashboard โ App Settings โ Basic โ App Secret. The same
fail-closed rule applies to TELEGRAM_WEBHOOK_SECRET and X_CONSUMER_SECRET.
X_BEARER_TOKEN=your_bearer_token
X_CONSUMER_SECRET=your_consumer_secret # โ ๏ธ REQUIRED โ the webhook returns 503 without it (same fail-closed rule as WhatsApp).
X_BOT_ACCOUNT_ID=your_bot_account_id
On-Chain Webhooks (Alchemy)
ALCHEMY_WEBHOOK_SECRET=your_alchemy_base_webhook_secret
ALCHEMY_CELO_WEBHOOK_SECRET=your_alchemy_celo_webhook_secret
Contract Verification
ETHERSCAN_API_KEY=your_etherscan_or_celoscan_api_key
Agent Relayer (AbaPayV3 โ autonomous bill payments)
RELAYER_PRIVATE_KEY=0x... # โ ๏ธ HOT KEY. Only needed if you deploy AbaPayV3 and enable agent payments.
NEXT_PUBLIC_APP_URL=https://abapays.com # Used to build agent payment deep links.
โ ๏ธ Understand the blast radius before enabling this. The relayer key can spend at most each user's remaining on-chain allowance, and only via payBillFor. It cannot drain a user's wallet, raise anyone's allowance, or withdraw the vault โ those bounds are enforced by the contract, not the backend. If the key leaks, the owner calls setRelayer(address(0)) and it is instantly dead. Fund it with gas only; it should never hold token balances.
Agent Identity (ERC-8004) โ one-time registration only
ERC8004_AGENT_URI=https://abapays.com/.well-known/agent.json # Used only by scripts/register8004.ts
ERC8004_REGISTRY_CELO_MAINNET=0x8004A169FB4a3325136EB29fA0ceB6D2e539a432 # Optional override
ERC8004_REGISTRY_CELO_SEPOLIA=0x8004A818BFB912233c491871b3d84c89A494BD9e # Optional override
ERC8004_REGISTRY_BASE_MAINNET=0x8004A169FB4a3325136EB29fA0ceB6D2e539a432 # Optional override โ same address as Celo mainnet, confirmed byte-identical via eth_getCode
NEXT_PUBLIC_ERC8004_AGENT_ID= # Optional. Set after registering, for UI display.
Uses the same CELO_PRIVATE_KEY Hardhat already has configured โ this is identity registration only, it never touches payments.
How to register: identity is per-chain โ there's no cross-chain agent record, so this is run once per chain, and both registrations point at the same agent.json URL.
- Deploy
public/.well-known/agent.json (edit its wallet.address to your real RELAYER_ADDRESS first) so it's reachable at https://<your-domain>/.well-known/agent.json.
- Set
ERC8004_AGENT_URI above to that URL.
npx hardhat run scripts/register8004.ts --network sepolia first โ confirm the tx on Celo Sepolia Celoscan and check the Registered event for the correct URI and agent ID.
- Only after that passes:
npx hardhat run scripts/register8004.ts --network celo โ spends real gas, mints the Celo identity permanently (AbaPay's live Celo agent ID: 9687).
- Separately,
npx hardhat run scripts/register8004.ts --network base โ mints the Base identity (AbaPay's live Base agent ID: 59561). Same URI, different registry/chain, different agent ID.
- Set
NEXT_PUBLIC_ERC8004_AGENT_ID to the agent ID the script prints. Look up either identity at 8004scan.io.
Both registrations only ever store the URL, not the card's contents, so editing agent.json (e.g. to add a new declared service) changes what the URL returns with no new transaction. But that alone is not enough for a scanner like 8004scan to notice: indexers appear to snapshot the card at registration time rather than polling the URL on a schedule, so there's no on-chain signal telling them anything changed. scripts/update8004uri.ts closes that gap โ it calls the registry's setAgentURI(agentId, sameURI), re-emitting a fresh URIUpdated event (without changing the URI itself) purely to give an indexer something new to react to:
ERC8004_AGENT_ID=9687 ERC8004_AGENT_URI=https://abapays.com/.well-known/agent.json npx hardhat run scripts/update8004uri.ts --network celo
ERC8004_AGENT_ID=59561 ERC8004_AGENT_URI=https://abapays.com/.well-known/agent.json npx hardhat run scripts/update8004uri.ts --network base
Run this any time agent.json's contents change (like the mcp service entry above) and you want an already-registered identity to be re-read.
x402 Settlement (main app, Celo + USDC/USDโฎ/USAโฎ)
CELO_X402_API_KEY=your_x402_celo_org_api_key # Server-side: settles via api.x402.celo.org
No client-side SDK key is needed: the payer's EIP-3009 authorization is signed by the wallet
the user already connected (src/lib/x402Pay.ts), not by a second wallet SDK.
NEXT_PUBLIC_X402_ENABLED= # Default ON. Set to "false" to use the contract call instead
x402 is the default settlement rail on both chains โ USDC, USDโฎ, or USAโฎ on Celo (each settling
against its own EIP-712 domain) and USDC on Base โ so payments are genuinely indexed on
x402scan rather than being relabeled contract calls. Anything without EIP-3009 uses the normal
contract call. It never touches the agent-initiated flow, since x402 needs a fresh signature per
payment. Distinct infra from RELAYER_PRIVATE_KEY above.
โ ๏ธ Expect some wallets to warn about the signature, and know why. x402 settles via an
EIP-3009 transferWithAuthorization โ a signature permitting a third party to move the tokens.
That is structurally the same request a token-drainer makes, so some wallet security scanners
flag it: Zerion has shown AbaPay's own request as "Malicious Request โ Approving this may risk
total asset loss." on a routine bill payment, while the same payment via the contract call
reads as an ordinary Send with "No Risks Found". This is inherent to how x402 works โ the very
property that makes a payment provable on x402scan is what the scanners object to โ not a fault
in the request. It is a deliberate trade.
Escape hatches, per chain: NEXT_PUBLIC_X402_ENABLED=false moves everything to the contract-call
rail; NEXT_PUBLIC_BASE_X402_ENABLED=false moves only Base. Both default to on.
x402 runs on every wallet, every environment and both chains โ Valora's WalletConnect hang
(see the wallet-connection section above) happens at the same point on a plain
eth_sendTransaction with no signature involved, so restricting x402 to in-browser wallets would
buy nothing there; the settlement rail isn't the variable.
๐ต The one real limit is the TOKEN, not the chain and not the wallet. x402 settles on an
EIP-3009 transferWithAuthorization signature, so it only works on tokens that implement one.
Celo's USDC, USDโฎ, and USAโฎ all do; on Base, USDC does and Tether's USDโฎ does not โ there is no such
function on that contract to sign against.
That is why the chain's lead stablecoin matters so much. Base leads with USDC
(TOKEN_ORDER_BY_CHAIN), so the default path on Base is x402. The token-reset effect is
keyed on chain ID: switching chain always resets the selected token to that chain's lead
stablecoin (unless the user deliberately picked the other one), rather than only resetting when
the previously-selected token doesn't exist on the new chain at all โ since USDโฎ exists on both
chains but only settles via x402 on Celo, a reset that fires solely on token-existence would
silently carry USDโฎ over from Celo to Base and demote that user to the contract-call rail.
Settlement runs through Celo's own x402 facilitator (api.x402.celo.org mainnet /
api.x402.sepolia.celo.org testnet โ built by Celo Core Co.), not thirdweb. thirdweb is
still used client-side only, for useFetchWithPayment's wallet-signing plumbing (protocol-
generic โ it reads the payment challenge from the response body, which works against any
compliant facilitator, not just thirdweb's own). Chosen over thirdweb's own facilitator
because: flat $0.001/settlement via prepaid credits vs. thirdweb's ~0.3% cut, no
billing plan required to settle on mainnet (thirdweb requires one or every mainnet
settlement fails with DELEGATION_CHECK_FAILED), and genuinely non-custodial โ the signed
payment authorization pays the vault directly, with no intermediate hop through the
facilitator's own wallet.
How to get the API key:
- Go to x402.celo.org โ Connect wallet (any wallet works โ this is just to sign a free, gasless message, not a transaction).
- You're issued an API key instantly, plus free credits (500 mainnet, 1000 testnet at time of writing) โ the full key is shown only once, copy it immediately.
- Set
CELO_X402_API_KEY to that key โ the same key works for both the mainnet and testnet endpoints, which are tracked as separate credit pools.
- Top up credits (USDC deposit, $1 โ 1,000 credits) from the same dashboard before you run out โ
/settle starts returning 402 at 0 credits, and the app sends a Telegram alert when that happens (see src/app/api/pay/x402/route.ts).
- Nothing else to sign up for โ the client side needs no SDK account. The payment authorization is signed by the wallet the user already connected, through the app's own viem wallet client (
src/lib/x402Pay.ts).
- Add the var to
.env.local and your hosting provider's production environment variables, then redeploy โ NEXT_PUBLIC_* vars are baked in at build time, so existing deployments won't pick up a change without a rebuild.
Cron / Maintenance
CRON_SECRET=any_long_random_string # Optional. Protects /api/cleanup and both /api/schedules/run* endpoints.
Stale abandoned pre-flight intents are swept automatically and opportunistically from inside the webhook (throttled, non-blocking) โ this needs no Vercel cron and works on the free/Hobby plan. /api/cleanup remains available for manual runs or an external free scheduler (cron-job.org, GitHub Actions) if you want a guaranteed cadence during quiet periods.
Scheduled Bills / Autopay Agent โ these two DO need an external cron to actually run:
unlike the webhook-driven cleanup above, nothing calls these on its own.
/api/schedules/run โ recurring bills (monthly/weekly/daily). Register once or twice a
day at cron-job.org (free) hitting POST https://<your-domain>/api/schedules/run
with header Authorization: Bearer <CRON_SECRET> (or x-cron-secret: <CRON_SECRET>).
/api/schedules/run-instant โ one-off future payments from the DeAI chat ("buy me MTN
airtime in the next 10 minutes"). Needs a much tighter cadence to actually land close to
the requested time โ register a separate free cron-job.org job hitting
POST https://<your-domain>/api/schedules/run-instant every 1โ5 minutes. It's cheap
even at that frequency: the query is scoped to frequency = 'once' rows only, so most
ticks find nothing due and return immediately.
Without registering these, users can still create schedules (recurring or one-off) from the
chat, but nothing will ever execute them โ they'll sit is_active forever with no cron to
pick them up.
Dune dashboards โ refreshed daily, automatically:
DUNE_API_KEY=your_dune_api_key # Required by /api/cron/dune-refresh
There are three public dashboards on the abapay Dune team, and /api/cron/dune-refresh
re-runs all of them:
The per-chain dashboards exist because on the combined one every per-chain figure is a slice
of a Celo+Base total, so per-chain user counts, DAU and new-vs-returning are all mixed. Each is
scoped to its own chain at the source, and each tracks both contract deployments on that
chain so history doesn't restart at a redeploy:
- Base:
0xC0A4dAA04DEd9c54D1239507B5A5E645761ef488 (AbaPayV4, current) and
0xF3AeFF0c326B1277A2D8623b7694aEB5E6A565e5 (the original AbaPay V1). SQL in
dune/base-chain/, deployed with node scripts/dune-base-setup.mjs.
- Celo:
0x5df8aE2B963165b735B18Ca86B1ea448d2AA032C (AbaPayV4, current) and
0x42Fa463798Ed129a9B5Ee51721CB6db1bfCBe3b9 (AbaPayV3, original). SQL in
dune/celo-chain/, deployed with node scripts/dune-celo-setup.mjs. Its
agent-vs-direct-vs-x402 rail split (12_by_rail.sql) is deliberately kept as the dashboard's
headline chart, unlike Base's equivalent โ see that directory's README for why.
See each directory's own README for the full detail.
Automatic daily refresh โ two mechanisms, both required:
| Layer | What keeps it fresh | When |
|---|
Data โ one materialized view per dashboard (dune.abapay.result_abapay_unified_payments, dune.abapay.result_abapay_base_events, dune.abapay.result_abapay_celo_events) | Dune's own matview cron | 02:00 UTC daily |
| Panels โ the queries that have charts across all three dashboards | .github/workflows/dune-refresh.yml โ /api/cron/dune-refresh | 03:15 UTC daily |
The workflow needs two repository secrets, APP_URL and CRON_SECRET.
โ ๏ธ Something outside this repo also calls ?dashboard=main. On 2026-08-15 the only workflow
run started 03:51 UTC, yet the five main panel queries were executed again at 05:15:03โ05:15:10
โ 1.5s apart, which is this route's own SPACING_MS, so it is this endpoint being called by
another scheduler (a Vercel dashboard cron or an external cron service predating the workflow).
It is not harmful, but it masks failures: main gets a second attempt each day and therefore
always looks healthy, while base โ which nothing else covers โ stays stale whenever the
workflow run fails. Worth finding and removing so both dashboards have the same single owner.
A refresh is only "done" when the execution COMPLETES. /execute returning an
execution_id means Dune accepted the job, not that the query ran: an accepted execution can
still end QUERY_STATE_FAILED, leaving the panel on yesterday's result while the cron reports a
clean 200. The route therefore polls every execution to a terminal state and makes one spaced
retry pass over whatever genuinely didn't refresh, and the two dashboards are separated by 60s
so the second one doesn't start into a rate limiter the first one just saturated. base is
always the second call, which is why it was always the casualty.
A dashboard panel renders the last execution of the query behind it, and refreshing a matview
does not count as an execution of that query. So the matview cron alone never moves a panel โ
the combined dashboard sat six days stale while its matviews were refreshing every six hours โ
and executing the queries alone would only re-aggregate a stale table. Both halves, every day.
Why not use Dune's own scheduler? Its built-in query scheduler runs only on the medium
and large engines, and the community_fluid_engine_v2 plan has neither โ requesting medium
returns "Performance medium is not supported for this dataset", so the in-app schedule never
fires however it is configured. Matview crons are the one piece of Dune-native scheduling that
does work on this plan, which is why the data layer uses them and the panel layer uses the API.
Each dashboard has a root query that feeds the matview the rest aggregate. The cron
deliberately does not execute the roots: neither has a chart of its own, so running one costs
credits to update nothing. Every query the cron does execute reads a matview rather than raw
chain tables โ well under 1 credit for all ten, against a 2,500/month quota. A few queries
are deployed but kept off the dashboards; the cron deliberately skips those, because executing
a query with no panel spends credits updating something nobody can see.
๐ Installation & Setup
-
Clone the repository
git clone https://github.com/investorphem/abapay.git
cd abapay
-
Install dependencies
-
Set up environment variables โ copy the variables above into .env.local.
-
Run the development server
-
Access the application
Smart Contract Development (Hardhat)
npx hardhat compile # Compile contracts
npm run test:contracts # Run the Solidity test suite
npx hardhat run scripts/deployV4.ts --network <network> # Deploy V4 (agent-initiated payments, adjustable withdrawal delay)
npx hardhat run scripts/register8004.ts --network <network> # Register the agent identity (ERC-8004)
npx hardhat run scripts/update8004uri.ts --network <network> # Re-push the agent URI so an indexer (8004scan) re-reads it
AbaPayV2.sol โ hardened contract (โ ๏ธ NOT YET AUDITED)
contracts/AbaPayV2.sol is a security-hardened successor to the original AbaPay.sol,
addressing the hardening gaps below. payBill's signature and the
PaymentReceived event are byte-for-byte identical to V1, so the frontend and the shared
PaymentReceived verifier (src/lib/paymentProof.ts) work with no backend changes.
| Hardening | Why |
|---|
SafeERC20 | Non-compliant tokens (e.g. some USDT deployments) don't return a bool; raw require(transfer(...)) breaks on them. |
ReentrancyGuard | setTokenSupport can whitelist any token; a hook-bearing token would otherwise make payBill reentrant. |
Pausable | V1 had no kill switch โ a post-deploy vulnerability could not be stopped. Refunds stay live while paused so users can be made whole. |
Ownable2Step | Prevents permanently bricking the contract by transferring ownership to a typo'd address. |
| Timelocked withdrawals | The biggest V1 risk: a single compromised owner key could drain the entire pooled vault instantly. Withdrawals must now be queued, then executed after a delay โ alert on WithdrawalQueued and cancel if it wasn't you. Fixed at 24h in V2/V3; owner-adjustable in V4 (see below). |
| Capped refunds | V1's refundUser was an unrestricted "send any amount anywhere" path that bypassed any withdrawal control. Now bounded per-token (and fails closed until a cap is set). |
| Balance-delta accounting | Emits the amount actually received, so fee-on-transfer tokens can't cause the backend to over-vend. |
Before mainnet:
- Get a professional audit. This contract holds pooled customer funds; a static review is not sufficient.
- Set
ABAPAY_OWNER to a multisig (Safe), not an EOA. The timelock buys detection time โ it only stops an attacker if a stolen key can't unilaterally cancel and re-queue, and it buys nothing at all if the delay has been set to 0 (see V4 below).
- Deploy to testnet and run the full payment flow end-to-end first.
- Call
setMaxRefund for each token โ refunds revert until a cap is configured.
payBill still uses transferFrom(msg.sender, โฆ), so the payer must be the signer. Delegated
spending (the DeAI "pay from social media" feature) needs an additional on-chain allowance
mechanism and is deliberately out of scope for this hardening pass โ it should be designed
and audited as its own change.
AbaPayV3.sol โ agent-initiated payments (โ ๏ธ NOT AUDITED)
contracts/AbaPayV3.sol builds on V2 to solve the problem above: on Telegram/WhatsApp there is
no wallet to sign with, so the agent could previously only hand the user a deep link to sign in
the app. V3 adds a session-key / delegated-spend pattern instead:
- The user, from their own wallet, does two things once: a standard ERC-20
approve(AbaPayV3, X),
and setSpendingAllowance(token, X) โ an on-chain cap they control.
- After that, the authorised relayer (a backend hot key,
RELAYER_PRIVATE_KEY) may call
payBillFor() on their behalf โ but the contract itself checks and decrements the remaining
allowance on every call, so the cap is enforced on-chain, not by the backend.
| Bound | Enforced by |
|---|
| Per-user total exposure | spendingAllowance[user][token] โ settable only by the user, revocable instantly to 0 |
| Per-transaction ceiling | maxAgentPaymentPerTx[token] โ owner-set, a second bound on top of the user's own allowance |
| Blast radius of a stolen relayer key | Can spend at most a user's remaining allowance, only via payBillFor โ cannot drain a wallet, raise anyone's allowance, or withdraw the vault |
| Kill switch | Owner calls setRelayer(address(0)) to instantly disable the agent, or pause() to halt all payments |
โ ๏ธ Not audited. The contract itself carries this warning in its header. Deploy to testnet for
demos; on mainnet, keep maxAgentPaymentPerTx and maxRefundPerTx small (scripts/deployV4.ts
defaults to a $10-equivalent per token) until a professional audit is done, then raise them via
setMaxAgentPayment / setMaxRefund. The live V4 vaults are set to 50 per agent payment
and 400 per refund for each supported stablecoin. The expected values are in
config/vaults.json, and node scripts/vault-config.mjs diffs them
against the chain.
payBillFor emits the same PaymentReceived event as V1/V2 (so the webhook needs no changes),
plus an additional AgentPayment event so the backend/any observer can distinguish "the user
signed" from "the agent spent an allowance."
AbaPayV4.sol โ adjustable withdrawal delay
V4 is V3 plus one change: the withdrawal timelock is no longer a hardcoded 24 hours. It is a
variable, withdrawalDelay, that the owner can raise, lower, or set to 0 via
setWithdrawalDelay(n). A fresh deploy defaults to 24h. Both live vaults run at 0, a deliberate owner
choice, so withdrawals from them are instant (see the warning below). V4 is what is deployed on
both mainnets:
| Chain | AbaPayV4 |
|---|
| Base | 0xC0A4dAA04DEd9c54D1239507B5A5E645761ef488 |
| Celo | 0x5df8aE2B963165b735B18Ca86B1ea448d2AA032C |
โ ๏ธ The previous Celo contract 0x42Fa4637โฆ is a V3 โ it has no setWithdrawalDelay, so its
24h timelock is fixed and it can never be made instant. That is why Celo was redeployed rather
than reconfigured. It is now retired: every token is unsupported, its relayer is 0x0 and it
is paused. The old Celo V1 (0x1d125198โฆ) no longer accepts any token either.
The queue itself is not removable โ it is compiled into the bytecode and there is no direct
withdraw(). At delay 0 a withdrawal is queueWithdrawal then executeWithdrawal back to
back: two transactions, no waiting.
โ ๏ธ Changing the delay is not retroactive. A withdrawal's executableAt is stamped when it is
queued, so lowering the delay does not free one that is already sitting in the queue โ you have
to cancelWithdrawal and re-queue it under the new delay. Cancelling moves no money; the tokens
never leave the vault.
โ ๏ธ A delay of 0 removes the protection the timelock exists for. It is the reason a stolen
owner key cannot drain the vault before anyone notices. At 0, whoever holds the key can queue and
execute in the same minute. Treat it as an emergency setting and raise it back afterwards.
node scripts/instant-withdrawals.mjs --chain celo
node scripts/instant-withdrawals.mjs --chain celo --apply
node scripts/instant-withdrawals.mjs --apply --withdraw
node scripts/instant-withdrawals.mjs --chain celo --restore-delay 86400
ERC-8004 Agent Identity
scripts/register8004.ts registers AbaPay's DeAI agent as a real on-chain identity on Celo via
the ERC-8004 "Trustless Agents" registry
(0x8004A169FB4a3325136EB29fA0ceB6D2e539a432 on mainnet), so it's discoverable and browsable on
8004scan.io / AgentScan the same way any on-chain identity is. Registration mints an ERC-721
whose tokenId is the agent's ID, pointing at a public agent card (public/.well-known/agent.json)
that names the operational relayer wallet as the agent's on-chain address.
This is identity only โ it does not touch payments. The relayer's signature-free
payBillFor flow above is completely unaffected; registering (or not) has zero effect on how
bills get paid. Before running on mainnet, verify the register(string) selector against the
registry's verified source on Celoscan โ see the script's header comment.
MCP Server (AI Agent Payments)
src/app/api/mcp/route.ts implements a real MCP (Model
Context Protocol) server โ the same open standard Claude and other AI agents use to call
tools โ over Streamable HTTP (JSON-RPC 2.0: initialize, tools/list, tools/call), no
extra dependency required. It's a fourth channel into the same execution engine that
already backs Telegram/WhatsApp/X, not a parallel system with its own rules:
Building an agent that integrates AbaPay itself, with no human ever opening abapays.com?
See docs/AGENT_INTEGRATION.md โ the x402 zero-setup path,
and the fully headless (wallet-signature-only) way to self-serve an MCP API key. Writing
TypeScript? sdk/ (abapay-sdk on npm) wraps both into two functions. Python?
python-sdk/ mirrors it field-for-field and is on PyPI too โ
pip install abapay-sdk, published via a Trusted Publisher (no token secret) off the
py-sdk-v* tag; CI (not a local run โ no Python interpreter existed in the environment
that wrote it) is what actually verified it. Prefer a full book over a single doc? docs/ gitbook/ covers the same ground as 12 chapters (SUMMARY.md is the table
of contents โ Markdown, ready to sync into GitBook or any docs host that reads a repo
directly).
| Tool | What it does | Needs |
|---|
describe_capabilities | Human-readable menu of what AbaPay can pay and what's currently paused | Nothing โ public |
list_plans | The real, currently purchasable plans for DATA / CABLE / EDUCATION, with exact variation_codes and live VTpass prices | Nothing โ public |
list_international_options | Browses the live international catalogue (140+ countries) one level at a time โ country โ product type โ operator โ priced plan | Nothing โ public |
check_balance | Reads the linked wallet's live balance + approved agent limit, per token, on a chain | OAuth Bearer token or api_key |
transaction_history | Lists recent real transactions for the linked wallet โ same data as the app's History tab | OAuth Bearer token or api_key |
get_payment_status | Looks up one payment by tx hash or request id: delivered, still confirming, failed or refunded, with refund state. Scoped to the linked wallet | OAuth Bearer token or api_key |
pay_bill | Pays a real bill (airtime, data, electricity, cable TV, education PIN, or international airtime/data) end-to-end, on-chain | (OAuth Bearer token or api_key) + pin, always |
pay_bill_batch | Pays airtime/data to 2-20 recipients in one call, one PIN for the whole batch | (OAuth Bearer token or api_key) + pin, always |
schedule_bill | Sets up a recurring/one-off airtime, data, electricity, or cable payment โ same automation Telegram/WhatsApp/X support | (OAuth Bearer token or api_key) + pin, always |
list_schedules | Lists active schedules for the linked wallet | OAuth Bearer token or api_key |
cancel_schedule | Cancels one schedule by id, or several by provider / all: true (those need the PIN); a call with none of them is refused | OAuth Bearer token or api_key (+ PIN for bulk) |
list_plans exists so variation_code is never something the agent has to invent.
Its description, and the server-level instructions, both tell the client to call it before
pay_bill for those three services and to pass back a returned code verbatim โ never to guess a
plan, a code, or a price. If it returns nothing usable (which genuinely happens โ JAMB is not
enabled on this merchant account), the correct behaviour is to say so, not to fabricate a code.
pay_bill covers EDUCATION as well as airtime/data/electricity/cable, because MCP is meant
to be the same trust boundary as chat, not a narrower one. Every rule it needs is shared and
already existed: requiresVariation() forces a variation_code, checkAccountNumber() enforces
JAMB's โฅ10-character profile ID, and requiresVerifiedName() decides that only JAMB
merchant-verifies (WAEC has no account to verify). It also validates the provider against the
live VTpass catalogue up front, so an agent can no longer pass a provider VTpass cannot sell
and discover it only after the money has moved.
service: "INTERNATIONAL" completes the purchase, unlike chat. Chat's INTERNATIONAL handling
(src/app/api/deai/core/route.ts) only validates a request and then tells the user to finish it
in the app โ it has never actually vended one. MCP's pay_bill does: list_international_options
walks VTpass's country โ product type โ operator โ variation chain, and pay_bill re-fetches the
chosen variation itself to derive the NGN-equivalent price from its own variation_rate/
charged_amount โ never trusting a client-supplied amount, since that number is what prices the
on-chain charge. Only fixed-price plans are payable this way for now; flexible-amount plans
still redirect to the app.
Every successful pay_bill now returns a premium receipt, not just a text line. Alongside the
confirmation text, the response includes a branded receipt card (rendered server-side with
next/og's ImageResponse โ no extra dependency โ see src/lib/deai/receiptCard.tsx) and a link
to a shareable, public receipt page at /receipt/[request_id] (src/app/receipt/). The link is
keyed by request_id, not tx_hash: a transaction hash is visible to anyone watching the vault
address on-chain, and the receipt page โ being public and shareable by design โ must not let a
blockchain observer correlate a payment to the customer's verified name/address, so it never shows
the purchased code/PIN either. transaction_history gets the same rich treatment โ a statement
card image alongside the plain-text list โ for browsing past activity without opening the app.
pay_bill, pay_bill_batch, transaction_history, check_balance, list_schedules, and
describe_capabilities also render as a real interactive card via MCP Apps (SEP-1865) โ an open
MCP extension (io.modelcontextprotocol/ui, shipped as the protocol's first official extension
2026-01-26), not a first-party-only mechanism. The flat PNG above is a fixed image with Satori's
font-subsetting limits (โฆ/โฎ have to be worked around โ see receiptCard.tsx's own comment on
that); the interactive card (src/lib/deai/mcpUiTemplates.ts) is real HTML/CSS/JS rendered by
the host in a sandboxed iframe, fed the tool's structuredContent over
ui/notifications/tool-result โ real โฆ/โฎ glyphs, theme-aware (reads the host's CSS variables for
light/dark), with a "View receipt" link wired through ui/open-link. Declared via
_meta.ui.resourceUri on those six tools and served through two new /api/mcp methods,
resources/list/resources/read (src/app/api/mcp/route.ts) โ additive only: a host that never
negotiates the extension just never calls resources/read, and every tool behaves exactly as
before (text ยฑ PNG image), per the spec's own graceful-degradation rule.
The receipt card covers every real outcome of pay_bill, not just full success.
finalizePayBillResult builds the full receipt (image + structuredContent) for any
outcome that produced a real txHash โ SUCCESS, PENDING
(still confirming on-chain), or FAILED_VENDING (charged, refund pending) โ each with its own
status colour, label, and icon on the card; only a payment that never reached the chain falls back
to text-only.
The card is now a genuinely premium surface, and it's where "everything AbaPay offers" lives.
Every view (receipt, history, balance, schedules, batch, capabilities) shares one
gradient hairline border and drop shadow, real inline SVG icons (a distinct one per status โ
success/pending/failed-vending/failed โ and per service โ airtime/data/electricity/cable/
education/bank/international), and a fade-in transition that retriggers on every re-render, so
paging through history or hitting Refresh/Cancel doesn't feel like a static swap. describe_capabilities's
card (the new capabilities view, via getCapabilitiesForCard() in src/lib/deai/capabilities.ts)
lists every AbaPay service with its example phrasing, whether it's usable right here over MCP vs.
app-only, and a live Paused/Available badge sourced from the same kill-switch state chat reads โ
the closest thing to a full menu that can be shown safely without a PIN field inside a
third-party-rendered iframe (see the trust-boundary note below on why forms with a PIN aren't on
the card).
The card calls tools back, not just displays them. transaction_history's card pages through
history with Prev/Next (re-calling the tool with a shifted offset โ transaction_history now
accepts one), check_balance's card has a Refresh button, and list_schedules' card has a Cancel
button per schedule โ all using the spec's "Interactive Updates" pattern (the View sending
tools/call back through the host and getting a normal result straight back, not via a
notification). Deliberately not extended to pay_bill/pay_bill_batch/schedule_bill: those
need a PIN, and typing a spending PIN into a sandboxed third-party iframe is a weaker trust
boundary than typing it directly into the chat, which is the boundary the rest of this doc is
built around protecting. cancel_schedule for a single schedule id needs no PIN, which is why it's the one write
action the card exposes. Cancelling several at once (provider, or an explicit all: true)
does need the PIN, so the card never offers it.
Already-connected clients pick up new/changed tools without a manual reconnect โ mostly.
initialize declares tools: { listChanged: true }, and GET /api/mcp with
Accept: text/event-stream opens a real SSE stream that pushes
notifications/tools/list_changed the moment a client starts listening, prompting a fresh
tools/list. This matters because an already-connected client does NOT re-run initialize just
because a new chat starts โ it reuses one persistent connection to the connector indefinitely.
โ ๏ธ Not a guarantee by itself: Anthropic's own MCP
connector tracker has open, acknowledged reports of a remote connector's tool list staying stale
even across a manual reconnect (anthropics/claude-ai-mcp#137, #476) โ a client/platform-side
caching issue outside this server's control. Until that's fixed platform-side, "Refresh tools
list" from the connector's own โฎ menu in Claude.ai is the fastest manual fallback โ lighter than a
full disconnect/reconnect, no re-authorization needed.
Both accept optional chain/token overrides โ they default to whatever was approved when the
API key was created, but a caller isn't stuck with that default if it comes up short. check_balance
returns balance + approved limit for every stablecoin on the chain (not just the default one),
so an agent can see upfront whether an alternative is even viable. If pay_bill is attempted with
the default and it's short on balance or on-chain allowance, the error itself checks whether
another token on that same chain already has enough of both and says so by name โ e.g. "USDโฎ is
short, but USDC already has enough balance and an approved limit โ retry with token: 'USDC'" โ
rather than a dead-end message naming only the token that failed.
pay_bill_batch โ multiple recipients in one call, matching chat's batch payments.
Chat's intent engine has parsed "send 500 to X and 1000 to Y" into multiple recipients since
intentEngine.ts's rule 14; MCP's pay_bill only ever took one. pay_bill_batch reuses the
exact same primitives chat's own batch handler calls (groupByChainToken, checkAutonomousCapacity,
executeAgentPayment โ all in src/lib/deai/batch.ts): recipients are grouped by (chain, token)
and each group's capacity is checked against its own subtotal, but if any group comes up
short the whole batch is refused before anything moves. Once capacity clears, recipients are
paid one at a time (never in parallel, to avoid relayer nonce contention) and the response
reports each individually โ a vend failure partway through is never reported as if the whole
batch failed. One difference makes this MORE capable than chat, not just at parity: chat's
ParsedRecipient shape has no per-recipient variation_code field, so a chat-driven DATA batch
has no way to name each recipient's plan โ pay_bill_batch's structured schema does, so it
requires one per DATA recipient instead of inheriting that gap. AIRTIME and DATA only, capped at
20 recipients per call.
schedule_bill/list_schedules/cancel_schedule bring MCP to parity with chat's
automations. Telegram/WhatsApp/X support recurring and one-off scheduled bills
(the scheduled_bills table, run by src/lib/scheduler.ts's cron); MCP has the same
capability, so an agent can pay a bill immediately or schedule one for later. schedule_bill collects
in one call what chat gathers over a multi-turn conversation, reusing pay_bill's exact validation
(requiresVariation, checkAccountNumber, checkAmountLive, the live-catalogue provider check)
and PIN gate, since a schedule is a standing spend. It charges nothing itself: if the wallet's
approved on-chain allowance already covers the amount, the schedule auto-pays itself each time
it's due; otherwise it's saved notify-only and something else has to call pay_bill when it comes
due. EDUCATION and INTERNATIONAL aren't schedulable, matching chat. MCP has no persistent channel
to push a "your bill just ran" message back into later on its own, so schedule_bill accepts an
optional customer_email for that โ without one, check list_schedules/transaction_history
yourself to see what happened.
Why this exists: third-party agent scanners like 8004scan.io only run
a health check against a declared a2a or mcp service โ see public/.well-known/agent.json's
services array, which declares both. The MCP server behind that declaration is real and
working, not a stub added just to satisfy the scanner.
Same trust model as chat, not a new one. pay_bill doesn't reimplement any security logic โ
it calls straight into the functions already backing Telegram/WhatsApp/X and the multi-recipient
batch flow: checkPinAllowed/verifyPin/recordPinFailure (same escalating lockout),
checkServiceAllowed (kill switches), checkAccountNumber/checkAmount (parity validation),
checkAgentSpendAllowed (operator per-tx/daily caps), checkAutonomousCapacity +
executeAgentPayment (on-chain allowance check, the shared discount engine, and vend), and
notifySpendOutOfBand (email + every other linked channel is told the instant money moves, so a
leaked API key is caught exactly like a stolen chat session would be).
Rate limiting is defense in depth, layered on top of the above, not a substitute for it โ a
blanket per-IP limit across every MCP tool call, plus a tighter per-identity limit on pay_bill,
schedule_bill, and pay_bill_batch specifically. Full numbers and mechanics: see
Rate Limiting under Security Architecture.
Chain-agnostic โ Celo or Base, whichever the linking wallet approved. An MCP key inherits the
approved_chain/approved_token recorded when it was created (same fields Telegram/WhatsApp/X
already use), and check_balance accepts an explicit chain override. There is nothing
Celo-specific or Base-specific in the MCP layer itself โ it's the same multi-chain relayer
(src/lib/deai/relayer.ts) and balance reader (src/lib/deai/services.ts) every other channel
shares.
OAuth 2.1 โ authorize once, in a browser, and never retype an API key again.
The api_key/pin tool arguments work, but a brand-new Claude conversation remembers
nothing, so the human had to paste their API key every single time. The server now implements a
full OAuth 2.1 authorization-code flow with PKCE (S256 only) and Dynamic Client
Registration:
| Endpoint | Purpose |
|---|
/.well-known/oauth-protected-resource (+ /.well-known/oauth-protected-resource/api/mcp) | Tells the client this resource is OAuth-protected and where its authorization server is |
/.well-known/oauth-authorization-server (+ /.well-known/oauth-authorization-server/api/mcp) | Authorization-server metadata |
/api/oauth/register | Dynamic Client Registration (RFC 7591) โ no manual client setup |
/api/oauth/authorize | The consent page โ the only page a human ever sees |
/api/oauth/token | Code exchange + refresh, with refresh-token rotation |
Both discovery documents are served at the plain /.well-known/โฆ path and at the RFC
path-insertion variant with /api/mcp appended, because different clients probe different ones.
Things worth knowing about this implementation:
- The consent page proves both the API key and the PIN before an authorization code is
ever issued. A stolen API key alone is not enough to authorize a connector.
- OAuth never authorizes a spend. The PIN is still required on every
pay_bill call,
exactly as on Telegram/WhatsApp. A Bearer token on its own can read a balance and nothing more.
- Exactly one condition returns a real HTTP 401 (with
WWW-Authenticate +
resource_metadata): no credential supplied at all. That 401 is the only signal an MCP
client uses to discover "this server supports OAuth" and show a connect button. A wrong
API key, a bad PIN, or a malformed argument stay in-band tool errors โ turning those into 401s
would make the client re-run the whole browser flow over a typo.
redirect_uri is validated against the registered list before anything renders, and a
failure renders a plain error page rather than redirecting โ redirecting to an unvalidated URI
is precisely the open-redirect vulnerability that would leak the authorization code.
- The consent page is a hand-rendered, fully self-contained HTML string (inline
<style>, no
scripts, no fonts, no third-party assets) so it satisfies the app's CSP without exception and
can't be broken by anything else in the app, styled with AbaPay's own emerald wordmark.
- Refresh tokens rotate on every use (OAuth 2.1's requirement for public clients), so a
stolen refresh token stops working as soon as the legitimate client refreshes โ and the theft
becomes detectable instead of silent.
Linking (no new env vars, no new table): agent_links.channel gained an 'MCP' value
(supabase/migrations/019_mcp_channel.sql) alongside TELEGRAM/WHATSAPP/X. Unlike those,
there's no bot to "claim" a link code with โ from the app's Agent Hub tab, pick the MCP (AI
Agents) tile, set a PIN, and it mints a 256-bit API key shown exactly once (only its
SHA-256 hash is ever stored). A wallet can hold several MCP keys at once โ one per agent/tool โ
each with its own label.
Connecting an AI agent (end users):
- In the AbaPay app, approve an on-chain spend limit for whichever chain/token you want the
agent to use (Agent Hub โ step 1) โ this is the real ceiling; nothing below can exceed it.
- Still in Agent Hub, pick MCP (AI Agents), optionally label the key (e.g. "Claude"), set a
PIN, and save the API key it shows you โ it will not be shown again.
- Point your MCP client at
https://agents.abapays.com/api/mcp as a remote (Streamable HTTP)
server:
- Easiest โ claude.ai (web), no file editing: Settings โ Connectors ("Integrations" on
some accounts) โ Add custom connector โ paste
https://agents.abapays.com/api/mcp โ Save.
It's now available as a tool source in any new chat.
- Claude Desktop (local config file) โ merge this into
%APPDATA%\Claude\claude_desktop_config.json (don't overwrite the whole file if you already
have other servers configured there):
{
"mcpServers": {
"abapay": { "url": "https://agents.abapays.com/api/mcp" }
}
}
- Any other MCP client: the same URL, Streamable HTTP transport โ no API key or auth
header at the connection level; see step 4.
- Authorize. If your client supports OAuth (claude.ai and Claude Desktop do), it will offer
a Connect button โ click it, and AbaPay's own consent page asks for your API key and PIN
once, in the browser. Every future conversation reconnects automatically. If your client
can't do OAuth, pass the API key as the
api_key tool argument instead โ it's a tool
argument, not an HTTP header, so there's no separate app-level auth step.
- Your PIN is asked for on every payment either way. Authorizing the connector does not
authorize spending. If an agent claims it can pay without your PIN, something is wrong.
Every tool declares annotations (title, readOnlyHint/destructiveHint, idempotentHint,
openWorldHint) โ pay_bill is correctly flagged destructive/non-idempotent (it moves real
money and calling it twice pays twice), while describe_capabilities/check_balance are
read-only โ so a client can warn a user appropriately before letting an agent invoke it.
Getting listed in claude.ai's Connectors Directory (so users can find AbaPay by browsing/
searching instead of pasting the URL) is a separate step from what's built here โ it's an
organizational submission through Anthropic, not a code change:
- Requires a Team or Enterprise claude.ai organization (submission happens in
admin settings โ Directory โ New submission); only Owners (or a delegated role on
Enterprise) can submit.
- Requirements confirmed against Anthropic's own submission docs: tool
title +
readOnlyHint/destructiveHint annotations (โ
done above), a public documentation URL
(https://abapays.com/docs โ live), a privacy policy URL (https://abapays.com/privacy โ
live), an icon, and reviewer test-account credentials.
- OAuth 2.0 is in place. The directory requires OAuth for authenticated connectors, and
AbaPay has it (see the OAuth section above): authorization code + PKCE, Dynamic Client
Registration, discovery metadata, and a real 401 so clients can discover it. What remains for
a directory listing is the organizational submission itself (a Team/Enterprise org, an icon,
and reviewer test-account credentials) โ not code.
- Until submitted/approved, "Add custom connector" with the URL (above) is a fully working,
unrestricted way to use it today โ the directory only adds discoverability, not capability.
A2A Server (Agent2Agent)
The same tools, reachable by other agents over A2A instead of MCP.
Two files, no new capability:
| Surface | Path |
|---|
| Agent Card (discovery) | /.well-known/agent-card.json โ src/app/.well-known/agent-card.json/route.ts |
| JSON-RPC endpoint | /api/a2a โ src/app/api/a2a/route.ts |
One implementation, two protocols. The tool definitions and their implementations were moved
out of src/app/api/mcp/route.ts into src/lib/deai/mcpTools.ts, which both routes import.
/api/mcp and /api/a2a are now transport shims over one callTool(). That is deliberate:
A2A has no private path to money โ the PIN gate, escalating lockout, on-chain allowance ceiling,
kill switches and operator spend caps all live below both routes, so a new protocol changes how
an agent asks, never what it may do. (The move was mechanical; tool logic is byte-identical.)
โ ๏ธ /.well-known/agent-card.json is not /.well-known/agent.json. The latter is AbaPay's
ERC-8004 registration card โ the on-chain identity 8004scan and Aigora read. The two specs
collided on the agent.json filename historically, which is exactly why A2A moved its card to
agent-card.json. Different documents, different consumers; overwriting one with the other
silently breaks the agent's on-chain listing.
No LLM in the invocation path. Chat channels route free text through parseIntent() because a
human typed it. A2A is machine-to-machine, so invocation is a structured DataPart carrying
{ skill, args }, validated against the same TOOLS schema MCP publishes. A text part gets the
skill catalogue back rather than a guess โ re-interpreting "send 5000" with a language model in an
agent-to-agent payment path adds a failure mode with no upside.
Synchronous by design. Every skill completes inside the request, so message/send returns a
final Message (spec-legal) and no Task is created. The card therefore declares
streaming: false and pushNotifications: false, and tasks/* + message/stream return
-32004 UnsupportedOperation rather than being half-implemented โ there is no task store to
query, and declaring capabilities we don't have would strand a peer waiting on updates that never
arrive.
Auth. Authorization: Bearer โฆ accepts either credential MCP accepts, by prefix: an
aba_mcp_โฆ Agent Hub key, or an OAuth 2.1 access token. A2A has no per-call api_key argument,
so the header is the only place a credential can arrive. A missing credential and a wrong one
stay distinct conditions, same rule as MCP. pay_bill still requires the PIN on every call.
Operator control. CHANNEL_A2A in platform_settings.kill_switches โ separate from
CHANNEL_MCP so pausing one surface doesn't pause the other. No migration needed; the column is
free-form JSONB and a missing key reads as enabled.
Call it:
curl -X POST https://agents.abapays.com/api/a2a \
-H "Authorization: Bearer aba_mcp_โฆ" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"message/send","params":{"message":{
"kind":"message","role":"user","messageId":"1",
"parts":[{"kind":"data","data":{"skill":"check_balance","args":{}}}]}}}'
x402 Settlement (main app only)
โ ๏ธ On by default; NEXT_PUBLIC_X402_ENABLED=false falls back to the contract call. Note the
wallet-warning trade-off documented in the env section above โ the EIP-3009 signature x402
requires is structurally what a drainer asks for, so some scanners flag it.
The web app's payment flow settles via x402 โ through Celo's own
facilitator (api.x402.celo.org, built by Celo Core Co. โ see
src/app/api/pay/x402/route.ts), not thirdweb โ whenever the user is paying with USDC, USDโฎ,
or USAโฎ on Celo. Each token settles against its own EIP-712 domain (X402_TOKEN_EIP712 in that
route) since Circle's USDC and Tether's USDโฎ/USAโฎ deployments don't share one. The same "Confirm &
Pay" button routes through x402 for any of the three tokens on Celo and through the normal payBill
contract call for everything else (a token without EIP-3009, Base when NEXT_PUBLIC_BASE_X402_ENABLED=false,
or x402 unconfigured). This makes the payment genuinely visible on x402scan โ not a
relabeled transaction โ because x402 settlement requires an EIP-3009
(transferWithAuthorization) signature from the payer for that specific payment. That
requirement is also precisely why the scanners object.
The 402 challenge itself is built in-house (a plain x402 v1, body-based response) rather
than relying on any SDK's default โ that's a deliberate choice, since thirdweb's own
settlePayment() always delivers a fresh challenge via a base64 header with an empty JSON
body, which generic x402 scanners (x402scan's discovery crawler included) don't parse,
causing registration to silently fail with a correct-looking 402 status but no usable
challenge.
Client-side, the challenge is read, signed and retried by src/lib/x402Pay.ts using the same
viem wallet client every contract call uses โ one wallet connection for the whole flow, no
second stack alongside wagmi. Signing in-house also lets the page read the
server's actual answer: a settlement failure that carries a tx_hash means the money already
moved, and the app must never "retry" it on the contract-call rail.
The body-based (v1) challenge also carries a hint field โ outside the x402 spec, additive, and
ignored by any client that only reads the fields it knows about. Being able to sign an
EIP-3009 authorization and having a client that drives the challenge/sign/retry sequence are
two different capabilities; a wallet with the former but not the latter gets a bare 402 with
nowhere to go. hint points that caller at the ordinary guided flow instead โ abapays.com,
which needs no x402 at all.
A refused settlement is retried before the rail is abandoned
๐ต Why a refused x402 settlement gets a real retry instead of an immediate fallback. A
transferWithAuthorization simulation can revert (the facilitator answers unable to estimate gas / invalid_payload) with no transaction and nothing moved. Falling back to the contract
call in that case costs two more prompts (approve + payBill) for a bill the x402 rail can
often settle on a second attempt costing one โ so the retry happens automatically, at three
levels:
- Before the facilitator is called at all.
src/lib/x402Settle.ts decides the EIP-3009
revert conditions that are visible in the payload โ an expired validity window, a
clock-skewed validAfter, a wrong recipient, an amount that disagrees with what the server
is about to declare as required โ so a payload that cannot settle is answered with a fresh
challenge instead of an opaque revert. The signed value, not the recomputed price, is what