Skip to content

Latest commit

 

History

History
51 lines (36 loc) · 1.38 KB

README.md

File metadata and controls

51 lines (36 loc) · 1.38 KB

discv5

ES Version Node Version

A TypeScript implementation of the DiscV5 protocol

Libp2p compatibility

Peer Discovery Compatible

Included is a libp2p peer-discovery compatibility module.

Example

import {Discv5Discovery} from "@chainsafe/discv5";
import {ENR, SignableENR} from "@chainsafe/enr";
import {createLibp2p} from "libp2p";
import PeerId from "peer-id";

const myPeerId: PeerId = ...;

const bootEnrs: ENR[] = [...];

const libp2p = createLibp2p({
  peerId: myPeerId,
  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

By default, importing this library will, as a side-effect, change the enr crypto implementation to use bcrypto. If you'd like to remain using @chainsafe/enr's default crypto you can add this after importing @chainsafe/discv5:

import {setV4Crypto, defaultCrypto} from "@chainsafe/enr";

setV4Crypto(defaultCrypto)

License

Apache-2.0