Skip to content

Instantly share code, notes, and snippets.

@vasco-santos
Last active September 24, 2020 17:28
Show Gist options
  • Save vasco-santos/4f22275a8146dfcf34dde830cabb23ae to your computer and use it in GitHub Desktop.
Save vasco-santos/4f22275a8146dfcf34dde830cabb23ae to your computer and use it in GitHub Desktop.
libp2p discovery setup
const Libp2p = require('libp2p')
const WebSockets = require('libp2p-websockets')
const WebRtcStar = require('libp2p-webrtc-star')
const Bootstrap = require('libp2p-bootstrap')
const Mdns = require('libp2p-mdns')
// Known peers addresses
const bootstrapMultiaddrs = [
 '/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
 '/dns4/lon-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3'
]
const node = await Libp2p.create({
modules: {
  // … other required modules
transport: [WebSockets, WebRtcStar],
peerDiscovery: [Bootstrap, Mdns]
  },
  config: {
peerDiscovery: {
[Bootstrap.tag]: {
enabled: true,
list: bootstrapMultiaddrs // provide array of multiaddrs
  }
  }
  },
// ...
})
await node.start()
node.on('peer:discovery', (peer) => {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment