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

chore: update example #291

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions packages/discv5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,26 @@ Included is a libp2p peer-discovery compatibility module.
#### Example

```typescript
import { Discv5Discovery, ENR } from "@chainsafe/discv5";
import Libp2p from "libp2p";
import {Discv5Discovery} from "@chainsafe/discv5";
import {ENR, SignableENR} from "@chainsafe/enr";
Copy link
Member

@nflaig nflaig Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have to import these from enr package or does discv5 re-export? the later seems better devex to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen them being re-exported. Maybe @wemeetagain knows better?

import {createLibp2p} from "libp2p";
import PeerId from "peer-id";

const myPeerId: PeerId = ...;

const bootstrapEnrs: ENR[] = [...];
const bootEnrs: ENR[] = [...];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add an import for this type?

Copy link
Member

@nflaig nflaig Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a general issue with our readme examples also in the Lodestar repo, might wanna spend some time investigating ChainSafe/lodestar#6300. This would ensure the examples are runnable and detect issues due to code refactoring / dependency updates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wemeetagain done!


const libp2p = new Libp2p({
const libp2p = createLibp2p({
peerId: myPeerId,
modules: {
peerDiscovery: [Discv5Discovery],
},
config: {
discv5: {
enr: ENR.createFromPeerId(myPeerInfo.id),
bindAddr: "/ip4/0.0.0.0/udp/9000",
bootstrapEnrs: bootstrapEnrs,
searchInterval: 30000, // wait 30s between searches
},
},
peerDiscovery: [() => new Discv5Discovery({
enabled: true,
enr: SignableENR.createFromPeerId(myPeerId),
peerId: myPeerId,
bindAddrs: {ip4: "/ip4/0.0.0.0/udp/9000"},
bootEnrs,
searchInterval: 30000, // wait 30s between searches
})]
});

```

## Additional features
Expand Down
Loading