Last active
March 25, 2022 09:23
-
-
Save Nuhvi/60291b111f93928d8110ff0ae9ecea25 to your computer and use it in GitHub Desktop.
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
// npm i [email protected] [email protected] | |
// Run `node create-hypercore.js` and pass the resulting key to https://gist.github.com/Nazeh/721368b93729dcfa00049c9de230f2ad | |
const Hypercore = require('hypercore'); | |
const Hyperswarm = require('hyperswarm'); | |
const createCore = async () => { | |
const core = new Hypercore('origin', { valueEncoding: 'json' }); | |
await core.ready(); | |
// Add blocks here if you want. | |
const blocks = [{ foo: 0 }, { foo: 0, bar: 1 }]; | |
await core.append(blocks); | |
const swarm = new Hyperswarm(); | |
swarm.on('connection', (conn, info) => { | |
console.log('connected to peer', info); | |
core.replicate(conn); | |
}); | |
const discovery = swarm.join(core.discoveryKey, { | |
server: true, | |
client: false, | |
}); | |
await discovery.flushed(); | |
console.log('Created core: ', core.key.toString('hex')); | |
process.once('SIGINT', () => { | |
swarm.destroy(); | |
}); | |
}; | |
createCore(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment