Basic libp2p bundle with settings that match js-ipfs.
This package provides a zero-config setup to make it easy to include a fully-configured libp2p host in any application. It is almost directly copied from js-ipfs, so you can be confident the settings are compatible. It also allows more nuanced access to the underlying libp2p settings.
npm i @nullify/libp2p-bundle
import create from "@nullify/libp2p-bundle";
const run = async () => {
const node = await create({
multiaddrs: ["/ip4/0.0.0.0/tcp/4007", "/ip4/0.0.0.0/tcp/4008/ws"],
});
const p = new Promise((resolve) => {
// Promise resolves on first discovered peer
node.on("peer:discovery", (peerId) => {
resolve(peerId);
});
});
await node.start();
const listenAddrs = node.transportManager.getAddrs();
console.log("listening on: ", listenAddrs);
const peerId = await p;
console.log(`Discovered: ${peerId.toB58String()}`);
await node.stop();
process.exit();
};
run();
- Repo :
object
- Libp2pConfig :
module:libp2p~Libp2pConfig
- Libp2p :
module:libp2p
- Options :
object
create(options) ⇒ Promise.<Libp2p>
Kind: global function
Returns: Promise.<Libp2p>
-
A properly configured libp2p host.
Param | Type | Description |
---|---|---|
options | Options | The set of options to control bundle creation. |
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
[datastore] | module:interface-datastore~Datastore | Input datastore. |
[keys] | module:interface-datastore~Datastore | Input keystore |
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
[options] | any | IPFS options. |
[peerId] | PeerId | Input PeerID object. |
[multiaddrs] | Array.<string> | Set of multiaddrs to listen on. |
[repo] | Repo | Input repo config. |
[keychainConfig] | Object | Input keychain config. |
[config] | Libp2pConfig | Libp2p options. |
PRs accepted.
Small note: If editing the README, please conform to the standard-readme specification.
MIT © 2021 Carson Farmer