---
name: doma-mpp
description: How to consume the Doma MPP API — payment-gated endpoints using the Machine Payments Protocol (HTTP 402). Use this skill whenever the user wants to register or buy a domain via MPP, call the Doma /register or /buy API, make paid API requests with mppx, or work with HTTP 402 payment flows for Doma domain registration or purchase. Also trigger when code imports mppx, mppx/client, or the user mentions MPP, paid APIs, or payment-gated endpoints in the context of Doma domains.
metadata:
  version: "1.1.0"
---

# Consuming the Doma MPP API

The Doma MPP API is gated behind the Machine Payments Protocol (MPP). When you call the endpoint, the server returns HTTP 402 Payment Required with a payment challenge. The `mppx` client library handles this automatically — it pays via Tempo stablecoins and retries the request, so your code just calls `fetch()` and gets back the result.

## Setup

Install dependencies:

```bash
npm install mppx viem
```

Create an account from a private key:

```ts
import { privateKeyToAccount } from "viem/accounts";
import { Mppx, tempo } from "mppx/client";

const account = privateKeyToAccount("0x<PRIVATE_KEY>");

// This polyfills global fetch to auto-handle 402 payment challenges
Mppx.create({ methods: [tempo({ account })] });
```

If you prefer not to polyfill global fetch:

```ts
const mppx = Mppx.create({
  polyfill: false,
  methods: [tempo({ account })],
});

// Use mppx.fetch instead of global fetch
const response = await mppx.fetch(url);
```

## The /register endpoint

```
POST /register
Content-Type: application/json

{ "domain": "example.com", "buyerAddress": "0x...", "contact": { ... } }
```

| Parameter      | Location | Required | Description                                                                |
| -------------- | -------- | -------- | -------------------------------------------------------------------------- |
| `domain`       | body     | yes      | Full domain including TLD (e.g. `example.com`)                             |
| `buyerAddress` | body     | yes      | EVM address of the domain buyer (0x-prefixed, 40 hex chars)                |
| `contact`      | body     | yes      | Object with registrant contact info (see required fields below)            |

**Supported TLDs:** `com`, `xyz`, `ai`, `io`, `net`, `cash`, `live`, `fyi`

**Cost:** Dynamic — the server looks up the real USD price from the Interstellar.xyz registrar API. Payment is handled automatically via MPP/Tempo.

### Registrant contact format

The `contact` parameter is a JSON object with ICANN registrant contact fields.

**Required fields:** `firstName`, `lastName`, `email`, `phone`, `phoneCountryCode`, `street`, `city`, `state`, `postalCode`, `countryCode`

**Optional fields:** `organization`, `fax`, `faxCountryCode`

```ts
interface RegistrantContact {
  firstName: string;      // required
  lastName: string;       // required
  email: string;          // required
  phone: string;          // required
  phoneCountryCode: string; // required, e.g. "+1"
  street: string;         // required
  city: string;           // required
  state: string;          // required
  postalCode: string;     // required
  countryCode: string;    // required, ISO 3166-1 alpha-2, e.g. "US"
  organization: string;   // optional
  fax: string;            // optional
  faxCountryCode: string; // optional
}
```

### Example request

```ts
import { privateKeyToAccount } from "viem/accounts";
import { Mppx, tempo } from "mppx/client";

const account = privateKeyToAccount("0x<PRIVATE_KEY>");
Mppx.create({ methods: [tempo({ account })] });

const domain = "example.com";
const buyerAddress = account.address;

const contact = {
  firstName: "Jane",
  lastName: "Smith",
  organization: "Acme Inc",
  email: "jane@acme.com",
  phone: "4151234567",
  phoneCountryCode: "+1",
  fax: "4151234567",
  faxCountryCode: "+1",
  street: "123 Main St",
  city: "San Francisco",
  state: "CA",
  postalCode: "94103",
  countryCode: "US",
};

const response = await fetch("https://mpp-testnet.doma.xyz/register", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ domain, buyerAddress, contact }),
});
const data = await response.json();
console.log(data);
```

