Installation

Learn how to get NEAR-API-JS running in your project

Requirements

  • Node.js v16^. Download Node.js.
  • Chrome/Firefox. NEAR-API-JS is designed to run in the browser, but it requires some Node.js polyfills. Website bundlers like Webpack5 and Vite have removed these polyfills to reduce default bundle size. Check 'Caveats' to see how to handle such cases.

Config

Caveats

If installing on a browser, make sure that the client environment has access to .global & Buffer. If not you will get errors in the browser console.

Set .global & Buffer in your index.js

  • JS
  • CDN

Firebase Functions

Due to missing browser polyfills 'near-api-js' will not be able to compose and URL and redirect the User to the wallet out of the box

// In Firebase Functions this will not work
nearAPI.requestSignIn()

The methods that redirect to the NEAR Waller are meant for Browser Usage However, if you need to get the redirect URL as a string, please refer to our RPC Login Documentation

Configuring Endpoints

You should create a function like this to switch the configuration between development and production environment

  • JS
  • Node JS

Creating an API client

  • JS
  • Node JS
  • CDN

Learn more

NEAR Features

Official 'near-api-js' Documentation