Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue while creating node #1613

Closed
Shivamycodee opened this issue Mar 6, 2023 · 1 comment
Closed

Issue while creating node #1613

Shivamycodee opened this issue Mar 6, 2023 · 1 comment
Labels
need/triage Needs initial labeling and prioritization

Comments

@Shivamycodee
Copy link

I'm trying to create a libp2p node with a known peerId

peerId:12D3KooWDKBMHRiAXPQK6Xr4cdT7WGp927DUiuNJV4jFBNd2yKkM
code to create libp2p node:-

import { createLibp2p } from "libp2p";
import { webRTCStar } from "@libp2p/webrtc-star";
import { noise } from "@chainsafe/libp2p-noise";
import { mplex } from "@libp2p/mplex";
import { Multiaddr } from "multiaddr";
import { webSockets } from "@libp2p/websockets";
import { kadDHT } from "@libp2p/kad-dht";
import PeerId from "peer-id";
import { floodsub } from "@libp2p/floodsub";

let node = await createLibp2p({
PeerId: peerId,
addresses: {
listen: [
"/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star",
],
},
transports: [webSockets(), wrtcStar.transport],
connectionEncryption: [noise()],
streamMuxers: [mplex()],
peerDiscovery: [wrtcStar.discovery],
dht: kadDHT(),
pubsub: floodsub(),
});

But, the created node have a different peerId from what I have mention, How can I solve it, any suggestions...

@Shivamycodee Shivamycodee added the need/triage Needs initial labeling and prioritization label Mar 6, 2023
@sneaker1
Copy link
Contributor

sneaker1 commented Mar 6, 2023

You need to create a proper PeerId object. You can create it from an existing json.

import { createFromJSON } from '@libp2p/peer-id-factory'
var peerId = await createFromJSON({
  "id": "Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP",
  "privKey": "CAASpwkwggSjAgEAAoIBAQCaNSDOjPz6T8HZsf7LDpxiQRiN2OjeyIHUS05p8QWOr3EFUCFsC31R4moihE5HN+FxNalUyyFZU//yjf1pdnlMJqrVByJSMa+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Wkca74qkbBmPn/6FFEb7PSZTO+tPHjyodGNgz9XpJJRjQuBk1aDJtlF3m1QKBgE5SAr5ym65SZOU3UGUIOKRsfDW4Q/OsqDUImvpywCgBICaX9lHDShFFHwau7FA52ScL7vDquoMB4UtCOtLfyQYA9995w9oYCCurrVlVIJkb8jSLcADBHw3EmqF1kq3NqJqm9TmBfoDCh52vdCCUufxgKh33kfBOSlXuf7B8dgMbAoGAZ3r0/mBQX6S+s5+xCETMTSNv7TQzxgtURIpVs+ZVr2cMhWhiv+n0Omab9X9Z50se8cWl5lkvx8vn3D/XHHIPrMF6qk7RAXtvReb+PeitNvm0odqjFv0J2qki6fDs0HKwq4kojAXI1Md8Th0eobNjsy21fEEJT7uKMJdovI/SErI=",
  "pubKey": "CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCaNSDOjPz6T8HZsf7LDpxiQRiN2OjeyIHUS05p8QWOr3EFUCFsC31R4moihE5HN+FxNalUyyFZU//yjf1pdnlMJqrVByJSMa+y2y4x2FucpoCAO97Tx+iWzwlZ2UXEUXM1Y81mhPbeWXy+wP2xElTgIER0Tsn/thoA0SD2u9wJuVvM7dB7cBcHYmqV6JH+KWCedRTum6O1BssqP/4Lbm2+rkrbZ4+oVRoU2DRLoFhKqwqLtylrbuj4XOI3XykMXV5+uQXz1JzubNOB9lsc6K+eRC+w8hhhDuFMgzkZ4qomCnx3uhO67KaICd8yqqBa6PJ/+fBM5Xk4hjyR40bwcf41AgMBAAE="
});

Now you can pass it to your createLibp2p Function

let node = await createLibp2p({
    PeerId: peerId,
    ...
    ...
)};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/triage Needs initial labeling and prioritization
Projects
None yet
Development

No branches or pull requests

3 participants