I´m trying to create a node with lib but when I add the addresses filed, the next error comes out:
P2PService.js:83 Error al crear el nodo: CodeError: no valid addresses were provided for transports [@libp2p/websockets]
at DefaultTransportManager.listen (transport-manager.ts:260:1)
at DefaultTransportManager.afterStart (transport-manager.ts:75:1)
at components.ts:75:1
at Array.map (<anonymous>)
at Proxy._invokeStartableMethod (components.ts:71:1)
at Proxy.afterStart (components.ts:90:1)
at Libp2pNode.start (libp2p.ts:217:1)
at async createLibp2p (index.ts:170:1)
at async createNode (P2PService.js:60:1)
I made sure the port was available and even tried different ones but it’s impossible to get my node to work. I’m trying to create a chat app that connects individual nodes to a hub and then provide their emails to find each other. Please I need help, this is very urgent.
The code is this:
import { createLibp2p } from 'libp2p'
import { createFromJSON } from '@libp2p/peer-id-factory'
import { webSockets } from '@libp2p/websockets'
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { kadDHT } from '@libp2p/kad-dht'
import PeerId from 'peer-id'
import { generateKeyPairFromSeed } from '@libp2p/crypto/keys'
const chatProtocol = '/mychat/1.0.0'
export async function createPeerId(privKey) {
try {
const peerIdPrivateKey = await generateKeyPairFromSeed("Ed25519", privKey)
console.log('peerIdPrivateKey:', peerIdPrivateKey)
const peerId = await PeerId.createFromPrivKey(peerIdPrivateKey.bytes)
console.log('peerId:', peerId)
localStorage.setItem('peerId', JSON.stringify(peerId))
console.log('Archivo JSON escrito con éxito')
} catch (error) {
console.error('Error al crear el PeerId:', error)
}
}
function getStoredPeerId() {
const peerDataJSON = localStorage.getItem('peerId')
if (!peerDataJSON) {
console.error('No se encontraron datos de PeerId en localStorage')
return null
}
return JSON.parse(peerDataJSON)
}
export async function createNode(privKey) {
await createPeerId(privKey)
const storedPeerId = getStoredPeerId()
console.log('PeerId almacenado recuperado:', storedPeerId)
const peerId = await createFromJSON(storedPeerId)
console.log('PeerId creado desde el JSON:', peerId)
if (!peerId) {
console.log('No se encontraron datos de PeerId')
return
}
try {
const node = await createLibp2p({
peerId: peerId,
addresses: {
listen: ['/ip4/127.0.0.1/tcp/10333']
},
transports: [webSockets()],
connectionEncryption: [noise()],
streamMuxers: [yamux()],
services: {
dht: kadDHT({
})
}
})
await node.start()
console.log('libp2p has started', node)
const listenAddrs = node.getMultiaddrs()
console.log('libp2p is listening on the following addresses: ', listenAddrs)
return node
} catch (error) {
console.error('Error al crear el nodo:', error)
}
}
Martín Castro Fernández is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.