Getting Started
Installation
Latest stable version: 2.2.3
# Install via NPM (You can use any wallet selector version you want)
npm install @wpdas/naxios @near-wallet-selector/modal-ui@8.9.13 --save
# Install via yarn (You can use any wallet selector version you want)
yarn add @wpdas/naxios @near-wallet-selector/modal-ui@8.9.13
Good to know: @near-wallet-selector/modal-ui need to be installed together because Naxios is integrated with NEAR Wallet Selector.
Preparing it
Import the NEAR Wallet Selector styles. The app needs it to render the Wallet Selector correctly.
import '@near-wallet-selector/modal-ui/styles.css'
Using It
It's super easy to get a Wallet, Contract, and RPC API in place all at once. Take a look:
import naxios from '@wpdas/naxios'
/**
* NEAR Wallet API
*/
const walletApi = new naxios({
rpcNodeUrl: 'https://free.rpc.fastnear.com', // optional
contractId: CONTRACT_ID,
network: 'testnet', // or mainnet, localnet
}).walletApi()
import naxios from '@wpdas/naxios'
/**
* NEAR Contract API
*/
const contractApi = new naxios({
rpcNodeUrl: 'https://free.rpc.fastnear.com', // optional
contractId: CONTRACT_ID,
network: 'testnet', // or mainnet, localnet
}).contractApi()
import naxios from '@wpdas/naxios'
/**
* NEAR RPC API
*/
const contractApi = new naxios({
rpcNodeUrl: 'https://free.rpc.fastnear.com', // optional
contractId: CONTRACT_ID,
network: 'testnet', // or mainnet, localnet
}).rpcApi()
import naxios from '@wpdas/naxios'
const naxiosInstance = new naxios({
rpcNodeUrl: 'https://free.rpc.fastnear.com', // optional
contractId: CONTRACT_ID,
network: 'testnet', // or mainnet, localnet
})
/**
* NEAR Wallet API (Must be a single instance)
*/
export const walletApi = naxiosInstance.walletApi()
// Examples of contract API instance usage
/**
* Contract API
* This is going to use default contractId (CONTRACT_ID)
*/
export const contractApi = naxiosInstance.contractApi()
/**
* Another Contract API
*/
export const socialDBcontractApi = naxiosInstance.contractApi({
contractId: 'v1.social08.testnet',
})
/**
* Greeting Contract API
*/
export const greetingContractApi = naxiosInstance.contractApi({
contractId: 'dev-1692221685438-15421910364142',
})
/**
* NEAR RPC API
*/
export const rpcApi = naxiosInstance.rpcApi()
Last updated