Hi, I’m trying to use gossipsub to build a decentralized mobile chat app @ ETHIndia.
I’m using GitHub - ChainSafe/js-libp2p-gossipsub: TypeScript implementation of Gossipsub but need some help
Here is the code to setup libp2p node:
import { GossipSub } from '@chainsafe/libp2p-gossipsub'
const createNode = async () => {
const node = await createLibp2p({
addresses: {
// add a listen address (localhost) to accept TCP connections on a random port
listen: ['/ip4/0.0.0.0/tcp/0/ws']
},
// transports: [tcp()],
transports: [webSockets({
filters: all
})],
connectionEncryption: [noise()],
streamMuxers: [mplex()],
peerDiscovery: [
bootstrap({
list: bootstrapMultiaddrs,
})
],
connectionManager: {
autoDial: true,
},
dht: kadDHT(),
// pubsub: floodsub()
pubsub: new GossipSub({
emitSelf: true
})
})
return node
}
const options = {}
const gsub = new GossipSub(node, options)
await gsub.start()
gsub.on('fruit', (data) => {
console.log(data)
})
gsub.subscribe('fruit')
gsub.publish('fruit', new TextEncoder().encode('banana'))
And here is the error I’m facing right now:
gsub.on('fruit', (data) => {
^
TypeError: gsub.on is not a function
at file:///home/boogeyman/GIT/Hub/ohjihq/js-libp2p-playground/src/index.js:62:6
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v18.10.0