libp2p / js-libp2p

The JavaScript Implementation of libp2p networking stack.
https://libp2p.github.io/js-libp2p/
Other
2.33k stars 446 forks source link

Example returns empty object. #2385

Closed sleep9 closed 9 months ago

sleep9 commented 9 months ago

Severity:

Severity: High

Description:

` import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' import { noise } from '@chainsafe/libp2p-noise' import { yamux } from '@chainsafe/libp2p-yamux' import{ mdns } from '@libp2p/mdns';

const createNode = () => { return createLibp2p({ addresses: { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [ tcp() ], streamMuxers: [ yamux(),mplex() ], connectionEncryption: [ noise() ], peerDiscovery: [ mdns() ] }) }

export const main = async () => {

   const [node1, node2] = await Promise.all([
    createNode(),
    createNode()
  ])

  await node1.start();
  await node2.start();
  console.log('node1: ', node1);
  console.log('node2: ', node2);

}

main() ` console outputs the following empty objects node1: Libp2pNode {} node2: Libp2pNode {}

SgtPooki commented 9 months ago

which example is this for? I can't find that code anywhere via https://github.com/search?q=org%3Alibp2p+%27const+%5Bnode1%2C+node2%5D+%3D+await+Promise.all%28%5B%27&type=code or searching locally

sleep9 commented 9 months ago

Slightly modified from this example which is outdated it seems? https://github.com/libp2p/js-libp2p/blob/v0.28.4/examples/pubsub/1.js

achingbrain commented 9 months ago

I'm not sure this is a problem, this is just how console.log prints objects instantiated from ES6 classes.

You may find it more useful to log the peer id instead?

console.log('node1', node1.peerId)
// node1 PeerId(12D3Foo...)
sleep9 commented 9 months ago

Your are correct good sir.