Created
July 22, 2023 00:47
-
-
Save louis030195/bb3637d26eb55cbe56aa729160e3c1e7 to your computer and use it in GitHub Desktop.
Pushing your electrical brain activity from Neurosity Crown to Arweave, the permaweb
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
import Bundlr from "@bundlr-network/client"; | |
import fs from "fs"; | |
import Arweave from "arweave"; | |
import { Neurosity } from "@neurosity/sdk"; | |
const jwk = JSON.parse(fs.readFileSync("wallet.json").toString()); | |
const neurosity = new Neurosity(); | |
neurosity.login({ | |
email: process.env.NEUROSITY_EMAIL!, | |
password: process.env.NEUROSITY_PASSWORD! | |
}) | |
.catch(error => { | |
console.log("error", error); | |
}).then(() => { | |
console.log("🧠 Ready to receive your EEG brain waves"); | |
neurosity.brainwaves("raw").subscribe((brainwaves) => { | |
// Stringify the entire brainwave object | |
const json = JSON.stringify(brainwaves); | |
uploadToArweave(json) | |
.then((r) => console.log(`https://arweave.net/${r.id}`)) | |
.catch(console.log); | |
}); | |
}); | |
const uploadToArweave = async (data: string, bundlr = true) => { | |
if (bundlr) { | |
const bundlr = new Bundlr( | |
"http://node2.bundlr.network", | |
"arweave", | |
jwk | |
); | |
return bundlr | |
.upload(data) | |
} | |
// initialize arweave | |
const arweave = Arweave.init({ | |
host: "arweave.net", | |
port: 443, | |
protocol: "https", | |
}); | |
const tx = await arweave.createTransaction( | |
{ | |
data: data, | |
}, | |
jwk | |
); | |
await arweave.transactions.sign(tx, jwk); | |
arweave.transactions.post(tx).then(console.log).catch(console.log); | |
return tx; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment