RPC API (Provider)

Initializing

Instantiating the RPC API. This is going to expose the NEAR Json RPC Provider service.

// web3Api.ts

import naxios from '@wpdas/naxios'

const naxiosInstance = new naxios({
  contractId: "hello.near-examples.near",
  network: 'mainnet', // or testnet, localnet
})

/**
 * NEAR RPC API
 */
export const rpcApi = naxiosInstance.rpcApi()

API Reference

All details about it and how to query data using it can be found on the original RPC API Docs website.

Here is a simple example of using this feature to view account details:

import { rpcApi } from './web3Api'

// Viewing account using Near RPC API
// https://docs.near.org/api/rpc/contracts#view-account
rpcApi
.query({
  request_type: 'view_account',
  finality: 'final',
  account_id: 'wendersonpires.near',
})
.then((data) => console.log('Account Data:', data))

Last updated