> For the complete documentation index, see [llms.txt](https://docs.abapays.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.abapays.com/protocols/x402.md).

# x402

> Zero setup

An independent agent — say, an FX agent holding a Celo wallet — never needs to know AbaPay exists in advance. The whole exchange happens over plain HTTP, challenge and response.

## The flow

1. Holds or uses a Celo wallet.
2. Calls AbaPay's quote / pay\_bill endpoint directly.
3. Gets `402 Payment Required` back, with the exact price and asset.
4. Signs an EIP-3009 `transferWithAuthorization` with that same wallet — nothing else.
5. Retries the request with the signed authorization attached.
6. AbaPay settles on Celo via Celo's own x402 facilitator and vends the bill.

> **Never required for this path:** abapays.com account, Agent Hub, API key, PIN, wallet-signature link.

## Request & response

`POST /api/pay/x402` — no `X-PAYMENT` header yet:

```json
{
  "serviceID": "mtn", "serviceCategory": "AIRTIME",
  "network": "MTN", "billersCode": "08012345678",
  "nairaAmount": 1000, "token": "USDT",
  "blockchain": "CELO", "wallet_address": "0xYourAgentWallet..."
}
```

← `402 Payment Required` (real field names):

```json
{
  "x402Version": 1,
  "error": "Payment required",
  "accepts": [{
    "scheme": "exact",
    "network": "eip155:42220",
    "asset": "0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e",
    "payTo": "0x5df8aE2B963165b735B18Ca86B1ea448d2AA032C",
    "maxTimeoutSeconds": 86400,
    "extra": { "name": "Tether USD", "version": "1", "primaryType": "TransferWithAuthorization" }
  }]
}
```

`POST /api/pay/x402` with `X-PAYMENT: <base64 signed authorization>` → `200 OK`:

```json
{
  "success": true, "status": "SUCCESS",
  "tx_hash": "0x91a3...4f2c", "request_id": "req_...",
  "purchased_code": null, "units": null
}
```

Both USDC and USD₮ settle via Celo's own x402 facilitator — each implements EIP-3009. Full field reference: [openapi.json](https://abapays.com/openapi.json).

## Don't hand-roll the signing

`abapay-sdk`'s `payBillViaX402()` does exactly the three requests and one signature above — pass it a viem account and the bill details, get back the settlement result. See [the SDK chapter](/build/sdk.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.abapays.com/protocols/x402.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
