@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:- npm
- pnpm
- yarn
- bun
Server
The server defines what payment is required and verifies credentials submitted by clients. Importmonad from the server entrypoint and pass it to Mppx.create.
server.ts
Gate an endpoint
Usemppx.charge() as middleware to require payment before serving a response.
server.ts
/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 ID143). To use testnet, set testnet: true.
Client
The client handles wallet interactions and credential creation. Importmonad 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
| Push | Pull | |
|---|---|---|
| Who pays gas | Client | Server |
| Transaction | Client broadcasts ERC-20 transfer | Server calls transferWithAuthorization |
| Credential | Transaction hash | Signed ERC-3009 authorization |
| Default for | JSON-RPC accounts (browser wallets) | Local accounts (private keys) |
| Trade-off | Client needs gas tokens | Server needs gas tokens |
Overriding the mode
Use themode option to set the payment mode explicitly, regardless of account type.
Monkey patch
The clientMppx.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

