Skip to content

Instantly share code, notes, and snippets.

@vasa-develop
Created December 28, 2019 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vasa-develop/1c1ab6296adf853ec46a1c6ef21bead6 to your computer and use it in GitHub Desktop.
Save vasa-develop/1c1ab6296adf853ec46a1c6ef21bead6 to your computer and use it in GitHub Desktop.
SimpleAsWater: Building a Chat Application using Libp2p
'use strict'
/* eslint-disable no-console */
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const Node = require('./libp2p_bundle')
const chalk = require('chalk');
const emoji = require('node-emoji')
PeerId.createFromJSON(require('./ids/moonId'), (err, peerId) => {
if (err) {
throw err
}
const peerInfo = new PeerInfo(peerId)
peerInfo.multiaddrs.add('/ip4/127.0.0.1/tcp/10333')
const nodeListener = new Node({ peerInfo })
nodeListener.start((err) => {
if (err) {
throw err
}
console.log(emoji.get('moon'), chalk.blue(' Moon ready '),
emoji.get('headphones'), chalk.blue(' Listening on: '));
peerInfo.multiaddrs.forEach((ma) => {
console.log(ma.toString() + '/p2p/' + peerId.toB58String())
})
console.log('\n' + emoji.get('moon'), chalk.blue(' Moon trying to connect with Earth '),
emoji.get('large_blue_circle'));
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment