Login
The following sample will show you how to make a simple connection handler. First, we will generate a QR Code that will be the entry point by which users can interact with your dApp. Once this QR Code is scanned and operation authorized, the account details are forwarded to you.
Prerequisites:
Getting startedStep 1: Import the following modules
Continue building on the index.js from the previous example (Environment Set-up) and add the following modules:
const { Client, UserAccount } = require("@xact-wallet-sdk/client");
require("dotenv").config();
Step 2: Generate a QR Code
The process of generating a QR Code is straight forward. Within the async function, simply call generateQRCode and wait for the image.
const qrCode = await client.generateQRCode({
scope: [ScopeEnum.PROFILE, ScopeEnum.NFT]
});
Step 3: Listen to new Connections
Finally get noticed when a new user accept the connexion to your dApp.
/* Subscribe to new Connections */
client.connect().subscribe(user => {
console.log('new connexion', user);
});
⭐ Congratulations! You have successfully completed the process of authentication to our wallet
Code Check ✅
Your index.js file should look like this:
const { Client } = require("@xact-wallet-sdk/client");
require("dotenv").config();
async function main() {
//get your api key from your .env file
const apiKey = process.env.API_KEY;
// If we weren't able to find it, we should throw a new error
if (apiKey == null) {
throw new Error("Environment variables API_KEY must be present");
}
/* Create a new instance of Client */
const client = new Client({apiKey});
/* Init the connection */
await client.initConnexion();
/* Generate a QR Code */
const qrCode = await client.generateQRCode();
/* Subscribe to new Connections */
client.connect().subscribe(user => {
console.log('new connexion', user);
});
}
main();
Last updated