Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save louis030195/bb3637d26eb55cbe56aa729160e3c1e7 to your computer and use it in GitHub Desktop.
Save louis030195/bb3637d26eb55cbe56aa729160e3c1e7 to your computer and use it in GitHub Desktop.
Pushing your electrical brain activity from Neurosity Crown to Arweave, the permaweb
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