Ask402

How do I accept MPP payments on my API?

Short answer

Add MPP middleware to your server, tell it which payment methods you take and who receives the money, and wrap each paid route with a charge. The reference library, mppx, has middleware for Next.js, Hono, Elysia and Express. Start on the test network, validate with the command-line tool, then switch to live. Stripe users can accept MPP through Stripe.

What you need

  • A recipient: the address or account that receives payments.
  • A secret key for your server.
  • Middleware for your framework.
  • At least one payment method you want to accept.

A minimal server

This follows the official quickstart. It uses Hono and the Tempo payment method on the test network, and charges 0.10 in the network's default stablecoin for GET /resource.

import { Hono } from 'hono'
import { Mppx, tempo } from 'mppx/hono'

const app = new Hono()

const mppx = Mppx.create({
  methods: [tempo.charge({
    recipient: '0xYourAddress',
    testnet: true,
  })],
  secretKey: process.env.MPP_SECRET_KEY!,
})

app.get(
  '/resource',
  mppx.charge({ amount: '0.1' }),
  (c) => c.json({ data: '...' }),
)

Generate the secret with openssl rand -hex 32. Keep it on the server and out of your logs.

Unpaid requests to /resource now get a 402 with a challenge. Paid requests reach your handler.

Frameworks

ModeWorks with
MiddlewareNext.js, Hono, Elysia, Express
ManualAnything built on the Fetch API, including Cloudflare Workers, Deno and Bun
Node.js listenersWrap your handler with Mppx.toNodeListener

Test it

The mppx command-line tool checks your work without real money.

npx mppx validate https://your-server.example
curl -i https://your-server.example/resource
npx mppx account create --network testnet
npx mppx account fund --network testnet
npx mppx https://your-server.example/resource --network testnet

The first command validates your implementation. The second shows the raw 402. The last three make a paid request with test tokens.

You can also paste your endpoint into the 402 checker to see the challenge decoded the way a client reads it.

Going live

  1. Remove testnet: true.
  2. Add a shared store. The quickstart warns that in production, and on platforms that run several copies of your server, the Tempo charge method needs a shared store such as Postgres. Without one it refuses to start.
  3. Use your real recipient address and check you control it.
  4. Mark paid routes as not cacheable. The protocol requires Cache-Control: no-store on 402 replies.

Choosing payment methods

Each method reaches different buyers.

  • Tempo reaches agents holding stablecoins on Tempo.
  • Card and Stripe reach buyers without crypto.
  • Lightning reaches buyers holding bitcoin.

You can list several, and the client picks one. The full list, with which are in production, is in MPP payment methods.

Accepting MPP through Stripe

If you already use Stripe, its announcement says you can accept MPP payments "in a few lines of code" through the PaymentIntents API, taking stablecoins as well as cards and buy now, pay later methods.

Offering x402 as well

You do not have to choose. A server can put x402's header and MPP's header in the same 402 reply, and each kind of client reads its own. MPP's documentation has a guide to serving both, and its evm method is described as compatible with x402's exact payments.

Doing both costs little and widens who can pay you. See how to accept x402 payments and x402 vs MPP.

Pricing

MPP has more ways to charge than a flat fee: session for streams of small payments and subscription for recurring access. See how an MPP payment works. General advice on setting a price is in how to price an x402 API, most of which applies to either protocol.

Sources

Facts checked against these sources on . Protocols change, so the official specification wins if it disagrees with this page. Read this page as Markdown.

Who writes this. Ask402 is published by Havok Holdings LLC, which also runs Agent402, one of the x402 services covered here. Agent402 is labelled wherever it appears. Everything else is described from each project’s own documentation, and nobody pays to be listed.