> For the complete documentation index, see [llms.txt](https://gitbook.keytrust.one/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.keytrust.one/off-ramp/integrations/web/node.js-sdk.md).

# Node.js SDK

For Node-based backends and actions that require your secret key

A node package for MoonPay server-side functions. See the package [here](https://www.npmjs.com/package/@moonpay/moonpay-node?activeTab=code).

First, import the `MoonPay` class.

```
import { MoonPay } from '@moonpay/moonpay-node`;
```

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

> ### 🚧NEVER use your secret key in client side code
>
> Load your secret key from an environment variable instead.

```
const moonPay = new MoonPay('sk_test_...');
```

Use the `moonPay` instance to access our functions.

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

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

```
const signature = moonPay.url.generateSignature(
  'https://buy.moonpay.com/?apiKey=pk_test_123&walletAddress=...',
);
```

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

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

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

```
const isSignatureValid = moonPay.url.isSignatureValid(
  '[...]/?apiKey=pk_test_123&signature=someSignature',
);
```

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

```
const params = {
  apiKey: 'pk_test_123',
  baseCurrencyCode: 'GBP',
};

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

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

```
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!'),
);
```

Then, make a `GET` request to your endpoint from the client with a `url` query param to get the signature.

Updated 3 months ago

***

* [Table of Contents](broken://pages/wh94uQaYummoWVYfmx2p)
* * [@moonpay/moonpay-node](broken://pages/wh94uQaYummoWVYfmx2p)
    * [Setup](broken://pages/wh94uQaYummoWVYfmx2p)
    * [Usage](broken://pages/wh94uQaYummoWVYfmx2p)
    * [Example](broken://pages/wh94uQaYummoWVYfmx2p)
