PerformanceBlog
Tempo MCP serverGive agents search and read tools for Tempo docs
Skip to content
LogoLogo

Accept one-time payments

Build a payment-gated API that charges $0.01 per request using mppx. The server returns a random photo from Picsum behind a paywall.

One-time payment server setup

Install one-time payment dependencies

Set up an Mppx charge instance

Set up an Mppx instance with the tempo method.

  • recipient is the address where you receive payments.
  • currency is the token address for payments (in this case, pathUSD).
import { Mppx, tempo } from 'mppx/server'
 
const mppx = Mppx.create({
  methods: [tempo({
    currency: '0x20c0000000000000000000000000000000000000',
    recipient: '0xa726a1CD723409074DF9108A2187cfA19899aCF8',
  })],
})

Add a one-time payment route

Add payment verification using mppx.charge as route middleware. The handler only runs after payment is verified.

import { Mppx, tempo } from 'mppx/nextjs'
 
const mppx = Mppx.create({
  methods: [tempo({
    currency: '0x20c0000000000000000000000000000000000000',
    recipient: '0xa726a1CD723409074DF9108A2187cfA19899aCF8',
  })],
})
 
export const GET =
  mppx.charge({ amount: '0.01', description: 'Random stock photo' })
  (async () => {
    const res = await fetch('https://picsum.photos/1024/1024')
    return Response.json({ url: res.url })
  })

Test the one-time payment endpoint

# Create account funded with testnet tokens
$ npx mppx account create
 
# Make a paid request
$ npx mppx http://localhost:3000/api/photo

Next steps for one-time payments