npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@psalomo/jsonrpc-client

v1.3.1

Published

TypeScript client for NEAR Protocol JSON-RPC API

Readme

@near-js/jsonrpc-client

This package provides a fully-typed, dynamic client for the NEAR Protocol JSON-RPC API. All methods and types are automatically generated from the official OpenAPI specification.

Installation

npm install @near-js/jsonrpc-client

Usage

Create a new client instance and use the available RPC functions:

import { NearRpcClient, status } from '@near-js/jsonrpc-client';

const client = new NearRpcClient({
  endpoint: 'https://rpc.mainnet.near.org',
});

async function getNetworkStatus() {
  const result = await status(client);
  console.log('Network status:', result);
}

getNetworkStatus();

Handling Responses

All method calls return a promise that resolves to a fully typed result object based on the JSON-RPC API specification.

import { NearRpcClient, block } from '@near-js/jsonrpc-client';

const client = new NearRpcClient({
  endpoint: 'https://rpc.mainnet.near.org',
});

async function getLatestBlock() {
  const result = await block(client, { finality: 'final' });
  console.log('Latest block height:', result.header?.height);
}

getLatestBlock();

Convenience Methods

The client includes convenience methods for common query operations:

import { viewAccount, viewFunction, viewAccessKey } from '@near-js/jsonrpc-client';

// View account information
const account = await viewAccount(client, {
  accountId: 'example.near',
  finality: 'final',
});
console.log('Account balance:', account.amount);
console.log('Storage used:', account.storageUsage);

// Call view functions
const result = await viewFunction(client, {
  accountId: 'contract.near',
  methodName: 'get_balance',
  finality: 'final',
});

// View access keys
const accessKey = await viewAccessKey(client, {
  accountId: 'example.near',
  publicKey: 'ed25519:...',
  finality: 'final',
});

JSON Parsing Utilities

Many NEAR contracts return JSON data as byte arrays. We provide convenient utilities to parse these:

import { viewFunction, viewFunctionAsJson, parseCallResultToJson } from '@near-js/jsonrpc-client';

// Manual parsing
const result = await viewFunction(client, {
  accountId: 'contract.near',
  methodName: 'get_status',
});
const data = parseCallResultToJson(result); // Converts byte array to JSON

// Or use the convenience function that does both
const data = await viewFunctionAsJson(client, {
  accountId: 'contract.near', 
  methodName: 'get_status',
});

// With TypeScript types
interface Status {
  version: string;
  uptime: number;
}
const status = await viewFunctionAsJson<Status>(client, {
  accountId: 'contract.near',
  methodName: 'get_status',
});
console.log(status.version); // Fully typed!

Runtime Validation

The client supports runtime validation using Zod schemas to ensure both request parameters and server responses conform to the NEAR RPC specification.

Default Usage (With Validation)

By default, all functions include validation for maximum safety:

import { NearRpcClient, status, block } from '@near-js/jsonrpc-client';

// Just create a client - validation is built into the functions
const client = new NearRpcClient({
  endpoint: 'https://rpc.mainnet.near.org',
});

// Request parameters are validated before sending
try {
  await block(client, { blockId: 'invalid' }); // ❌ Throws validation error
  await block(client, { finality: 'final' }); // ✅ Valid parameters
} catch (error) {
  console.error('Validation error:', error.message);
  // "Invalid block request: Expected finality or block_id"
}

// Server responses are also validated
const result = await status(client);
// You can trust that 'result' matches the expected schema

Minimal Bundle Size (No Validation)

For applications where bundle size is critical, use the /no-validation export:

import { NearRpcClient, status, block } from '@near-js/jsonrpc-client/no-validation';

// Same API, but no runtime validation
const client = new NearRpcClient({
  endpoint: 'https://rpc.mainnet.near.org'
});

// No validation = smaller bundle size
await block(client, { finality: 'final' });

Bundle Size Comparison

The new validation approach uses per-function schema imports for optimal tree-shaking:

  • With validation: ~60KB for 2 functions (only includes schemas for used functions)
  • No validation: ~7KB (no Zod schemas included)
  • Old approach: ~150KB+ (included all schemas even for unused functions)

Benefits of Validation

  • Request Safety: Catch parameter errors before making network requests
  • Response Integrity: Ensure server responses match the expected schema
  • Better Error Messages: Get clear, descriptive errors instead of cryptic failures
  • Development Speed: Find API usage mistakes immediately during development
  • Runtime Protection: Guard against malformed or unexpected server responses
  • Optimal Tree-Shaking: Only pay for validation of functions you actually use

Features

  • 🔧 Dynamic methods: All 28+ RPC methods automatically available
  • 📝 Fully typed: Complete TypeScript support with proper request/response types
  • 🔄 Auto-updating: New API methods appear automatically without code changes
  • ✅ Runtime validation: Validates both request parameters and server responses
  • 🎯 Convenience methods: Simplified methods for common operations like viewAccount
  • 🌳 Tree-shakable: Validation is modular - only included when used