-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_node.js
34 lines (30 loc) · 880 Bytes
/
create_node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { MemoryBlockstore } from "blockstore-core";
import { MemoryDatastore } from "datastore-core";
import { createHelia } from "helia";
import { createLibp2p } from "libp2p";
import { tcp } from "@libp2p/tcp";
import { noise } from "@chainsafe/libp2p-noise";
import { yamux } from "@chainsafe/libp2p-yamux";
import { identifyService } from "libp2p/identify";
export const createNode = async () => {
const blockstore = new MemoryBlockstore();
const datastore = new MemoryDatastore();
const libp2p = await createLibp2p({
addresses: {
listen: ["/ip4/127.0.0.1/tcp/0"],
},
transports: [tcp()],
connectionEncryption: [noise()],
streamMuxers: [yamux()],
datastore,
services: {
identify: identifyService(),
},
});
const ipfsClient = await createHelia({
libp2p,
blockstore,
datastore,
});
return ipfsClient;
};