docs: Migrate js-ipfs examples to Helia.

This commit is contained in:
Hayden Young 2024-01-19 16:19:18 +00:00
parent 64e36df5a1
commit a7ec7b7b41
3 changed files with 12 additions and 8 deletions

View File

@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>OrbitDB API - v1.0</title>
<title>OrbitDB API - v2.0</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>

View File

@ -89,7 +89,7 @@ The identity object is stored like any other [IPLD data structure](https://ipld.
```js
import { createLibp2p } from 'libp2p'
import { createHelia } from 'helia' from 'ipfs-core'
import { createHelia } from 'helia'
import * as Block from 'multiformats/block'
import { Identities } from '@orbitdb/core'
import * as dagCbor from '@ipld/dag-cbor'

View File

@ -9,19 +9,21 @@ To install OrbitDB:
npm install @orbitdb/core
```
IPFS is also required:
Helia, the Javascript version of IPFS, is also required:
```bash
npm install ipfs-core
npm install helia
```
Instantiate OrbitDB and create a database:
```js
import { create } from 'ipfs-core'
import { createLibp2p } from 'libp2p'
import { createHelia } from 'helia'
import { createOrbitDB } from '@orbitdb/core'
const ipfs = await create() // IPFS is required for storage and network communication
const libp2p = await createLibp2p({ /* Libp2p options */ })
const ipfs = await createHelia({ libp2p }) // Helia is required for storage and network communication
const orbitdb = await createOrbitDB({ ipfs })
const mydb = await orbitdb.open('mydb')
console.log(mydb.address) // /orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13
@ -32,10 +34,12 @@ Open and replicate an existing database:
```js
// In another process
import { create } from 'ipfs-core'
import { createLibp2p } from 'libp2p'
import { createHelia } from 'helia'
import { createOrbitDB } from '@orbitdb/core'
const ipfs = await create()
const libp2p = await createLibp2p({ /* Libp2p options */ })
const ipfs = await createHelia({ libp2p }) // Helia is required for storage and network
const orbitdb = await createOrbitDB({ ipfs })
const theirdb = await orbitdb.open('/orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13')
for await (let record of theirdb.iterator()) {