---
title: REST API Examples
slug: rest-api-examples
docTags: 
createdAt: 2024-05-16T18:32:16.479Z
---

## Prerequisites:

- **Admin Macaroon** - The admin macaroon is an authentication token that allows you to interact with your LND node's gRPC API with administrative permissions. You can also grab a "Read Only" macaroon that wont have permissions to spend. You can find your Macaroons in your Voltage Dashboard by visiting **Manage Access** -> **Macaroon Bakery**

## Interacting With Your Node's LND REST API

::embed[]{url="https://youtu.be/srIUzxa6Iq8"}

Here are some code snippets demonstrating how to interact with some of the most common and popular LND API methods:


**GetInfo** - [https://lightning.engineering/api-docs/api/lnd/lightning/get-info](https://lightning.engineering/api-docs/api/lnd/lightning/get-info)

:::CodeblockTabs
```javascript
const REST_HOST = 'node-name.m.voltageapp.io:8080';
const MACAROON = 'your-macaroon-in-hex-format'; // Replace this with your actual macaroon in hex format

const getInfo = async () => {
  try {
    const response = await fetch(`https://${REST_HOST}/v1/getinfo`, {
      method: 'GET',
      headers: {
        'Grpc-Metadata-macaroon': MACAROON,
      },
    });
    const data = await response.json();
    console.log("getInfo", data)
  } catch (error) {
    console.error('Error:', error);
  }
};
```

```none
```
:::

**AddInvoice** - [https://lightning.engineering/api-docs/api/lnd/lightning/add-invoice](https://lightning.engineering/api-docs/api/lnd/lightning/add-invoice)

```javascript
const REST_HOST = 'node-name.m.voltageapp.io:8080';
const MACAROON = 'your-macaroon-in-hex-format'; // Replace this with your actual macaroon in hex format

const createInvoice = async () => {
  try {
    const response = await fetch(`https://${REST_HOST}/v1/invoices`, {
      method: 'POST',
      headers: {
        'Grpc-Metadata-macaroon': MACAROON,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        value: 1000, // Invoice amount in satoshis
        memo: 'Test invoice', // Optional memo for the invoice
      }),
    });
    const data = await response.json();
    setInvoice(data);
  } catch (error) {
    console.error('Error:', error);
  }
};
```

SendPaymentSync - [https://lightning.engineering/api-docs/api/lnd/lightning/send-payment-sync](https://lightning.engineering/api-docs/api/lnd/lightning/send-payment-sync)

```javascript
const REST_HOST = 'node-name.m.voltageapp.io:8080';
const MACAROON = 'your-macaroon-in-hex-format'; // Replace this with your actual macaroon in hex format

const payInvoice = async () => {
  try {
    const response = await fetch(`https://${REST_HOST}/v1/channels/transactions`, {
      method: 'POST',
      headers: {
        'Grpc-Metadata-macaroon': MACAROON,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        payment_request: 'lnbc...', // Paste the invoice's payment request here
        amt: 1000, // Amount to pay in satoshis
      }),
    });
    const data = await response.json();
    console.log("payInvoice", data)
  } catch (error) {
    console.error('Error:', error);
  }
};
```



- `POST /v1/channels/transactions`

  `: Pays an invoice by providing the payment request and the amount to pay.`
- `POST /v1/invoices`

  `: Creates a new invoice with a specified amount and optional memo.`
- `GET /v1/getinfo`

  `: Retrieves general information about your node.`

Make sure to replace the placeholders in the script with your actual macaroon file path, node URL, and the desired invoice details.
