Skip to main content

Getting Started


The Gear-JS API offers a set of utilities, libraries, and tools that enable JavaScript applications to interact with programs running on the Vara network via queries to a Vara node.

The sections below describe tools for implementing basic functions in a JS application, such as managing key pairs (accounts), calculating gas required for network operations, uploading programs to the network, sending messages to programs, reading program states, retrieving messages from the user's mailbox, working with metadata, and more. Useful code snippets are provided in the Cookbook section.

The basic API is implemented on the Substrate layer and is consistent across all Substrate-based networks. The Gear-JS API code is available on GitHub. A complete API overview can be found on the Polkadot documentation portal.


Since Vara and Vara Testnet can have different runtime versions, they may have different extrinsic signatures. When operating on the Vara Network, using the VaraApi class is more convenient than GearApi, and VaraTestnetApi is recommended for the Vara Testnet Network.


Install the Gear-JS API using npm:

npm install @gear-js/api

or using yarn:

yarn add @gear-js/api

Getting Started

Start the API connection to the local running RPC node:

import { GearApi } from '@gear-js/api';

const gearApi = await GearApi.create();

Connect to a different node:

const gearApi = await GearApi.create({
providerAddress: 'ws[s]://someIP[:somePort]',

Below are a few entry points for interacting with the Vara RPC Node.

For connection to the local node, use:


For connection to the Vara Network Testnet, use:


Retrieve node information:

const chain = await gearApi.chain();
const nodeName = await gearApi.nodeName();
const nodeVersion = await gearApi.nodeVersion();
const genesis = gearApi.genesisHash.toHex();


This simple example demonstrates how to subscribe to new blocks and get chain specifications:

async function connect() {
const gearApi = await GearApi.create({
providerAddress: 'wss://',

const [chain, nodeName, nodeVersion] = await Promise.all([

`Connected to chain ${chain} using ${nodeName} v${nodeVersion}`,

const unsub = await gearApi.gearEvents.subscribeToNewBlocks((header) => {
`New block with number: ${header.number.toNumber()} and hash: ${header.hash.toHex()}`,


Refer to the NFT Marketplace example for a demonstration of creating a React application that connects to an NFT smart contract running on the blockchain.