### Success response (200)

```json
{
  "success": true,
  "domain": "example.com",
  "network": "testnet",
  "txHash": "0xabc123...",
  "paymentContract": "0x9aC6761B5A1006E09C60a0BE10cd1C9d32911e96",
  "voucherAmount": "29990000000000000000",
  "order": {
    "domain": "example.com",
    "amount": "29.99",
    "buyerAddress": "0x...",
    "registrantContact": { ... },
    "voucher": { ... },
    "voucherSignature": "0x..."
  }
}
```

### Error responses

| Status  | Meaning                                                                          |
| ------- | -------------------------------------------------------------------------------- |
| **400** | Missing/invalid domain, buyerAddress, contact (or missing required contact fields), unsupported TLD, or invalid order metadata |
| **402** | Payment required (handled automatically by `mppx`)                               |
| **409** | Domain not available for registration                                            |
| **500** | On-chain registration transaction failed                                         |
| **503** | Operator wallet temporarily underfunded — retry later or try a less expensive domain |

## The /buy endpoint

Buy a domain already listed for sale on the Doma Seaport orderbook. The server picks the lowest active USDC-priced listing and fulfills it from the operator's wallet; the NFT lands at your `buyerAddress`.

```
POST /buy
Content-Type: application/json

{ "domain": "example.com", "buyerAddress": "0x..." }
```

| Parameter      | Location | Required | Description                                                                 |
| -------------- | -------- | -------- | --------------------------------------------------------------------------- |
| `domain`       | body     | yes      | Full domain to purchase (e.g. `example.com`). Must currently be listed.    |
| `buyerAddress` | body     | yes      | EVM address that receives the NFT (0x-prefixed, 40 hex chars)              |

**Listing selection:** server picks the lowest-priced active USDC/USDTEST listing. No way to specify a particular listing.

**Cost:** Dynamic — set by the chosen listing's price.

**Listing-price cap:** Listings above `MPP_MAX_LISTING_PRICE_USD` (server-side, default `$1,000`) return 422.

### Example request

```ts
import { privateKeyToAccount } from "viem/accounts";
import { Mppx, tempo } from "mppx/client";

const account = privateKeyToAccount("0x<PRIVATE_KEY>");
Mppx.create({ methods: [tempo({ account })] });

const response = await fetch("https://mpp-testnet.doma.xyz/buy", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ domain: "example.com", buyerAddress: account.address }),
});
const data = await response.json();
console.log(data);
```

### Success response (200)

```json
{
  "success": true,
  "domain": "example.com",
  "network": "testnet",
  "txHash": "0xabc123...",
  "buyerAddress": "0x...",
  "listingPrice": "5.00",
  "currency": "USDTEST",
  "orderId": "0x...",
  "tokenAddress": "0x424bDf2E8a6F52Bd2c1C81D9437b0DC0309DF90f",
  "tokenId": "25365190687432888579676975852141828319420787625078172166982785882149804979775"
}
```

### Error responses

| Status  | Meaning                                                                          |
| ------- | -------------------------------------------------------------------------------- |
| **400** | Missing/invalid `domain` or `buyerAddress`                                       |
| **402** | Payment required (handled automatically by `mppx`)                               |
| **404** | No active USDC-priced listing for this domain                                    |
| **422** | Listing price exceeds `MPP_MAX_LISTING_PRICE_USD` cap                            |
| **500** | Server error or on-chain Seaport revert (e.g., listing cancelled mid-flow)       |
| **503** | Operator wallet temporarily insufficient — try a less expensive listing or retry later |

### Payment-mode requirement

`/buy` requires push payment mode. The server advertises `supportedModes: ["push"]` so `mppx` 0.5.13+ auto-negotiates. Older mppx versions (0.4.x) won't work — upgrade to mppx 0.6.x or later.

## The /x402/buy-fractional endpoint

