SDK Installation
The monterrey.app SDK provides a type-safe way to integrate crypto payments into your application. Available for JavaScript/TypeScript.
Installation
# npm
npm install @monterrey/sdk
# yarn
yarn add @monterrey/sdk
# pnpm
pnpm add @monterrey/sdkRequirements
- Node.js 18 or later
- TypeScript 5.0+ (optional, but recommended)
Basic Setup
import { MonterreyClient } from "@monterrey/sdk";
// Initialize the client
const monterrey = new MonterreyClient({
apiKey: process.env.MONTERREY_API_KEY!,
});
// Now you can use the client
const payment = await monterrey.payments.create({
merchantRef: "order_123",
amount: "1000000",
currency: "USDC",
chain: "polygon",
});Configuration Options
const monterrey = new MonterreyClient({
// Required: Your API key
apiKey: "mk_live_...",
// Optional: API base URL (for self-hosted instances)
baseUrl: "https://api.monterrey.app",
// Optional: Request timeout in milliseconds
timeout: 30000,
// Optional: Custom fetch implementation
fetch: customFetch,
// Optional: Retry configuration
retry: {
maxRetries: 3,
retryDelay: 1000,
},
});Environment Variables
We recommend storing your API key in environment variables:
# .env
MONTERREY_API_KEY=mk_live_your_api_key_here
MONTERREY_WEBHOOK_SECRET=whsec_your_secret_here// Load from environment
const monterrey = new MonterreyClient({
apiKey: process.env.MONTERREY_API_KEY!,
});TypeScript Support
The SDK is written in TypeScript and includes full type definitions. All methods are strongly typed:
import {
MonterreyClient,
Payment,
PaymentStatus,
CreatePaymentParams,
} from "@monterrey/sdk";
// Types are inferred automatically
const payment: Payment = await monterrey.payments.create({
merchantRef: "order_123",
amount: "1000000",
currency: "USDC",
chain: "polygon",
});
// TypeScript will catch errors
payment.status; // PaymentStatus
payment.address; // string
payment.invalidField; // Error: Property does not existFramework-Specific Setup
Next.js
// lib/monterrey.ts
import { MonterreyClient } from "@monterrey/sdk";
export const monterrey = new MonterreyClient({
apiKey: process.env.MONTERREY_API_KEY!,
});
// app/api/payments/route.ts
import { monterrey } from "@/lib/monterrey";
import { NextResponse } from "next/server";
export async function POST(request: Request) {
const body = await request.json();
const payment = await monterrey.payments.create({
merchantRef: body.orderId,
amount: body.amount,
currency: "USDC",
chain: "polygon",
});
return NextResponse.json(payment);
}Express
// server.ts
import express from "express";
import { MonterreyClient } from "@monterrey/sdk";
const app = express();
const monterrey = new MonterreyClient({
apiKey: process.env.MONTERREY_API_KEY!,
});
app.post("/api/payments", async (req, res) => {
const payment = await monterrey.payments.create({
merchantRef: req.body.orderId,
amount: req.body.amount,
currency: "USDC",
chain: "polygon",
});
res.json(payment);
});Next Steps
- Quick Start Guide - Create your first payment
- React Components - Pre-built UI components
- API Reference - Full API documentation