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

# Node.js SDK

> Set up the moonpay-node SDK with your secret key to sign widget URLs and call MoonPay APIs from your server.

## Install

```bash theme={null}
npm install @moonpay/moonpay-node
```

View the package on [npm](https://www.npmjs.com/package/@moonpay/moonpay-node?activeTab=code).

## Setup

First, import the `MoonPay` class.

```typescript theme={null}
import { MoonPay } from '@moonpay/moonpay-node`;
```

Set up the `MoonPay` class with your secret key.

<Warning>
  NEVER use your secret key in client side code. Load your secret key from an environment variable instead.
</Warning>

```typescript theme={null}
const moonPay = new MoonPay("sk_test_...");
```

## Usage

Use the `moonPay` instance to access our functions.

### URL utilities

MoonPay URL utilities are namespaced under the `.url` property.

#### Signing your URL

If you include the `walletAddress` or `walletAddresses` query param, you'll need to sign the URL.

```typescript theme={null}
const signature = moonPay.url.generateSignature(
  "https://buy.moonpay.com/?apiKey=pk_test_123&walletAddress=...",
);
```

Or, return the signed URL, using the `returnFullURL` option.

```typescript theme={null}
const signedURL = moonPay.url.generateSignature(
  "https://buy.moonpay.com/?apiKey=pk_test_123&walletAddress=...",
  { returnFullURL: true },
);
```

#### Verifying a signature

Or, you can verify that a URL is correctly signed.

```typescript theme={null}
const isSignatureValid = moonPay.url.isSignatureValid(
  "[...]/?apiKey=pk_test_123&signature=someSignature",
);
```

#### Generating a signed URL

You can also have us generate the full, signed URL, based on some input parameters.

```typescript theme={null}
const params = {
  apiKey: "pk_test_123",
  baseCurrencyCode: "GBP",
};

const url = moonPay.url.generate({ flow: "buy", params });
```

## Example

Here's an example of an Express endpoint that signs a URL query param.

```typescript theme={null}
import express from "express";
import { MoonPay } from "@moonpay/moonpay-node";

const moonPay = new MoonPay("sk*test*...");
const app = express();

app.get("/moonpay_signature", (req, res) => {
  const { url } = req.query;
  const signature = moonPay.url.generateSignature(url);
  res.send({ signature });
});

app.listen(3000, () => console.log("Listening on port 3000!"));
```