Buy a fixed USD amount of a domain's fractional ERC-20 token. This endpoint is gated by the **Coinbase x402 protocol** (HTTP 402), not MPP, and the payment leg runs on **Base** in USDC, separate from the Doma Chain fulfillment leg. `mppx` does not handle x402 challenges; use an x402-compliant client instead (for example `@x402/fetch` or `x402-axios`).

```
POST /x402/buy-fractional
Content-Type: application/json

{ "domain": "example.ai", "buyerAddress": "0x...", "usdSpend": "5.00" }
```

| Parameter      | Location | Required | Description                                                                 |
| -------------- | -------- | -------- | --------------------------------------------------------------------------- |
| `domain`       | body     | yes      | Full domain whose fractional token to buy (e.g. `example.ai`). Must already have a fractional token. |
| `buyerAddress` | body     | yes      | EVM address that receives the fractional tokens (0x-prefixed, 40 hex chars) |
| `usdSpend`     | body     | yes      | USD amount to spend, as a decimal string (e.g. `"5.00"`)                    |

**USD-spend model:** you specify dollars in (`usdSpend`), not tokens out. The server quotes the equivalent USD price back through the x402 payment requirements, you pay that amount in USDC on Base, and the server buys however many fractional tokens that amount fills at the time of execution. `tokensOut` in the response tells you what you actually received.

**Venue auto-detection:** the server resolves whether the domain's fractional token is still on its launchpad bonding curve or has graduated to a Uniswap pool, and routes the buy accordingly. You don't choose a venue; the response's `venue` field tells you which one was used.

**The buyer never touches Doma Chain.** Your wallet only needs USDC on Base to pay the x402 challenge. The operator wallet executes the on-chain buy on Doma Chain and delivers the fractional tokens to your `buyerAddress` there. You don't need a Doma Chain RPC, gas, or a Doma-chain-aware signer for this endpoint.

**Spend limit:** there is no fixed spend cap. A purchase is bounded only by the operator's USDC.e float on Doma Chain — a `usdSpend` larger than the operator can currently fund returns 503.

### Example request

```ts
import { wrapFetchWithPayment } from "@x402/fetch"; // or any x402-compliant client
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount("0x<PRIVATE_KEY>"); // Base wallet, funded with USDC
const fetchWithPayment = wrapFetchWithPayment(fetch, account);

const response = await fetchWithPayment("https://mpp.doma.xyz/x402/buy-fractional", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    domain: "example.ai",
    buyerAddress: "0x...", // can be a different address than the payer
    usdSpend: "5.00",
  }),
});
const data = await response.json();
console.log(data);
```

### How the probe-and-pay flow works

1. Client sends `POST /x402/buy-fractional` with `{ domain, buyerAddress, usdSpend }` and no payment.
2. The server resolves the fractional token for `domain`, runs guardrail checks (positive `usdSpend`, operator USDC.e balance), and returns **402 Payment Required** with x402 payment requirements: scheme `exact`, network Base (or Base Sepolia), amount equal to `usdSpend`.
3. If the body is malformed or a guardrail fails before payment, the server still answers with a 402 carrying a benign zero-amount quote so the request can proceed to the real check; the handler then authoritatively re-validates and returns the actual 4xx with no charge taken.
4. Your x402 client constructs and signs the USDC payment on Base, then retries the request with the payment attached.
5. The server verifies the payment with the x402 facilitator, executes the on-chain buy on Doma Chain (launchpad or Uniswap), delivers tokens to `buyerAddress`, and only then settles the payment. If the on-chain leg fails after payment verification but before a 200, the response is a 500 and the buyer is not charged (settle-after-success).
6. The server returns 200 with the purchase result.

### Success response (200)

```json
{
  "success": true,
  "domain": "example.ai",
  "txHash": "0xabc123...",
  "deliveryTxHash": "0xdef456...",
  "venue": "launchpad",
  "tokensOut": "1234.56",
  "tokenAddress": "0x...",
  "buyerAddress": "0x...",
  "network": "mainnet"
}
```

