1. Create an account
Go to monkepay.xyz and sign up. You can use email, Google, or a web3 wallet (MetaMask, Coinbase Wallet).
2. Get your API keys
In the dashboard, go to API Keys → Create Key.
You’ll see your key ID and secret once — copy both now and store them somewhere safe. The secret cannot be retrieved again.
MONKEPAY_API_KEY_ID=mk_live_...
MONKEPAY_API_KEY_SECRET=...
Add these to your .env file. Never commit them.
3. Install the SDK
npm install @monkepay/sdk
4. Gate an endpoint
Pick your framework:
Hono
Express
Fastify
Next.js
import { Hono } from 'hono'
import { MonkePayHono } from '@monkepay/sdk'
const app = new Hono()
const monkePay = MonkePayHono({
apiKeyId: process.env.MONKEPAY_API_KEY_ID!,
apiKeySecret: process.env.MONKEPAY_API_KEY_SECRET!,
price: '0.001', // $0.001 USDC per request
})
app.use('/api/*', monkePay())
app.get('/api/data', (c) => c.json({ result: 'paid content' }))
import express from 'express'
import { MonkePayExpress } from '@monkepay/sdk'
const app = express()
const monkePay = MonkePayExpress({
apiKeyId: process.env.MONKEPAY_API_KEY_ID!,
apiKeySecret: process.env.MONKEPAY_API_KEY_SECRET!,
price: '0.001',
})
app.get('/api/data', monkePay(), (req, res) => {
res.json({ result: 'paid content' })
})
import Fastify from 'fastify'
import { MonkePayFastify } from '@monkepay/sdk'
const app = Fastify()
const monkePay = MonkePayFastify({
apiKeyId: process.env.MONKEPAY_API_KEY_ID!,
apiKeySecret: process.env.MONKEPAY_API_KEY_SECRET!,
price: '0.001',
})
app.register(monkePay({
setup: (scope) => {
scope.get('/api/data', async () => ({ result: 'paid content' }))
},
}))
app.listen({ port: 3000 })
// app/api/data/route.ts
import { MonkePayNext } from '@monkepay/sdk/next'
import { NextResponse } from 'next/server'
const monkePay = MonkePayNext({
apiKeyId: process.env.MONKEPAY_API_KEY_ID!,
apiKeySecret: process.env.MONKEPAY_API_KEY_SECRET!,
price: '0.001',
})
export const GET = monkePay(async () => {
return NextResponse.json({ result: 'paid content' })
})
5. Set your payout address
In the dashboard, go to Settings → Payout Address. Enter your EVM wallet address and select your network.
This is where your USDC will be sent when you request a payout. It’s separate from your MonkePay wallet — your MonkePay wallet is managed by MonkePay and receives payments from agents. Your payout address is your personal wallet where you withdraw to.
If you signed up with MetaMask or Coinbase Wallet, your payout address is auto-filled from your connected wallet.
6. Test it
The easiest way to test is with x402-fetch. Install it and run a quick test:
import { wrapFetchWithPayment } from 'x402-fetch'
import { createSigner } from 'x402/types'
// Load a test wallet with USDC on Base Sepolia
// Get testnet USDC from https://faucet.circle.com
const walletClient = await createSigner('base-sepolia', process.env.AGENT_PRIVATE_KEY as `0x${string}`)
const fetch402 = wrapFetchWithPayment(fetch, walletClient)
const response = await fetch402('http://localhost:3000/api/data')
const data = await response.json()
console.log(data) // { result: 'paid content' }
If the request succeeds, you’ll see the payment appear in your dashboard under Transactions.
Next steps