Skip to content

Commit

Permalink
fix: update Helia usage and fix tests (#63)
Browse files Browse the repository at this point in the history
Helia 1.1.x comes with a libp2p instance so remove custom libp2p
creation.  The 101 example still has it so there's still a reference
to link people to.
  • Loading branch information
achingbrain authored May 22, 2023
1 parent 2e70bb8 commit 5f0c6e2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 54 deletions.
47 changes: 1 addition & 46 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,10 @@

async function main () {
const { createHelia } = await import('helia')
const { createLibp2p } = await import('libp2p')
const { identifyService } = await import('libp2p/identify')
const { noise } = await import('@chainsafe/libp2p-noise')
const { yamux } = await import('@chainsafe/libp2p-yamux')
const { webSockets } = await import('@libp2p/websockets')
const { bootstrap } = await import('@libp2p/bootstrap')
const { unixfs } = await import('@helia/unixfs')
const { MemoryBlockstore } = await import('blockstore-core')
const { MemoryDatastore } = await import('datastore-core')

// the blockstore is where we store the blocks that make up files
const blockstore = new MemoryBlockstore()

// application-specific data lives in the datastore
const datastore = new MemoryDatastore()

// libp2p is the networking layer that underpins Helia
const libp2p = await createLibp2p({
datastore,
transports: [
webSockets()
],
connectionEncryption: [
noise()
],
streamMuxers: [
yamux()
],
peerDiscovery: [
bootstrap({
list: [
'/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN',
'/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa',
'/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb',
'/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt'
]
})
],
services: {
identify: identifyService()
}
})

// create a Helia node
const helia = await createHelia({
datastore,
blockstore,
libp2p
})
const helia = await createHelia()

// print out our node's PeerId
console.log(helia.libp2p.peerId)
Expand Down
9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@
"test": "test-node-example test/*"
},
"dependencies": {
"@chainsafe/libp2p-noise": "^12.0.0",
"@chainsafe/libp2p-yamux": "^4.0.1",
"@helia/unixfs": "^1.2.1",
"@libp2p/bootstrap": "^8.0.0",
"@libp2p/websockets": "^6.0.1",
"blockstore-core": "^4.1.0",
"datastore-core": "^9.1.1",
"helia": "^1.0.0",
"libp2p": "^0.45.0"
"helia": "^1.0.0"
},
"devDependencies": {
"test-ipfs-example": "^1.0.0"
Expand Down

0 comments on commit 5f0c6e2

Please sign in to comment.