`deliveryTxHash` is only present for `launchpad` venue buys, where the launchpad sends tokens to the operator and the operator forwards them to `buyerAddress` in a second transaction. For `uniswap` venue buys, the swap's recipient is set to `buyerAddress` directly, so there is no separate delivery transaction.

### Error responses

These statuses are returned on the paid request after payment verification. The unpaid discovery probe always answers 402 (amount $0.00 when the request is malformed or the domain has no fractional token); the authoritative 4xx/5xx is returned only after payment (settle-after-success means an invalid request is never charged).

| Status  | Meaning                                                                          |
| ------- | -------------------------------------------------------------------------------- |
| **400** | Body is not `{ domain, buyerAddress, usdSpend }`, or `buyerAddress` is not a valid 0x address |
| **402** | Payment required (x402 challenge; handled automatically by an x402 client)       |
| **404** | No fractional token exists for this domain                                      |
| **422** | `usdSpend` is not a positive decimal, or the token's launch failed (`launchpad-failed`) and buying is disabled |
| **500** | Server error, on-chain buy or token-delivery transaction failed                 |
| **503** | Operator USDC.e balance is temporarily insufficient for this spend amount; retry later or spend less |

On any response status 400 or above, the buyer is never charged (settle-after-success).

## The /x402/buy endpoint

Buy a domain already listed for sale on the Doma Seaport orderbook, paid over the **Coinbase x402 protocol** (HTTP 402) instead of MPP. The payment leg runs on **Base** in USDC; fulfillment (the Seaport order) runs on **Doma Chain**. `mppx` does not handle x402 challenges; use an x402-compliant client instead (for example `@x402/fetch` or `x402-axios`).

```
POST /x402/buy
Content-Type: application/json

{ "domain": "example.ai", "buyerAddress": "0x..." }
```

| Parameter      | Location | Required | Description                                                                 |
| -------------- | -------- | -------- | --------------------------------------------------------------------------- |
| `domain`       | body     | yes      | Full domain to buy, including TLD (e.g. `example.ai`). Must currently be listed. |
| `buyerAddress` | body     | yes      | EVM address that receives the NFT (0x-prefixed, 40 hex chars)              |

**Listing selection:** server picks the lowest-priced active USDC/USDTEST listing. No way to specify a particular listing.

**Cost:** dynamic. The server quotes the chosen listing's live USD-equivalent price back through the x402 payment requirements; you pay that amount in USDC on Base.

**The buyer never touches Doma Chain.** Your wallet only needs USDC on Base to pay the x402 challenge. The operator wallet fulfills the Seaport order on Doma Chain and delivers the NFT to your `buyerAddress` there.

**Listing-price cap:** listings above `MPP_MAX_LISTING_PRICE_USD` (server-side, default `$1,000`) return 422.

### Example request

```ts
import { wrapFetchWithPayment } from "@x402/fetch"; // or any x402-compliant client
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount("0x<PRIVATE_KEY>"); // Base wallet, funded with USDC
const fetchWithPayment = wrapFetchWithPayment(fetch, account);

const response = await fetchWithPayment("https://mpp.doma.xyz/x402/buy", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    domain: "example.ai",
    buyerAddress: "0x...", // can be a different address than the payer
  }),
});
const data = await response.json();
console.log(data);
```

### How the probe-and-pay flow works

1. Client sends `POST /x402/buy` with `{ domain, buyerAddress }` and no payment.
2. The server looks up the lowest active listing for `domain`, runs guardrail checks (price cap, operator wallet float), and returns **402 Payment Required** with x402 payment requirements: scheme `exact`, network Base (or Base Sepolia), amount equal to the listing's live USD price.
3. If the body is malformed or a guardrail fails before payment, the server still answers with a 402 carrying a benign zero-amount quote so the request can proceed to the real check; the handler then authoritatively re-validates and returns the actual 4xx with no charge taken.
4. Your x402 client constructs and signs the USDC payment on Base, then retries the request with the payment attached.
5. The server verifies the payment with the x402 facilitator, fulfills the Seaport order on Doma Chain, delivers the NFT to `buyerAddress`, and only then settles the payment. If the on-chain leg fails after payment verification but before a 200 (for example the listing was cancelled or its price drifted, and Seaport reverts on the consideration mismatch), the response is a 500 and the buyer is not charged (settle-after-success).
6. The server returns 200 with the purchase result.

