showing error like this CodeError: no valid addresses were provided for transports [@libp2p/websockets] at DefaultTransportManager.listen (file:///home/hani/Developer/IPFS/Helia%20IPFS%20On%20Nodejs/node_modules/libp2p/dist/src/transport-manager.js:19

async function createnode() {
const { createLibp2p } = await import(‘libp2p’)
const { createHelia } = await import(‘helia’)
const { MemoryDatastore } = await import(‘datastore-core’);
const { MemoryBlockstore } = await import(‘blockstore-core’);
const datastore = new MemoryDatastore()
const blockstore = new MemoryBlockstore()
const { webSockets } = await import(‘@libp2p/websockets’)
const { noise } = await import(‘@chainsafe/libp2p-noise’);
const { yamux } = await import(“@chainsafe/libp2p-yamux”);
const { tcp } = await import(‘@libp2p/tcp’)

return createHelia({
    datastore,
    blockstore,
    libp2p: await createLibp2p({
        addresses: {
            listen: ['/ip4/142.256.23.25/tcp/4040']
        },
        transports: [
            // webSockets()
            tcp()
        ],
        connectionEncryption: [
            noise()
        ],
        streamMuxers: [
            yamux()
        ],
        datastore
    })

})

}

async function Addget(){

const nodeA = await createnode()
const nodeB = await createnode()

await nodeA.lipp2p.dial(nodeB.lipp2p.getMultiaddrs())

const input = new TextEncoder().encode(‘helloworld’)
const digest =await sha256.digest(input)
const cid = CID.createV1(raw.code,digest)

await nodeA.blockstore.put(cid,input)

const block =await nodeB.blockstore.get(cid)

console.info( new TextDecoder().decode(block))

await nodeA.stop()
await nodeB.stop()
}

Your error says:

no valid addresses were provided for transports [@libp2p/websockets]

…but your code example has commented out adding the websocket transport to libp2p so I think you may have changed the code at some point after you got that error.

Your config also has both nodes trying to listen on port 4040 of 142.256.23.25 - they cannot both listen on the same port.

If you use 0 as the port number it’ll choose a random high port.

1 Like