Skip to main content
The @monad-crypto/mpp package implements Monad payments for the Machine Payments Protocol (MPP). It enables one-time payment processing through ERC-20 token transfers on Monad. This guide covers the Monad-specific @monad-crypto/mpp package. For general MPP concepts, see the MPPX documentation.

Installation

Install the package and its peer dependencies:

Server

The server defines what payment is required and verifies credentials submitted by clients. Import monad from the server entrypoint and pass it to Mppx.create.
server.ts

Gate an endpoint

Use mppx.charge() as middleware to require payment before serving a response.
server.ts
When a client requests /premium without a valid payment credential, the server responds with a 402 Payment Required status and a challenge describing the payment requirements. The client then submits a credential (transaction hash or signed authorization) to complete the payment.

Testnet

By default, the package connects to Monad mainnet (chain ID 143). To use testnet, set testnet: true.

Client

The client handles wallet interactions and credential creation. Import monad from the client entrypoint. With a local private key, the client defaults to pull mode — it signs an ERC-3009 authorization without broadcasting a transaction.
client.ts

Push vs pull mode

Overriding the mode

Use the mode option to set the payment mode explicitly, regardless of account type.

Monkey patch

The client Mppx.create() function monkey patches the Web fetch API to use the configured payment method whenever it receives a 402 Payment Required HTTP response. You can also use mppx.fetch directly.
client.ts