Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NEAR protocol near-js-api documentation on how to use the API

Tags:

nearprotocol

I'm working on a web app and want to have a login with near button to connect to the network through the web wallet, so my user can call contracts in the network. I have found the corgi example app hosted on https://corgis.near.org/, and this code looks like it is connecting to the web wallet: https://github.com/nearprotocol/corgis/blob/master/src/index.js#L13

async function InitContract() {
  const nearConfig = getConfig(process.env.NODE_ENV || "development");

  // Initializing connection to the NEAR
  const near = await nearlib.connect({
    deps: {
      keyStore: new nearlib.keyStores.BrowserLocalStorageKeyStore(),
    },
    ...nearConfig,
  });

  // Needed to access wallet
  const walletConnection = new nearlib.WalletConnection(near);

  // Load in account data
  let currentUser;
  if (walletConnection.getAccountId()) {
    currentUser = {
      accountId: walletConnection.getAccountId(),
      balance: (await walletConnection.account().state()).amount,
    };
  }

but I'm trying to find some documentation for the https://github.com/near/near-api-js library which provides a bit more insights on how things work, what are the options for example to connect to different networks (betanet, testnet, mainnet).

like image 209
chefsale Avatar asked Nov 18 '25 10:11

chefsale


1 Answers

I have found the documentation for the near-api-js: https://near.github.io/near-api-js/ which explains how to provide a chainId to the network which you want to connect: https://near.github.io/near-api-js/interfaces/_utils_network_.network.html.

like image 74
chefsale Avatar answered Nov 21 '25 10:11

chefsale



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!