Reputation: 326
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).
Upvotes: 3
Views: 350
Reputation: 326
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.
Upvotes: 1