-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Victor Maia
committed
Apr 11, 2017
1 parent
aa4e761
commit 66d7775
Showing
3 changed files
with
25 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,32 @@ | ||
const Swarm = require("./../src/swarm.js"); | ||
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 config = { | ||
account: "d849168d52ea5c40de1b0b973cfd96873c961963", | ||
password: "sap", | ||
dataDir: process.env.HOME+"/Library/Ethereum/testnet", | ||
ethApi: process.env.HOME+"/Library/Ethereum/testnet/geth.ipc" | ||
privateKey: privateKeyPath, | ||
dataDir: process.env.HOME + "/Library/Ethereum/testnet", | ||
ethApi: process.env.HOME + "/Library/Ethereum/testnet/geth.ipc" | ||
}; | ||
|
||
// Magically starts a local Swarm node | ||
// Downloads binaries if necessary | ||
Swarm.local(config)(swarm => new Promise((resolve, reject) => { | ||
console.log("running"); | ||
console.log(swarm); | ||
// Removes the temporary private key file | ||
fs.unlinkSync(privateKeyPath); | ||
|
||
// Uploads data using the local node | ||
swarm.upload(new Buffer("test")).then(hash => { | ||
console.log("Uploaded data. Address:", hash); | ||
|
||
// Closes the Swarm process. | ||
resolve(); | ||
}); | ||
|
||
}).catch(e => console.log(e)); | ||
})) | ||
.then(() => console.log("Done!")); | ||
.then(() => console.log("Done!")) | ||
.catch(e => console.log(e)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters