> ## Documentation Index
> Fetch the complete documentation index at: https://docs.moflay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Use the Moflay Node.js SDK

> Install the Node.js SDK, authenticate with an API key, create M-Pesa Express payments, and read Moflay records.

Use `@moflay/sdk` when you want the fastest path to a working Moflay integration in Node.js or TypeScript.

## Prerequisites

* A [Moflay account](/setup-moflay)
* A valid [API key](/setup-api-key)

## Install the SDK

<CodeGroup>
  ```bash npm theme={null}
  npm install @moflay/sdk
  ```

  ```bash pnpm theme={null}
  pnpm add @moflay/sdk
  ```

  ```bash bun theme={null}
  bun add @moflay/sdk
  ```
</CodeGroup>

## Authenticate the client

```typescript theme={null}
import { Moflay } from "@moflay/sdk";

const moflay = new Moflay({
  token: process.env.MOFLAY_API_KEY!,
});
```

## Send an express payment

```typescript theme={null}
const payment = await moflay.express.pay({
  phoneNumber: "254712345678",
  amount: 1000,
  description: "Order 1001",
  accountReference: "ORDER1001",
});

console.log(payment.paymentId, payment.status);
```

## Add customer details

```typescript theme={null}
const payment = await moflay.express.pay({
  phoneNumber: "254712345678",
  customerName: "Jane Doe",
  amount: 250000,
  description: "Plan",
  accountReference: "SUB202604",
  metadata: {
    orderId: "SUB-2026-04",
  },
});
```

## Read customers and transactions

```typescript theme={null}
const transactions = await moflay.transactions.list({ limit: 10 });

for await (const page of transactions) {
  console.log(page.data);
}
```

```typescript theme={null}
const customers = await moflay.customers.list({ limit: 10 });

for await (const page of customers) {
  console.log(page.data);
}
```

## Amounts

Send payment amounts as integer minor currency units. For example, `amount: 1000` means `KES 10.00`.

## SDK vs raw HTTP

| Use the SDK when                            | Use raw HTTP when                           |
| ------------------------------------------- | ------------------------------------------- |
| Your backend uses Node.js or TypeScript     | Your backend uses another language          |
| You want typed request and response helpers | You want direct control over HTTP behavior  |
| You prefer SDK pagination helpers           | You already have an HTTP client abstraction |

## Related pages

* [Make your first payment](/first-payment)
* [Make your first payment with HTTP](/first-payment-http)
* [Express payment examples](/sdk-examples/express-payment)
* [Payment statuses & outcomes](/payments/transaction-statuses)
