# @cosmjs/json-rpc Agent Guide

> **Package**: `@cosmjs/json-rpc` v0.38.0 **Purpose**: JSON-RPC 2.0 protocol
> implementation **Layer**: Transport Layer

## Package Overview

Implements JSON-RPC 2.0 protocol for RPC communication. Used by
`@cosmjs/tendermint-rpc` for HTTP and WebSocket RPC calls.

### Key Features

- **JSON-RPC 2.0**: Full spec compliance
- **Request/Response**: Standard RPC pattern
- **Batch Requests**: Multiple requests in one call
- **Error Handling**: Typed error responses

## Types

```typescript
interface JsonRpcRequest {
  readonly jsonrpc: "2.0";
  readonly id: string | number;
  readonly method: string;
  readonly params?: any;
}

interface JsonRpcSuccess {
  readonly jsonrpc: "2.0";
  readonly id: string | number;
  readonly result: any;
}

interface JsonRpcError {
  readonly jsonrpc: "2.0";
  readonly id: string | number;
  readonly error: {
    readonly code: number;
    readonly message: string;
    readonly data?: any;
  };
}
```

## Common Usage

```typescript
import { parseJsonRpcResponse, isJsonRpcErrorResponse } from "@cosmjs/json-rpc";

// Parse response
const response = parseJsonRpcResponse(jsonString);

if (isJsonRpcErrorResponse(response)) {
  console.error("RPC error:", response.error);
} else {
  console.log("Result:", response.result);
}
```

---

**Last Updated**: January 6, 2026 **Package Version**: 0.38.0


