Skip to main content

Welcome to NEAR API TypeScript

NEAR API TypeScript is a modern, type-safe library for building applications on the NEAR Protocol blockchain. Built from the ground up with TypeScript, it provides a robust and developer-friendly interface for interacting with NEAR Protocol in both browser and Node.js environments.

Key Features

Type-Safe

Full TypeScript support with comprehensive type definitions for all API methods

Multi-Platform

Works seamlessly in browser, Node.js, and universal environments

Flexible Error Handling

Choose between safe (Result-based) and throwable API variants

Key Management

Built-in key services with support for memory, file, and IndexedDB storage

Transaction Building

Comprehensive transaction builder with action creators

Native Token Support

First-class support for NEAR tokens and gas units with type-safe helpers

Why NEAR API TypeScript?

Modern TypeScript-First Design

Built with modern TypeScript practices, providing excellent IDE support, autocompletion, and compile-time type checking. Every function and type is fully documented with JSDoc comments.

Flexible Error Handling

Choose the error handling approach that fits your needs:
  • Throwable variants: Standard async functions that throw errors
  • Safe variants: Return Result<T, E> objects for functional error handling

Multi-Platform Support

Write once, run anywhere. The library automatically detects your environment and uses the appropriate implementation:
  • Universal: Core functionality that works everywhere
  • Browser: Browser-specific features like IndexedDB key storage
  • Node.js: Node-specific features like file-based key storage

Quick Example

import {
  createTestnetClient,
  createMemoryKeyService,
  createMemorySigner,
  transfer,
  near,
} from 'near-api-ts';

// Create a client
const client = createTestnetClient();

// Query account information
const { accountInfo } = await client.getAccountInfo({
  accountId: 'testnet',
  atMomentOf: 'LatestFinalBlock',
});

console.log('Balance:', accountInfo.balance.total.near);

// Set up signing with a key service
const keyService = createMemoryKeyService({
  keySource: { privateKey: 'ed25519:your-private-key' },
});

const signer = createMemorySigner({
  signerAccountId: 'your-account.testnet',
  client,
  keyService,
});

// Send a transaction
await signer.executeTransaction({
  intent: {
    action: transfer({ amount: near('1') }),
    receiverAccountId: 'receiver.testnet',
  },
});

Next Steps

Community and Support