I’m currently trying to instantiate a local Helia node in the browser where I’m able to pin content using blockstore-idb. So for instantiating Helia I’m using the following config:
async function createNode() {
let localSafedBlockstore = window.localStorage.getItem("blockstore");
let localSafedDatasore = window.localStorage.getItem("datastore");
if (!localSafedBlockstore) {
localSafedBlockstore = "blockstore-" + window.crypto.randomUUID();
window.localStorage.setItem("blockstore", localSafedBlockstore);
}
if (!localSafedDatasore) {
localSafedDatasore = "datastore-" + window.crypto.randomUUID();
window.localStorage.setItem("datastore", localSafedDatasore);
}
// the blockstore is where we store the blocks that make up files
const blockstore = new IDBBlockstore(localSafedBlockstore);
await blockstore.open();
// application-specific data lives in the datastore
const datastore = new IDBDatastore(localSafedDatasore);
await datastore.open();
// libp2p is the networking layer that underpins Helia
const libp2p = await createLibp2p({
datastore,
transports: [webSockets(), webTransport()],
connectionEncryption: [noise()],
streamMuxers: [yamux()],
peerDiscovery: [
bootstrap({
list: [
"/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
"/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
"/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
"/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
],
}),
],
});
// Listen for new peers
libp2p.addEventListener("peer:discovery", (evt) => {
const peer = evt.detail;
// dial them when we discover them
libp2p.dial(peer.id).catch((err) => {
console.log(`Could not dial ${peer.id}`, err);
});
});
// Listen for new connections to peers
libp2p.addEventListener("peer:connect", (evt) => {
const connection = evt.detail;
console.log(`Connected to ${connection.toString()}`);
});
// Listen for peers disconnecting
libp2p.addEventListener("peer:disconnect", (evt) => {
const connection = evt.detail;
console.log(`Disconnected from ${connection.toCID().toString()}`);
});
return await createHelia({
datastore,
blockstore,
libp2p,
});
}
However, I’m not able to establish a connection to other peers. And therefore I’m not able to find my node and the pinned content using PL Diagnose.
The events always indicate that I get connected and then immediately disconnected again. The image shows the output of the events defined when creating my node.
I already looked into the Helia examples, as well as multiple issues and PRs on the repositories. I’m really out of ideas.
Is there something wrong with my libp2p configuration or could it be an entirely different issue (Firewall etc)?
EDIT: Okay it seems like I totally misused blockstore-idb and datastore-idb. Using Memory Datastore I get connections to others peers and my node can be found in the DHT.