const axios = require('axios')
const crypto = require('crypto-js')
let apiKey = "YOUR_API_KEY_HERE"
let nodeName = "voltage-example"
let nodePassword = "YOUR_SECURE_PASSWORD"
console.log("Creating your node...")
'X-VOLTAGE-AUTH': apiKey,
purchased_type: "ondemand",
response = await makeRequest('POST', 'https://api.voltage.cloud/node/create', creationBody, voltageHeaders)
nodeId = response.node_id
console.log("Created the node: "+nodeId)
// Wait until the node is waiting_init
response = await makeRequest('POST', 'https://api.voltage.cloud/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)
console.log("Initializing wallet with password: "+nodePassword)
wallet_password: Buffer.from(nodePassword).toString('base64'),
cipher_seed_mnemonic: seedPhrase,
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'),
encryptedMacaroon = crypto.AES.encrypt(
// Backup Seed and Macaroon
macaroon: encryptedMacaroon,
response = await makeRequest('POST', 'https://api.voltage.cloud/node/macaroon', macBody, voltageHeaders)
console.log("Uploaded macaroon")
response = await makeRequest('POST', 'https://api.voltage.cloud/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) {
var result = response.data