Last active
November 1, 2018 06:17
-
-
Save vongohren/bb6dd69f60426f5a408fa71db191547a 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
import IPFS from 'ipfs' | |
import OrbitDB from 'orbit-db' | |
// OrbitDB uses Pubsub which is an experimental feature | |
// and need to be turned on manually. | |
// Note that these options need to be passed to IPFS in | |
// all examples even if not specified so. | |
const ipfsOptions = { | |
EXPERIMENTAL: { | |
pubsub: true | |
} | |
} | |
const ipfs = new IPFS(ipfsOptions) | |
let orbitdb; | |
ipfs.on('error', (e) => console.error(e)) | |
ipfs.on('ready', async () => { | |
orbitdb = await OrbitDB.createInstance(ipfs); | |
console.log('IPFS ready'); | |
}) | |
export const getOrbitDb = async (endpoint) => { | |
// Create / Open a database | |
console.log('asdjsadjadjsa') | |
try { | |
console.log('open') | |
const db = await orbitdb.open(endpoint, { | |
// If database doesn't exist, create it | |
create: true, | |
overwrite: true, | |
}) | |
console.log('ran open') | |
db.events.on('ready', () => { | |
console.log('READY') | |
}) | |
await db.load() | |
return db; | |
} catch(e) { | |
console.error(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment