> ## Documentation Index
> Fetch the complete documentation index at: https://cosmos-docs-cosmjs-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# @cosmjs/tendermint-rpc

> Tendermint/CometBFT RPC client for HTTP and WebSocket

Low-level RPC client for communicating with Tendermint/CometBFT nodes. Supports HTTP and WebSocket transports, and auto-detects the node version.

```bash theme={"system"}
npm install @cosmjs/tendermint-rpc
```

## connectComet

Auto-detects the CometBFT/Tendermint version and returns the appropriate client.

```typescript theme={"system"}
function connectComet(endpoint: string | HttpEndpoint): Promise<CometClient>
```

```typescript theme={"system"}
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:

| Method              | Parameters                                 | Returns                              |
| ------------------- | ------------------------------------------ | ------------------------------------ |
| `status`            | —                                          | `Promise<StatusResponse>`            |
| `block`             | `height?: number`                          | `Promise<BlockResponse>`             |
| `blockResults`      | `height?: number`                          | `Promise<BlockResultsResponse>`      |
| `blockchain`        | `minHeight?: number`, `maxHeight?: number` | `Promise<BlockchainResponse>`        |
| `tx`                | `params: TxParams`                         | `Promise<TxResponse>`                |
| `txSearch`          | `params: TxSearchParams`                   | `Promise<TxSearchResponse>`          |
| `validators`        | `params: ValidatorsParams`                 | `Promise<ValidatorsResponse>`        |
| `broadcastTxSync`   | `params: BroadcastTxParams`                | `Promise<BroadcastTxSyncResponse>`   |
| `broadcastTxAsync`  | `params: BroadcastTxParams`                | `Promise<BroadcastTxAsyncResponse>`  |
| `broadcastTxCommit` | `params: BroadcastTxParams`                | `Promise<BroadcastTxCommitResponse>` |
| `abciQuery`         | `params: AbciQueryParams`                  | `Promise<AbciQueryResponse>`         |
| `disconnect`        | —                                          | `void`                               |

## Version-Specific Clients

### Tendermint37Client

For Tendermint 0.37 nodes.

| Method             | Parameters                         | Returns                       |
| ------------------ | ---------------------------------- | ----------------------------- |
| `connect` (static) | `endpoint: string \| HttpEndpoint` | `Promise<Tendermint37Client>` |
| `create` (static)  | `rpcClient: RpcClient`             | `Tendermint37Client`          |

### Comet38Client

For CometBFT 0.38 nodes.

| Method             | Parameters                         | Returns                  |
| ------------------ | ---------------------------------- | ------------------------ |
| `connect` (static) | `endpoint: string \| HttpEndpoint` | `Promise<Comet38Client>` |
| `create` (static)  | `rpcClient: RpcClient`             | `Comet38Client`          |

### Comet1Client

For CometBFT 1.x nodes.

| Method             | Parameters                         | Returns                 |
| ------------------ | ---------------------------------- | ----------------------- |
| `connect` (static) | `endpoint: string \| HttpEndpoint` | `Promise<Comet1Client>` |
| `create` (static)  | `rpcClient: RpcClient`             | `Comet1Client`          |

## Type Guards

| Function               | Parameters            | Returns                        |
| ---------------------- | --------------------- | ------------------------------ |
| `isTendermint37Client` | `client: CometClient` | `client is Tendermint37Client` |
| `isComet38Client`      | `client: CometClient` | `client is Comet38Client`      |
| `isComet1Client`       | `client: CometClient` | `client 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.

| Method        | Parameters                                             | Returns                           |
| ------------- | ------------------------------------------------------ | --------------------------------- |
| `constructor` | `endpoint: string \| HttpEndpoint`, `timeout?: number` | `HttpClient`                      |
| `execute`     | `request: JsonRpcRequest`                              | `Promise<JsonRpcSuccessResponse>` |
| `disconnect`  | —                                                      | `void`                            |

### HttpBatchClient

Batches multiple RPC requests into a single HTTP call.

| Method        | Parameters                                                                      | Returns                           |
| ------------- | ------------------------------------------------------------------------------- | --------------------------------- |
| `constructor` | `endpoint: string \| HttpEndpoint`, `options?: Partial<HttpBatchClientOptions>` | `HttpBatchClient`                 |
| `execute`     | `request: JsonRpcRequest`                                                       | `Promise<JsonRpcSuccessResponse>` |
| `disconnect`  | —                                                                               | `void`                            |

```typescript theme={"system"}
interface HttpBatchClientOptions {
  dispatchInterval: number;
  batchSizeLimit: number;
  httpTimeout?: number;
}
```

### WebsocketClient

WebSocket client for streaming subscriptions.

| Method        | Parameters                                         | Returns                                                 |
| ------------- | -------------------------------------------------- | ------------------------------------------------------- |
| `constructor` | `endpoint: string`, `onError?: (err: any) => void` | `WebsocketClient`                                       |
| `execute`     | `request: JsonRpcRequest`                          | `Promise<JsonRpcSuccessResponse>`                       |
| `listen`      | `request: JsonRpcRequest`                          | `Stream<SubscriptionEvent>`                             |
| `connected`   | —                                                  | `Promise<void>` (resolves when the socket is connected) |
| `disconnect`  | —                                                  | `void`                                                  |

## Key Types

### HttpEndpoint

```typescript theme={"system"}
interface HttpEndpoint {
  readonly url: string;
  readonly headers: Record<string, string>;
}
```

### RpcClient

```typescript theme={"system"}
interface RpcClient {
  readonly execute: (request: JsonRpcRequest) => Promise<JsonRpcSuccessResponse>;
  readonly disconnect: () => void;
}
```

### BlockIdFlag

```typescript theme={"system"}
enum BlockIdFlag {
  Unknown = 0,
  Absent = 1,
  Commit = 2,
  Nil = 3,
  Unrecognized = -1,
}
```

## Date Utilities

| Function                     | Parameters                          | Returns                              |
| ---------------------------- | ----------------------------------- | ------------------------------------ |
| `fromRfc3339WithNanoseconds` | `str: string`                       | `DateWithNanoseconds`                |
| `toRfc3339WithNanoseconds`   | `date: ReadonlyDateWithNanoseconds` | `string`                             |
| `fromSeconds`                | `seconds: number`, `nanos?: number` | `DateWithNanoseconds`                |
| `toSeconds`                  | `date: ReadonlyDateWithNanoseconds` | `{ seconds: number; nanos: number }` |

## Address Utilities

| Function                         | Parameters                                           | Returns      |
| -------------------------------- | ---------------------------------------------------- | ------------ |
| `pubkeyToAddress`                | `type: "ed25519" \| "secp256k1"`, `data: Uint8Array` | `string`     |
| `pubkeyToRawAddress`             | `type: "ed25519" \| "secp256k1"`, `data: Uint8Array` | `Uint8Array` |
| `rawSecp256k1PubkeyToRawAddress` | `pubkeyData: Uint8Array`                             | `Uint8Array` |
| `rawEd25519PubkeyToRawAddress`   | `pubkeyData: Uint8Array`                             | `Uint8Array` |