### Success response (200)

```json
{
  "success": true,
  "domain": "example.ai",
  "txHash": "0xabc123...",
  "network": "mainnet",
  "listingPrice": "5.00",
  "amountUsd": "5.00",
  "currency": "USDC",
  "orderId": "0x...",
  "tokenAddress": "0x...",
  "tokenId": "25365190687432888579676975852141828319420787625078172166982785882149804979775",
  "buyerAddress": "0x..."
}
```

`listingPrice` is the native-currency price actually paid on-chain (e.g. `"0.003"` for an ETH listing); `amountUsd` is the USD-equivalent quoted and paid over x402. They are equal for USDC listings.

### Error responses

These statuses are returned on the paid request after payment verification. The unpaid discovery probe always answers 402 (amount $0.00 when the request is malformed or no listing exists); the authoritative 4xx/5xx is returned only after payment (settle-after-success means an invalid request is never charged).

| Status  | Meaning                                                                          |
| ------- | -------------------------------------------------------------------------------- |
| **400** | Body is not `{ domain, buyerAddress }`, or `buyerAddress` is not a valid 0x address |
| **402** | Payment required (x402 challenge; handled automatically by an x402 client)       |
| **404** | No active USDC-priced listing for this domain                                   |
| **422** | Listing price exceeds the `MPP_MAX_LISTING_PRICE_USD` cap                       |
| **500** | Server error, listing cancelled or price drifted mid-flow (Seaport revert), or operator wallet issue |
| **503** | Operator wallet temporarily insufficient to fulfill this listing; retry later or try a less expensive listing |

On any response status 400 or above, the buyer is never charged (settle-after-success).

## The /x402/quote-fractional endpoint

A **free, read-only quote** for what `/x402/buy-fractional` would deliver for a given `usdSpend`. No payment, no x402 challenge, no on-chain writes. Agents should call this first to learn `expectedTokensOut` before deciding whether to buy.

```
POST /x402/quote-fractional
Content-Type: application/json

{ "domain": "example.ai", "usdSpend": "5.00" }
```

| Parameter      | Location | Required | Description                                                                 |
| -------------- | -------- | -------- | --------------------------------------------------------------------------- |
| `domain`       | body     | yes      | Full domain whose fractional token to quote (e.g. `example.ai`). Must already have a fractional token. |
| `usdSpend`     | body     | yes      | USD amount to quote, as a decimal string (e.g. `"5.00"`)                    |
| `buyerAddress` | body     | no       | EVM address (0x-prefixed, 40 hex chars). Only used as the routing recipient for a Uniswap quote and does not affect the quoted amount. Defaults to a placeholder if omitted. |

This endpoint runs the same discovery and quote math as `/x402/buy-fractional` (venue auto-detection, launchpad bonding-curve math or Uniswap routing quote), so `expectedTokensOut` reflects what a buy would deliver at that moment. It is not a guarantee: on-chain state (curve state, pool liquidity) can move between the quote and a later buy.

### Example request

```ts
const response = await fetch("https://mpp.doma.xyz/x402/quote-fractional", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ domain: "example.ai", usdSpend: "5.00" }),
});
const data = await response.json();
console.log(data);
```

### Success response (200)

```json
{
  "domain": "example.ai",
  "tokenAddress": "0x...",
  "venue": "launchpad",
  "expectedTokensOut": "1234.56",
  "priceUsd": "5.00",
  "network": "mainnet"
}
```

### Error responses

| Status  | Meaning                                                                          |
| ------- | -------------------------------------------------------------------------------- |
| **400** | Body is not `{ domain, usdSpend }`, or `buyerAddress` (if provided) is not a valid 0x address |
| **404** | No fractional token exists for this domain                                      |
| **422** | `usdSpend` is not a positive decimal, or the token's launch failed (`launchpad-failed`) and buying is disabled |
| **500** | Server error while computing the quote                                          |

