
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@near-js/jsonrpc-client
Advanced tools
@near-js/jsonrpc-clientThis 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.
npm install @near-js/jsonrpc-client
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();
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();
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',
});
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!
The client supports runtime validation using Zod schemas to ensure both request parameters and server responses conform to the NEAR RPC specification.
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
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' });
The new validation approach uses per-function schema imports for optimal tree-shaking:
viewAccountFAQs
TypeScript client for NEAR Protocol JSON-RPC API
The npm package @near-js/jsonrpc-client receives a total of 58 weekly downloads. As such, @near-js/jsonrpc-client popularity was classified as not popular.
We found that @near-js/jsonrpc-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.