Skip to main content
Low-level RPC client for communicating with Tendermint/CometBFT nodes. Supports HTTP and WebSocket transports, and auto-detects the node version.
npm install @cosmjs/tendermint-rpc

connectComet

Auto-detects the CometBFT/Tendermint version and returns the appropriate client.
function connectComet(endpoint: string | HttpEndpoint): Promise<CometClient>
import { connectComet } from "@cosmjs/tendermint-rpc";

const client = await connectComet("https://rpc.my-chain.network");
const status = await client.status();

CometClient

CometClient is a union type of all version-specific clients: Tendermint37Client | Comet38Client | Comet1Client. They share these methods:
MethodParametersReturns
statusPromise<StatusResponse>
blockheight?: numberPromise<BlockResponse>
blockResultsheight?: numberPromise<BlockResultsResponse>
blockchainminHeight?: number, maxHeight?: numberPromise<BlockchainResponse>
txparams: TxParamsPromise<TxResponse>
txSearchparams: TxSearchParamsPromise<TxSearchResponse>
validatorsparams: ValidatorsParamsPromise<ValidatorsResponse>
broadcastTxSyncparams: BroadcastTxParamsPromise<BroadcastTxSyncResponse>
broadcastTxAsyncparams: BroadcastTxParamsPromise<BroadcastTxAsyncResponse>
broadcastTxCommitparams: BroadcastTxParamsPromise<BroadcastTxCommitResponse>
abciQueryparams: AbciQueryParamsPromise<AbciQueryResponse>
disconnectvoid

Version-Specific Clients

Tendermint37Client

For Tendermint 0.37 nodes.
MethodParametersReturns
connect (static)endpoint: string | HttpEndpointPromise<Tendermint37Client>
create (static)rpcClient: RpcClientTendermint37Client

Comet38Client

For CometBFT 0.38 nodes.
MethodParametersReturns
connect (static)endpoint: string | HttpEndpointPromise<Comet38Client>
create (static)rpcClient: RpcClientComet38Client

Comet1Client

For CometBFT 1.x nodes.
MethodParametersReturns
connect (static)endpoint: string | HttpEndpointPromise<Comet1Client>
create (static)rpcClient: RpcClientComet1Client

Type Guards

FunctionParametersReturns
isTendermint37Clientclient: CometClientclient is Tendermint37Client
isComet38Clientclient: CometClientclient is Comet38Client
isComet1Clientclient: CometClientclient is Comet1Client
These are TypeScript type predicates, so the compiler narrows the client type in the branch where the guard returns true.

RPC Clients

Low-level HTTP and WebSocket implementations.

HttpClient

Standard HTTP client for request/response RPC.
MethodParametersReturns
constructorendpoint: string | HttpEndpoint, timeout?: numberHttpClient
executerequest: JsonRpcRequestPromise<JsonRpcSuccessResponse>
disconnectvoid

HttpBatchClient

Batches multiple RPC requests into a single HTTP call.
MethodParametersReturns
constructorendpoint: string | HttpEndpoint, options?: Partial<HttpBatchClientOptions>HttpBatchClient
executerequest: JsonRpcRequestPromise<JsonRpcSuccessResponse>
disconnectvoid
interface HttpBatchClientOptions {
  dispatchInterval: number;
  batchSizeLimit: number;
  httpTimeout?: number;
}

WebsocketClient

WebSocket client for streaming subscriptions.
MethodParametersReturns
constructorendpoint: string, onError?: (err: any) => voidWebsocketClient
executerequest: JsonRpcRequestPromise<JsonRpcSuccessResponse>
listenrequest: JsonRpcRequestStream<SubscriptionEvent>
connectedPromise<void> (resolves when the socket is connected)
disconnectvoid

Key Types

HttpEndpoint

interface HttpEndpoint {
  readonly url: string;
  readonly headers: Record<string, string>;
}

RpcClient

interface RpcClient {
  readonly execute: (request: JsonRpcRequest) => Promise<JsonRpcSuccessResponse>;
  readonly disconnect: () => void;
}

BlockIdFlag

enum BlockIdFlag {
  Unknown = 0,
  Absent = 1,
  Commit = 2,
  Nil = 3,
  Unrecognized = -1,
}

Date Utilities

FunctionParametersReturns
fromRfc3339WithNanosecondsstr: stringDateWithNanoseconds
toRfc3339WithNanosecondsdate: ReadonlyDateWithNanosecondsstring
fromSecondsseconds: number, nanos?: numberDateWithNanoseconds
toSecondsdate: ReadonlyDateWithNanoseconds{ seconds: number; nanos: number }

Address Utilities

FunctionParametersReturns
pubkeyToAddresstype: "ed25519" | "secp256k1", data: Uint8Arraystring
pubkeyToRawAddresstype: "ed25519" | "secp256k1", data: Uint8ArrayUint8Array
rawSecp256k1PubkeyToRawAddresspubkeyData: Uint8ArrayUint8Array
rawEd25519PubkeyToRawAddresspubkeyData: Uint8ArrayUint8Array