## How the payment flow works under the hood

You don't need to manage this yourself — `mppx` does it automatically — but for understanding:

1. Client sends `POST https://mpp-testnet.doma.xyz/register` with JSON body `{ domain, buyerAddress, contact }`
2. Server checks domain availability via the Interstellar.xyz Partner API and creates a payment order (voucher)
3. Server returns **402 Payment Required** with a `WWW-Authenticate` header containing a payment challenge. The challenge includes HMAC-signed metadata (domain, amount, voucher) so the order survives the retry.
4. `mppx` extracts the challenge, signs a payment credential using the Tempo account
5. `mppx` retries the request with an `Authorization` header containing the credential
6. Server reconstructs the order from the HMAC-verified challenge metadata, executes the on-chain payment contract (`pay()` function), waits for the transaction receipt, and returns the result

## Reading the payment receipt

After a successful request, you can inspect the payment receipt:

```ts
import { Receipt } from "mppx";

const response = await fetch("https://mpp-testnet.doma.xyz/register", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ domain: "example.com", buyerAddress: "0x...", contact: { /* ... */ } }),
});
const receipt = Receipt.fromResponse(response);

console.log(receipt.status); // "success"
console.log(receipt.reference); // transaction hash
console.log(receipt.timestamp); // payment timestamp
```

## Endpoints

| Environment | Base URL                       |
| ----------- | ------------------------------ |
| Testnet     | `https://mpp-testnet.doma.xyz` |
| Mainnet     | `https://mpp.doma.xyz`         |

## CLI usage

You can also test from the command line:

```bash
npx mppx account create    # Create a Tempo account (auto-funded on testnet)
npx mppx -X POST -H "Content-Type: application/json" -d '{"domain":"example.com","buyerAddress":"0x...","contact":{...}}' "https://mpp-testnet.doma.xyz/register"
```

### Mainnet CLI usage

The `mppx` CLI defaults to the Tempo **testnet** chain when no RPC URL is provided. For mainnet requests (against `mpp.doma.xyz`), you **must** specify the mainnet RPC — otherwise the CLI will connect to testnet and fail because the mainnet USDC token doesn't exist on testnet.

Use the `-r` flag to specify the mainnet RPC:

```bash
npx mppx --account main -r https://rpc.tempo.xyz -X POST -H "Content-Type: application/json" -d '{"domain":"example.com","buyerAddress":"0x...","contact":{...}}' "https://mpp.doma.xyz/register"
```

| Network | RPC URL                          |
| ------- | -------------------------------- |
| Mainnet | `https://rpc.tempo.xyz`          |
| Testnet | `https://rpc.moderato.tempo.xyz` |

## After Registration: Managing Your Domain

After registering a domain, use the `doma` CLI to manage DNS records and nameservers. For full CLI documentation including token trading, subdomain management, bridging, and more, install the Doma skill:

```bash
npx skills add d3-inc/doma-skill
```

### Install Doma CLI

```bash
npm install -g @doma-protocol/cli
```

### Configure

```bash
doma config set privateKey "0x..."
```

The private key should be for the wallet where the domain was tokenized on the Doma chain. This defaults to the `buyerAddress` wallet used for MPP registration. On macOS, the private key is stored in Keychain.

### Manage DNS Records

Once using Doma nameservers, set DNS records on-chain:

```bash
doma dns set example.com @ A 76.76.21.21 -y          # Apex A record
doma dns set example.com www CNAME cname.vercel-dns.com -y  # Subdomain CNAME
doma dns list example.com                              # View all records
```

DNS and nameserver write operations on the Doma chain use sponsored gas (gasless) via ERC-4337 — no ETH balance is needed on Doma for these operations.

### Set Nameservers

Point your domain to custom nameservers:

```bash
doma nameservers set example.com ns1.myprovider.com ns2.myprovider.com
```
