Skip to content

near/near-jsonrpc-client-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

86 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

NEAR Protocol TypeScript RPC Client

CI codecov

An automated, type-safe TypeScript client for NEAR Protocol's JSON-RPC API, generated from the official OpenAPI specification.

πŸ“¦ Packages

This monorepo contains two packages:

πŸš€ Quick Start

Installation

npm install @near-js/jsonrpc-client

Node.js (Vanilla)

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

const client = new NearRpcClient({
  endpoint: 'https://rpc.testnet.fastnear.com',
});
const blockResult = await block(client, { finality: 'final' });
console.log('Latest block height:', blockResult.header.height);

Bundlers (React, Vue, Angular, etc.)

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

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

// Fully typed method calls
const blockResult = await block(client, { finality: 'final' });
const account = await viewAccount(client, {
  accountId: 'example.near',
  finality: 'final',
});

Browser (Vanilla HTML)

<script type="module">
  const { NearRpcClient, block } = await import(
    'https://unpkg.com/@near-js/jsonrpc-client@latest/dist/browser-standalone.min.js'
  );
  const client = new NearRpcClient({
    endpoint: 'https://rpc.mainnet.near.org',
  });
  const blockResult = await block(client, { finality: 'final' });
  console.log('Latest block height:', blockResult.header.height);
</script>

Browser Console (One-liner)

Paste this directly into any browser's developer console on any webpage:

const { NearRpcClient, block } = await import(
  'https://unpkg.com/@near-js/jsonrpc-client@latest/dist/browser-standalone.min.js'
);
const client = new NearRpcClient({ endpoint: 'https://rpc.mainnet.near.org' });
const blockResult = await block(client, { finality: 'final' });
console.log('Latest block height:', blockResult.header.height);

✨ Features

  • πŸ”§ Auto-generated from NEAR's official OpenAPI specification
  • πŸ“ Fully typed with TypeScript strict mode
  • βœ… Runtime validation with Zod schemas
  • πŸ”„ Automatic updates via GitHub Actions
  • 🌳 Tree-shakable for optimal bundle size
  • πŸš€ Modern fetch-based HTTP client
  • 🌐 Browser compatible with standalone bundle
  • πŸ“¦ CDN ready for instant usage anywhere
  • πŸ§ͺ Well tested with 80%+ coverage

πŸ—οΈ Development

This project uses pnpm workspaces and requires Node.js 20+.

# Install dependencies
pnpm install

# Build all packages
pnpm build

# Run tests
pnpm test

# Lint code
pnpm lint

# Generate types from OpenAPI spec
pnpm generate

πŸ§ͺ Testing

This project uses Vitest for testing. You can run tests for the entire project or for individual packages.

Running All Tests

To run all tests for both packages, use the following command from the root of the project:

# Run all tests in watch mode
pnpm -r test:watch

# Run all tests once (avoiding watch mode)
pnpm test

Note: The root pnpm test command is an alias for pnpm -r test.

Running Tests for a Specific Package

To run tests for a specific package, use the --filter flag with the package name:

# Run tests for the types package once
pnpm --filter @near-js/jsonrpc-types test

# Run tests for the client package in watch mode
pnpm --filter @near-js/jsonrpc-client test:watch

Coverage

To generate a coverage report, add the --coverage flag to the test command:

# Generate coverage for all packages
pnpm -r test:coverage

# Generate coverage for a specific package
pnpm --filter @near-js/jsonrpc-client test:coverage

πŸ€– Automation

The project includes GitHub Actions workflows for:

  • CI/CD: Testing, linting, and building on every PR
  • Auto-updates: Daily checks for OpenAPI spec changes
  • Coverage: Automated test coverage reporting

πŸ“„ License

MIT - see LICENSE file for details.

🀝 Contributing

Contributions are welcome! Please read our Contributing Guide for details.


This is an open source implementation being developed as a proposal for the NEAR DevHub bounty.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •