@xmtp/grpc-api-client
TypeScript icon, indicating that this package has built-in type declarations

0.2.7 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @xmtp/grpc-api-client

Weekly Downloads

105

Version

0.2.7

License

MIT

Unpacked Size

652 kB

Total Files

36

Last publish

Collaborators

  • alexxmtp
  • fabriguespe
  • nplasterer-xmtp
  • saul-xmtp
  • nick-xmtp
  • xmtp-eng-robot
  • galligan