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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@saka-labs/near-jsonrpc-types

v0.7.0

Published

TypeScript types and schemas for NEAR JSON-RPC API.

Downloads

12

Readme

@saka-labs/near-jsonrpc-types

TypeScript types and schemas for NEAR JSON-RPC API.

Installation

npm install @saka-labs/near-jsonrpc-types

Usage

Import Types

import type {
  AccountView,
  AccountId,
  ValidatorStakeView,
  BlockHeaderView,
  ExecutionOutcomeView,
  RpcBlockRequest,
  RpcBlockResponse,
  RpcQueryRequest,
  RpcQueryResponse,
} from "@saka-labs/near-jsonrpc-types";

Import Method Definitions

import {
  query,
  queryViewAccount,
  queryCallFunction,
  queryViewCode,
  block,
  status,
  validators,
  broadcastTxCommit,
  gasPrice,
  health,
  networkInfo,
  EXPERIMENTALProtocolConfig,
} from "@saka-labs/near-jsonrpc-types/methods";

const transporter = jsonRpcTransporter({
  endpoint: "https://rpc.testnet.near.org",
});

// Client with only specific methods
const client = createClientWithMethods({
  transporter,
  methods: { block, status, query, queryViewAccount, queryCallFunction },
  runtimeValidation: true,
});

const result - client.query({
  request_type: "view_account",
  account_id: "example.near",
  finality: "final",
})

Import TypeScript Types and Schemas

// TypeScript type definitions
import type {
  AccountView,
  ValidatorStakeView,
  BlockHeaderView,
} from "@saka-labs/near-jsonrpc-types/schemas";

Import Zod Validation Schemas

// Runtime validation schemas
import {
  AccountViewSchema,
  ValidatorStakeViewSchema,
  BlockHeaderViewSchema,
  RpcBlockRequestSchema,
  RpcBlockResponseSchema,
} from "@saka-labs/near-jsonrpc-types/zod-schemas";

// Validate API responses at runtime
const account = AccountViewSchema.parse(response);
const blockRequest = RpcBlockRequestSchema.parse(userInput);

Import Property Mappings

import { mappedSnakeCamelProperty } from "@saka-labs/near-jsonrpc-types/mapped-properties";

// Convert between snake_case and camelCase property names
const camelCase = mappedSnakeCamelProperty.get("account_id"); // "accountId"

Import Discriminator Helpers

import {
  DiscriminateRpcQueryResponse,
  DiscriminateRpcTransactionResponse,
} from "@saka-labs/near-jsonrpc-types";

// Type-safe discrimination of union response types
const { result } = await client.queryViewAccount({
  accountId: "example.near",
  syncCheckpoint: "earliest_available",
});

const discriminated = DiscriminateRpcQueryResponse(result);
if (discriminated.AccountView) {
  // TypeScript knows this is AccountView type
  console.log(`Balance: ${discriminated.AccountView.amount}`);
  console.log(`Storage: ${discriminated.AccountView.storageUsage}`);
} else if (discriminated.CallResult) {
  // TypeScript knows this is CallResult type
  console.log(`Result: ${discriminated.CallResult.result}`);
}

Available Exports

  • /methods - JSON-RPC method definitions with type parameters and validation schemas
  • /schemas - TypeScript type definitions for all NEAR JSON-RPC types
  • /zod-schemas - Runtime Zod validation schemas for type checking and parsing
  • /mapped-properties - Property name conversion mappings between snake_case and camelCase
  • Main export - Discriminator helper functions for type-safe union response handling

Available Methods

The package includes all NEAR JSON-RPC methods:

Core Methods:

  • block - Get block information
  • query - Query account/contract state (generic method)
  • status - Get node status
  • validators - Get current validators
  • gasPrice - Get current gas price
  • health - Check node health
  • networkInfo - Get network information

Query Methods (Discriminated):

  • queryViewAccount - Query account information
  • queryViewCode - Query contract code
  • queryCallFunction - Call a view function
  • queryViewAccessKey - Query access key information
  • queryViewAccessKeyList - Query all access keys for an account
  • queryViewState - Query contract state
  • queryViewGlobalContractCode - Query global contract code
  • queryViewGlobalContractCodeByAccountId - Query global contract code by account

Transaction Methods:

  • broadcastTxAsync - Broadcast transaction asynchronously
  • broadcastTxCommit - Broadcast transaction and wait for commit
  • sendTx - Send transaction
  • tx - Get transaction status

Advanced Methods:

  • chunk - Get chunk information
  • changes - Get state changes (generic method)
  • lightClientProof - Get light client proof
  • nextLightClientBlock - Get next light client block

Changes Methods (Discriminated):

  • changesAccountChanges - Get account changes
  • changesSingleAccessKeyChanges - Get single access key changes
  • changesSingleGasKeyChanges - Get single gas key changes
  • changesAllAccessKeyChanges - Get all access key changes
  • changesAllGasKeyChanges - Get all gas key changes
  • changesContractCodeChanges - Get contract code changes
  • changesDataChanges - Get data changes

Experimental Methods:

  • EXPERIMENTALProtocolConfig - Get protocol configuration
  • EXPERIMENTALValidatorsOrdered - Get validators in order
  • EXPERIMENTALReceipt - Get receipt information
  • EXPERIMENTALTxStatus - Get transaction status
  • EXPERIMENTALChanges - Get state changes
  • EXPERIMENTALChangesInBlock - Get changes in block
  • And more...

For complete method details, parameter types, and response schemas, see /methods.

Features

  • Complete TypeScript coverage of NEAR JSON-RPC API
  • Discriminated method definitions for better type safety and developer experience
  • Discriminator helper functions for type-safe union response handling
  • Runtime validation with Zod schemas
  • Tree-shakeable - import only what you need
  • Auto-generated from OpenAPI specification
  • Type-safe method definitions with request/response validation
  • Property name conversion utilities
  • Support for all NEAR JSON-RPC methods including experimental ones
  • Automatic discriminator property handling (requestType, changesType, etc.)

Related

License

MIT