Registry / messaging / grpc-libp2p-client

grpc-libp2p-client

JSON →
library0.0.42jsnpmunverified

grpc-libp2p-client is a browser-based gRPC client library built on libp2p, enabling direct peer-to-peer gRPC communication from browsers to libp2p servers. It supports all four gRPC modes (Unary, Server Streaming, Client Streaming, Bidirectional Streaming). Version 0.0.42 is the current stable release; the project appears to be in early development with active commits. Key differentiators: browser-first (uses WebRTC, noise, yamux), protobuf-encoded messages, no dependency on gRPC-web or HTTP/2. Ideal for decentralized applications requiring secure, efficient P2P gRPC.

npm install grpc-libp2p-client
INSTALL
IMPORT
SIG · GRPC-LIBP2P-CLIENT
G
grpc-libp2p-client
messagingjavascriptv0.0.42
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Libp2pGrpcClient
import { Libp2pGrpcClient } from 'grpc-libp2p-client'
const Libp2pGrpcClient = require('grpc-libp2p-client')
ESM module; default export not available.
createLibp2p
import { createLibp2p } from 'libp2p'
import { createLibp2p } from 'grpc-libp2p-client'
libp2p is a peer dependency; not part of this package.
Libp2pGrpcClient type
import { Libp2pGrpcClient } from 'grpc-libp2p-client'
Types are included; can be used with TypeScript.

Create libp2p node with WebRTC, noise, yamux, then instantiate Libp2pGrpcClient and perform a unary call.

import { createLibp2p } from 'libp2p'; import { webRTC } from '@libp2p/webrtc'; import { noise } from '@chainsafe/libp2p-noise'; import { yamux } from '@chainsafe/libp2p-yamux'; import { Libp2pGrpcClient } from 'grpc-libp2p-client'; const node = await createLibp2p({ transports: [webRTC()], connectionEncryption: [noise()], streamMuxers: [yamux()] }); await node.start(); const serverPeerAddr = process.env.SERVER_PEER_ADDR ?? '/ip4/127.0.0.1/tcp/4006/p2p/12D3KooW...'; const serverProtocol = '/my-grpc-service/1.0.0'; const grpcClient = new Libp2pGrpcClient(node, serverPeerAddr, '', serverProtocol); console.log('gRPC client ready.'); const messageBytes = new Uint8Array([1,2,3]); try { const responseData = await grpcClient.unaryCall('/myservice.Service/MyMethod', messageBytes, 3000); console.log('Unary call successful:', responseData); } catch (error) { console.error('Unary call failed:', error); }
Debug
Known issues
gotchaMessage bytes must be protobuf-encoded using protobufjs or similar; the library does not handle serialization.
fix
Use a protobuf library like protobufjs to encode/decode messages manually before passing to libp2pGrpcClient methods.
affects: >=0.0.0
gotchaLibp2pGrpcClient constructor expects a libp2p node that is already started, or will start it? The example shows node.start() before client creation. Not starting the node may cause connection failures.
fix
Always start the libp2p node before calling new Libp2pGrpcClient() or ensure the client handles it (check docs).
affects: >=0.0.0
breakingThe version is 0.0.42, indicating pre-1.0 state; API may change without notice. Consider pinning exact version.
fix
Pin to exact version in package.json (e.g., "grpc-libp2p-client": "0.0.42") and review changelogs before upgrading.
affects: <1.0.0
gotchaThe unaryCall method returns a Promise<Uint8Array>; error handling must catch network or decoding errors.
fix
Wrap calls in try/catch and handle errors appropriately; responses are raw bytes.
affects: >=0.0.0
gotchaServer stream, client stream, and bidirectional calls use the generic Call method with mode strings ('server-streaming', 'client-streaming', 'bidi-streaming'). Typos in mode strings will fail silently or throw.
fix
Use exact mode strings: 'server-streaming', 'client-streaming', or 'bidi-streaming' (case-sensitive).
affects: >=0.0.0
Errors
Common errors & fixes
Error: Protocol not supported
The libp2p node does not have the correct transport (e.g., WebRTC) or connection encrypter (noise).
fix
Ensure the node is created with required transports and encryption: include webRTC and noise in config.
TypeError: node.peerId is undefined
The libp2p node has not been started before accessing its peerId.
fix
Call await node.start() before using node.peerId or passing node to Libp2pGrpcClient.
Error: Cannot find module 'grpc-libp2p-client'
Package not installed, or wrong import path in a CommonJS context.
fix
Install with npm install grpc-libp2p-client, and use ES module import syntax (type: "module" in package.json or .mjs extension).
Error: Method not found: /myservice.Service/MyMethod
The gRPC method path string does not match what the server expects.
fix
Double-check the method path format: it should be '/package.Service/Method' (case-sensitive).
Upgrade
Version history
0.0.42latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
18
Resources
grpc-libp2p-client — npm install grpc-libp2p-client · libregistry