Getting started

Register your App

To start using Xact SDK, you will need to Register your App in order to get an API Key.

Note that a warning will appear on the authorization screens for your app until you apply to be a verified app.

Step 1: Set up your node.js environment

1.1 Create a new directory for our example

Open your terminal and create a directory named xact-sdk. After you created the project directory navigate into this directory.

mkdir xact-sdk && cd xact-sdk

1.2 Initialize your project

npm init -y

Step 2: Install the Xact SDK

Now that you have your Node environment setup, we can get started with Xact's JS SDK! You can open this project in your favorite text editor like Visual Studio Code or Webstorm.

1.1 Install it with your favorite package manager

// install Xact's JS SDK with NPM
npm i @xact-wallet-sdk/client@latest

// Install with Yarn
yarn add @xact-wallet-sdk/client@latest

// Install with PNPM
pnpm install @xact-wallet-sdk/client@latest

1.2 Define your environment

Install dotenv with your favorite package manager. This will allow our node environment to use your API key that we will store in a .env file.

// install with NPM
npm install dotenv

// Install with Yarn
yarn add dotenv

// Install with PNPM
pnpm install dotenv

Create .env file in your project

The .env file will store your API key. Create this file in the root directory of your project and save it as .env file.

Now you can add your API key provided from your Xact Dev portal.

.env
API_KEY=...

Step 3: Create index.js file in the 'root' directory

This file will contain the code we will write in the following samples.

Grab your Xact API key from the .env file.

const { Client } = require("@xact-wallet-sdk/client");
require("dotenv").config();

async function main() {

    //Grab your api key from your .env file
    const apiKey = process.env.API_KEY;


    // If we weren't able to grab it, we should throw a new error
    if (apiKey == null) {
        throw new Error("Environment variables API_KEY must be present");
    }
}
main();

Step 5: Create you Xact client

Note that the API key is directly linked to a unique environment.

You haven't the option at this stage to select the Hedera mainnet or testnet. Since we are using an API key generated from the Xact Dev portal, the environment is already known at this stage.

Let's now initialize the Client with the API key

const client = new Client({apiKey, options: {debugLevel: DebugLevel.DEBUG /* Default to OFF */}});

Then you need to initialize the connection and await for it :

await client.initConnexion();

Your project environment is now set up to successfully submit actions through the Xact Wallet!

Next, you will learn how to Login new users.

Code Check ✅

What your index.js file should look like at this point:

index.js
const { Client } = require("@xact-wallet-sdk/client");
require("dotenv").config();

async function main() {

    //Grab your api key from your .env file
    const apiKey = process.env.API_KEY;


    // If we weren't able to grab 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();
}
main();

Last updated