# Getting started

## Register your App

To start using Xact SDK, you will need to [Register your App](https://dev.xact.ac) in order to get an API Key.

{% hint style="info" %}
Note that a warning will appear on the authorization screens for your app until you [apply to be a verified app](https://form.sylleb.io/xact-sdk-verification).
{% endhint %}

## 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.

```bash
mkdir xact-sdk && cd xact-sdk
```

### 1.2 Initialize your project

```bash
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](https://code.visualstudio.com/Download) or [Webstorm](https://www.jetbrains.com/fr-fr/webstorm/).

### 1.1 Install it with your favorite package manager

```javascript
// 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.

```javascript
// 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](https://dev.xact.ac).

{% code title=".env" %}

```javascript
API_KEY=...
```

{% endcode %}

## 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.

```javascript
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

{% hint style="warning" %}
Note that the API key is directly linked to a unique environment.
{% endhint %}

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](https://dev.xact.ac), the environment is already known at this stage.

Let's now initialize the Client with the API key

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

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

```javascript
await client.initConnexion();
```

Your project environment is now set up to successfully submit actions through the [Xact Wallet](https://wallet.xact.ac)!

Next, you will learn how to Login new users.

## Code Check ✅

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

{% code title="index.js" %}

```javascript
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();
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xact.gitbook.io/xact/sdk/javascript/getting-started.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
