Wallet API

Initializing

Instantiating the Wallet API.

// web3Api.ts

import naxios from '@wpdas/naxios'

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

/**
 * NEAR Wallet API (Must be a single instance)
 */
export const walletApi = naxiosInstance.walletApi()

API Reference

  • accounts: Signed-in Accounts.

  • accountId: Main/first signed-in account ID in the accounts list.

  • contractId: Contract ID.

  • initNear: Initializes a connection to the NEAR blockchain. This is called automatically when there's any contract interaction.

  • network: Current network (testnet, mainnet or localnet).

  • recentlySignedInWallets: Returns ID-s of 5 recently signed in wallets.

  • selectedWalletId: Selected Wallet Id

  • signInModal: Open up the Signin Wallet Modal.

  • wallet: Wallet instance.

  • walletSelector: WalletSelector instance.

Opening the Sign-in Wallet Selector Modal

You can open up the NEAR Wallet Selector modal by calling signInModal():

import { walletApi } from "./web3Api"

walletApi.signInModal();

Customizing the Wallets Options for NEAR Wallet Selector

By default, naxios only uses @near-wallet-selector/my-near-wallet as a means of connecting the wallet. However, you can add other wallet selectors as follows:

npm install @near-wallet-selector/ledger @near-wallet-selector/my-near-wallet

Then, you can start naxius as follows:

import naxios from '@wpdas/naxios'
import { setupMyNearWallet } from '@near-wallet-selector/my-near-wallet'
import { setupLedger } from '@near-wallet-selector/ledger'

const naxiosInstance = new naxios({
  contractId: CONTRACT_ID,
  network: 'testnet', // or mainnet, localnet
  walletSelectorModules: [
    setupMyNearWallet(),
    setupLedger(),
  ],
})

/**
 * NEAR Wallet API (Must be a single instance)
 */
export const walletApi = naxiosInstance.walletApi()

Find out all the NEAR wallet selectors here: NEAR Wallet Selector

Last updated