---
title: Creating a Node Walkthrough
slug: creating-a-node-walkthrough
docTags: 
createdAt: 2024-05-04T13:02:31.695Z
---

This document will walk you through everything you need to know to create a node on Voltage via the API. First we'll describe the process then show a complete code example.

# Process

Here's the general process of creating a node via our API:

1. Call the [/node/create](https://docs.voltage.cloud/voltage-api#J5HeW) endpoint to create a node with your settings
2. Call the [/node](https://docs.voltage.cloud/voltage-api#1GhGq) endpoint every 5 or 10 seconds to check on the status of the node. It's first status is provisioning.
3. After it's provisioned it will switch to status waiting\_init. This means the node is waiting to be initialized. Now you should call [/v1/genseed](https://api.lightning.community/#v1-genseed) *on the node* to generate a seed for yourself.
4. Once you have a seed, you can initialize the wallet. Call the [/v1/initwallet](https://api.lightning.community/#v1-initwallet) endpoint *on the node*. Pass in it the seed created in step #3 and a password. YOU MUST ALSO SET stateless\_init: true! If you don't then you won't be able to access the node. This will return a macaroon in the API response.
5. After your node is initialized, you can encrypt the seed and macaroon to your password used for the node.
6. Use the [/node/upload\_seed ](https://docs.voltage.cloud/voltage-api#ch54M)and [/node/macaroon](https://docs.voltage.cloud/voltage-api#5uMDG) endpoints to backup your encrypted seed and macaroon. (Give the macaroon a name of admin)
7. That's it! Your node's status should now be running and you can use your macaroon to connect. We use TLS Certificates that are signed by a trusted Certificate Authority so it's not required to supply it when connecting. However, there are some applications that require it nonetheless. If you encounter one, you can get your node's certificate with the [/node/cert](https://docs.voltage.cloud/voltage-api#eNPIz) endpoint.

# Example

Here is an example script written in Node.js. This script would create a node, initialize it, and upload the encrypted backups.



```javascript
const axios = require('axios')
const crypto = require('crypto-js')

// Define your variables
let apiKey = "YOUR_API_KEY_HERE"
let nodeName = "voltage-example"
let nodePassword = "YOUR_SECURE_PASSWORD"
let orgId = "YOUR_ORG_ID"

async function main() {
    console.log("Creating your node...")

    voltageHeaders = {
        'X-VOLTAGE-AUTH': apiKey,
    }

    // Create the Node
    creationBody = {
        network: "testnet",
        purchased_type: "ondemand",
        type: "standard",
        name: nodeName,
        settings: {
            alias: nodeName,
            autocompaction: false,
            autopilot: false,
            color: "#EF820D",
            grpc: true,
            keysend: true,
            rest: true,
            whitelist: [
              "1.2.3.4"
            ],
            wumbo: true
        }
    }
    response = await makeRequest('POST', 'https://api.voltage.cloud/organizations/' + orgId + '/node/create', creationBody, voltageHeaders)
    nodeId = response.node_id
    console.log("Created the node: "+nodeId)

    // Wait until the node is waiting_init
    do {
        statusBody = {
            node_id: nodeId
        }
        response = await makeRequest('POST', 'https://api.voltage.cloud/organizations/' + orgId + '/node', statusBody, voltageHeaders)
        nodeStatus = response.status
        nodeApi = response.api_endpoint
        console.log("Found node's status of "+nodeStatus)

        // Wait 5 seconds before checking again
        await new Promise(r => setTimeout(r, 5000))
    }
    while (nodeStatus !== "waiting_init")

    // Get a seed for the node
    response = await makeRequest('GET', 'https://' + nodeApi + ':8080/v1/genseed', {}, {})
    seedPhrase = response.cipher_seed_mnemonic
    console.log("Got seed phrase: "+seedPhrase)

    // Initialize the node
    console.log("Initializing wallet with password: "+nodePassword)
    initBody = {
        wallet_password: Buffer.from(nodePassword).toString('base64'),
        cipher_seed_mnemonic: seedPhrase,
        stateless_init: true
    }
    response = await makeRequest('POST', 'https://'+nodeApi+':8080/v1/initwallet', initBody, {})
    nodeMacaroon = response.admin_macaroon
    console.log("Got Node's Macaroon: "+nodeMacaroon)

    // Encrypt the Macaroon and Seed
    encryptedSeed = crypto.AES.encrypt(
        Buffer.from(seedPhrase.join(",")).toString('base64'),
        nodePassword
    ).toString();

    encryptedMacaroon = crypto.AES.encrypt(
        nodeMacaroon,
        nodePassword
    ).toString();

    // Backup Seed and Macaroon
    let macBody = {
        node_id: nodeId,
        macaroon: encryptedMacaroon,
        name: "admin"
    }
    response = await makeRequest('POST', 'https://api.voltage.cloud/organizations/' + orgId + '/node/macaroon', macBody, voltageHeaders)
    console.log("Uploaded macaroon")

    let seedBackBody = {
        node_id: nodeId,
        seed: encryptedSeed
    }
    response = await makeRequest('POST', 'https://api.voltage.cloud/organizations/' + orgId + '/node/upload_seed', seedBackBody, voltageHeaders)
    console.log("Uploaded seed")

    console.log("Successfully created your node!")
}

function makeRequest(method, url, data, headers) {
    return new Promise(function (resolve, reject) {
        axios({
            method: method,
            url: url,
            headers: headers,
            data: data

        }).then(
            (response) => {
                var result = response.data
                resolve(result)
            },
            (error) => {
                console.log(error)
                reject(error)
            }
        );
    });
}

main()
```

