Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Update GETTING_STARTED.md docs to give users default configs #2091

Open
Tracked by #2081
maschad opened this issue Sep 28, 2023 · 0 comments
Open
Tracked by #2081

docs: Update GETTING_STARTED.md docs to give users default configs #2091

maschad opened this issue Sep 28, 2023 · 0 comments
Labels
topic/docs Documentation

Comments

@maschad
Copy link
Member

maschad commented Sep 28, 2023

We a user lands on the https://github.com/libp2p/js-libp2p/blob/master/doc/GETTING_STARTED.md page, they should primarily see a defaultConfig that would allow them to get started on most networking setups. Here's an example

import { createLibp2p } from 'libp2p'
import { webSockets } from '@libp2p/websockets'
import { noise } from '@chainsafe/libp2p-noise'
import { mplex } from '@libp2p/mplex'
import { yamux } from '@chainsafe/libp2p-yamux',

import { bootstrap } from '@libp2p/bootstrap'

// Known peers addresses
const bootstrapMultiaddrs = [
  '/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb',
  '/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN'
]

const node = await createLibp2p({
  transports: [webSockets()],
  connectionEncryption: [noise()],
  streamMuxers: [yamux(), mplex()],
  peerDiscovery: [
    bootstrap({
      list: bootstrapMultiaddrs, // provide array of multiaddrs
    })
  ]
})

node.addEventListener('peer:discovery', (evt) => {
  console.log('Discovered %s', evt.detail.id.toString()) // Log discovered peer
})

node.addEventListener('peer:connect', (evt) => {
  console.log('Connected to %s', evt.detail.remotePeer.toString()) // Log connected peer
})

The user can then go through the remaining sections to learn more about peer discovery, connection encryption, transports, pubsub, stream muxers etc.

@maschad maschad added the need/triage Needs initial labeling and prioritization label Sep 28, 2023
@maschad maschad changed the title docs: Update GETTING_STARTED docs to give users default configs docs: Update GETTING_STARTED.md docs to give users default configs Oct 2, 2023
@maschad maschad added topic/docs Documentation and removed need/triage Needs initial labeling and prioritization labels Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic/docs Documentation
Projects
Status: 🛠️ Todo
Development

No branches or pull requests

1 participant