helia_node.ts
1 import { noise } from '@chainsafe/libp2p-noise' 2 import { yamux } from '@chainsafe/libp2p-yamux' 3 import { unixfs } from '@helia/unixfs' 4 import { bootstrap } from '@libp2p/bootstrap' 5 import { identify } from '@libp2p/identify' 6 import { tcp } from '@libp2p/tcp' 7 import { MemoryBlockstore } from 'blockstore-core' 8 import { MemoryDatastore } from 'datastore-core' 9 import { createHelia } from 'helia' 10 import { createLibp2p } from 'libp2p' 11 12 13 // adapted from: https://github.com/ipfs-examples/helia-examples/blob/main/examples/helia-101/301-networking.js 14 15 async function createNode() { 16 // the blockstore is where we store the blocks that make up files 17 const blockstore = new MemoryBlockstore() 18 19 // application-specific data lives in the datastore 20 const datastore = new MemoryDatastore() 21 22 // libp2p is the networking layer that underpins Helia 23 const libp2p = await createLibp2p({ 24 datastore, 25 peerDiscovery: [ 26 bootstrap({ 27 list: [ 28 '/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN', 29 '/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa', 30 '/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb', 31 '/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt', 32 '/ip4/165.227.41.107/tcp/4001/p2p/12D3KooWLFe4THrNrBZ4WmkxfHbjxL2C3nF6ni3ZF5txkWSsmjv9' 33 ] 34 }) 35 ], 36 services: { 37 identify: identify() 38 } 39 }) 40 41 // const customNomde = await createHelia({ 42 // datastore, 43 // blockstore, 44 // libp2p 45 // }) 46 47 return createHelia() 48 } 49 50 export { createNode }