Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xmtp/grpc-api-client

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xmtp/grpc-api-client

A GRPC-backed API client for Node.js applications

  • 0.2.8
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

GRPC API Client

Status

An API Client that satisfies the xmtp-js ApiClient interface, to be used in Node.js applications.

Features

  • Uses GRPC/Protobuf instead of HTTP/JSON for better performance
  • Uses the XMTP Subscribe2 endpoint to allow updating subscriptions without closing the connection
  • Configurable logger using pino

Usage

First, install the package in your project:

yarn add @xmtp/grpc-api-client
import { GrpcApiClient } from "@xmtp/grpc-api-client"
import { Client } from "@xmtp/xmtp-js"

const client = await Client.create(someWallet, {
  apiClientFactory: GrpcApiClient.fromOptions,
})

API Reference

subscribe(params: SubscribeParams, callback: SubscribeCallback, onConnectionLost: OnConnectionLostCallback): SubscriptionManager

This method is used to subscribe to a stream of new envelopes matching a predicate. It returns a SubscriptionManager which provides methods to unsubscribe and update content topics.

publish(messages: PublishParams[])`

This method is used to publish messages to the network. It takes an array of PublishParams as input.

query(params: QueryParams, options: QueryAllOptions): Promise<messageApi.Envelope[]>`

This method is used to query the store for messages. It returns a promise that resolves to an array of messageApi.Envelope.

Examples

Subscribing to a stream

let numEnvelopes = 0
const subscriptionManager = apiClient.subscribe(
  { contentTopics: [randomTopic] },
  () => {
    numEnvelopes++
  },
)

Publishing messages

await apiClient.publish([buildPublishParams({}), buildPublishParams({})])

Querying for messages

const results = await apiClient.query({ contentTopic: randomTopic }, {})

Please refer to the test files for more detailed examples and use cases

FAQs

Package last updated on 31 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc