Last active
August 23, 2021 14:58
-
-
Save hiba-machfej/e81f838764f147d6885e39a6b996e668 to your computer and use it in GitHub Desktop.
near-login
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { keyStores, Near, utils, WalletConnection } from "near-api-js"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const CONTRACT_ID = "YOUR_CONTRACT_ID.testnet"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const near = new Near({ | |
networkId: "testnet", | |
keyStore: new keyStores.BrowserLocalStorageKeyStore(), | |
nodeUrl: "https://rpc.testnet.near.org", | |
walletUrl: "https://wallet.testnet.near.org", | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const wallet = new WalletConnection(near, "guest-book"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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