Skip to main content
This page is a technical reference for @monad-crypto/mpp. For a developer-oriented guide with examples, visit the overview.

Server

Example

server.ts
import { monad } from "@monad-crypto/mpp/server";
import { Mppx } from "mppx";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount(process.env.SERVER_PRIVATE_KEY as `0x${string}`);

const mppx = Mppx.create({
  methods: [
    monad({
      account,
      recipient: account.address,
      // ... parameters below
    }),
  ],
});

Parameters

The monad server payment method accepts the following parameters.
ParameterTypeDefaultDescription
amountstringDefault payment amount, human-readable (e.g. "1.50")
currencystringUSDCERC-20 token contract address
decimalsnumber6Token decimals
descriptionstringHuman-readable description
externalIdstringExternal identifier to echo back in receipt
recipientstringRecipient address for payments
testnetbooleanfalseTestnet mode
waitForConfirmationbooleantrueWhether to wait for the charge transaction to confirm on-chain
getClient(params: { chainId?: number }) => ClientFunction that returns a viem Client for the given chain ID
accountAccount | AddressServer account used to broadcast receiveWithAuthorization transactions. Required when accepting authorization payloads. The server pays gas from this account.
storeStoreStore for transaction hash replay protection. Use a shared store in multi-instance deployments so consumed hashes are visible across all server instances.

Client

Example

client.ts
import { monad } from "@monad-crypto/mpp/client";
import { Mppx } from "mppx/client";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount(process.env.CLIENT_PRIVATE_KEY as `0x${string}`);

const mppx = Mppx.create({
  methods: [monad({ 
    account,
    // ... parameters below
  })],
});

// Make a paid request
const response = await fetch("http://localhost:3000/premium");
const data = await response.json();
console.log(data);

Parameters

The monad client payment method accepts the following parameters.
ParameterTypeDefaultDescription
accountAccount | AddressWallet account. If omitted, resolved from the viem Client.
mode"push" | "pull"AutoPayment mode. Defaults to "push" for JSON-RPC accounts, "pull" for local accounts.
getClient(params: { chainId?: number }) => ClientCustom viem Client resolver. Uses built-in RPC URLs if not provided.