-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathrun_node.js
36 lines (30 loc) · 1.13 KB
/
run_node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// THIS IS OUTDATED
// TODO: update it
const Swarm = require("./..");
const fs = require("fs");
const path = require("path");
const privateKeyPath = path.join(process.cwd(), "swarmPrivateKey");
// Writes a temporary private key file to disk
fs.writeFileSync(privateKeyPath, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef");
// To run Swarm locally, you need a running Geth
// node and an Ethereum account/password
const swarmSetup = {
privateKey: privateKeyPath,
dataDir: process.env.HOME + "/Library/Ethereum/testnet",
ensApi: process.env.HOME + "/Library/Ethereum/testnet/geth.ipc",
binPath: process.env.HOME + "/.swarm/swarm"
};
// Magically starts a local Swarm node
// Downloads binaries if necessary
Swarm.local(swarmSetup)(swarm => new Promise((resolve, reject) => {
// Removes the temporary private key file
fs.unlinkSync(privateKeyPath);
// Uploads data using the local node
swarm.upload("test").then(hash => {
console.log("Uploaded data. Address:", hash);
// Closes the Swarm process.
resolve();
}).catch(e => console.log(e));
}))
.then(() => console.log("Done!"))
.catch(e => console.log(e));