Voltage
Search…
Creating a Node Walkthrough
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 endpoint to create a node with your settings
    2.
    Call the /node 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 on the node to generate a seed for yourself.
    4.
    Once you have a seed, you can initialize the wallet. Call the /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 and /node/macaroon 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 endpoint.

Example

Here is an example script written in Node.js. This script would create a node, initialize it, and upload the encrypted backups.
1
const axios = require('axios')
2
const crypto = require('crypto-js')
3
4
// Define your variables
5
let apiKey = "YOUR_API_KEY_HERE"
6
let nodeName = "voltage-example"
7
let nodePassword = "YOUR_SECURE_PASSWORD"
8
9
async function main() {
10
console.log("Creating your node...")
11
12
voltageHeaders = {
13
'X-VOLTAGE-AUTH': apiKey,
14
}
15
16
// Create the Node
17
creationBody = {
18
network: "testnet",
19
purchased_type: "ondemand",
20
type: "standard",
21
name: nodeName,
22
settings: {
23
alias: nodeName,
24
autocompaction: false,
25
autopilot: false,
26
color: "#EF820D",
27
grpc: true,
28
keysend: true,
29
rest: true,
30
whitelist: [
31
"1.2.3.4"
32
],
33
wumbo: true
34
}
35
}
36
response = await makeRequest('POST', 'https://api.voltage.cloud/node/create', creationBody, voltageHeaders)
37
nodeId = response.node_id
38
console.log("Created the node: "+nodeId)
39
40
// Wait until the node is waiting_init
41
do {
42
statusBody = {
43
node_id: nodeId
44
}
45
response = await makeRequest('POST', 'https://api.voltage.cloud/node', statusBody, voltageHeaders)
46
nodeStatus = response.status
47
nodeApi = response.api_endpoint
48
console.log("Found node's status of "+nodeStatus)
49
50
// Wait 5 seconds before checking again
51
await new Promise(r => setTimeout(r, 5000))
52
}
53
while (nodeStatus !== "waiting_init")
54
55
// Get a seed for the node
56
response = await makeRequest('GET', 'https://' + nodeApi + ':8080/v1/genseed', {}, {})
57
seedPhrase = response.cipher_seed_mnemonic
58
console.log("Got seed phrase: "+seedPhrase)
59
60
// Initialize the node
61
console.log("Initializing wallet with password: "+nodePassword)
62
initBody = {
63
wallet_password: Buffer.from(nodePassword).toString('base64'),
64
cipher_seed_mnemonic: seedPhrase,
65
stateless_init: true
66
}
67
response = await makeRequest('POST', 'https://'+nodeApi+':8080/v1/initwallet', initBody, {})
68
nodeMacaroon = response.admin_macaroon
69
console.log("Got Node's Macaroon: "+nodeMacaroon)
70
71
// Encrypt the Macaroon and Seed
72
encryptedSeed = crypto.AES.encrypt(
73
Buffer.from(seedPhrase.join(",")).toString('base64'),
74
nodePassword
75
).toString();
76
77
encryptedMacaroon = crypto.AES.encrypt(
78
nodeMacaroon,
79
nodePassword
80
).toString();
81
82
// Backup Seed and Macaroon
83
let macBody = {
84
node_id: nodeId,
85
macaroon: encryptedMacaroon,
86
name: "admin"
87
}
88
response = await makeRequest('POST', 'https://api.voltage.cloud/node/macaroon', macBody, voltageHeaders)
89
console.log("Uploaded macaroon")
90
91
let seedBackBody = {
92
node_id: nodeId,
93
seed: encryptedSeed
94
}
95
response = await makeRequest('POST', 'https://api.voltage.cloud/node/upload_seed', seedBackBody, voltageHeaders)
96
console.log("Uploaded seed")
97
98
console.log("Successfully created your node!")
99
}
100
101
function makeRequest(method, url, data, headers) {
102
return new Promise(function (resolve, reject) {
103
axios({
104
method: method,
105
url: url,
106
headers: headers,
107
data: data
108
109
}).then(
110
(response) => {
111
var result = response.data
112
resolve(result)
113
},
114
(error) => {
115
console.log(error)
116
reject(error)
117
}
118
);
119
});
120
}
121
122
main()
Copied!
Last modified 1mo ago
Copy link