Skip to content

Instantly share code, notes, and snippets.

@hiba-machfej
Last active August 23, 2021 14:58
Show Gist options
  • Save hiba-machfej/e81f838764f147d6885e39a6b996e668 to your computer and use it in GitHub Desktop.
Save hiba-machfej/e81f838764f147d6885e39a6b996e668 to your computer and use it in GitHub Desktop.
near-login
import { keyStores, Near, utils, WalletConnection } from "near-api-js";
export const CONTRACT_ID = "YOUR_CONTRACT_ID.testnet";
export const near = new Near({
networkId: "testnet",
keyStore: new keyStores.BrowserLocalStorageKeyStore(),
nodeUrl: "https://rpc.testnet.near.org",
walletUrl: "https://wallet.testnet.near.org",
});
export const wallet = new WalletConnection(near, "guest-book");
const accountId = wallet.getAccountId();
const signIn = () => {
if (accountId) {
wallet.signOut();
window.location.reload();
} else {
wallet.requestSignIn(CONTRACT_ID);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment