Sign-in & sign-out with NearFi

Request NearFi user wallet to sign-in your application

Signing in

Once NearFi wallet object is available (see here), it is recommended for applications to request approval from users to sign-in the applications. Example code to request sign-in:

//request permission to call any function of your contract application 
const signInResponse = await window.nearFiWallet.requestSignIn({
  contractId: "your-contract-id", // the contract Id of your application
});
if (signInResponse.error) {
  console.log("failed to sign-in")
} else {
  console.log("sign-in success")
}

//you can also use promise to request
window.nearFiWallet.requestSignin({
  contractId: "your-contract-id", // the contract Id of your application
}).then(signInResponse => {})

// Or add `methodNames` if your contract application only needs permission for some of the methods
await window.nearFiWallet.requestSignIn({
  contractId: "your-contract-id", // the contract Id of your application
  methodNames: ["method1", "method2"]       // (optional) changed methods the app allowed to use
});

The response of requestSignIn function also has an access key information. More details on the response can be found here. Once successfully signed in, function window.nearFiWallet.isSignedIn() will return true.

Signing out

API signOut serve the function of singing out when a user wants to disconnect the wallet from the applications.

await window.nearFiWallet.signOut();

Last updated