> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chainstream.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> How to sign API requests with authentication

## Signing Requests

ChainStream uses API keys to authenticate all API calls. The **Base API URL** will be one of the following depending on your workspace environment type:

* Mainnet: `https://api.chainstream.io/`

Each API request must include the following headers:

* `Authorization` - This value should be set to `Bearer <Access Token>`. The access token is a Base64 encoded JSON Web Token (JWT).

## Generating JWT Token

You can generate a JWT token using the following code. The `scope` parameter is optional and controls access permissions for specific API modules.

### Available Scopes

The following scopes are currently supported:

* `webhook.read` - Read access to Webhook API endpoints
* `webhook.write` - Write access to Webhook API endpoints
* `kyt.read` - Read access to KYT (Know Your Transaction) API endpoints
* `kyt.write` - Write access to KYT API endpoints

<Note>
  If no scope is specified, the token will have access to all general API endpoints. Scopes are only required when accessing protected Webhook or KYT endpoints.
</Note>

### JavaScript

**Example 1: Without scope (general API access)**

```javascript theme={null}
import { AuthenticationClient } from 'auth0';

const auth0Client = new AuthenticationClient({
    domain: `dex.asia.auth.chainstream.io`,
    clientId: 'your client id',
    clientSecret: 'your client secret'
  });

const response = await auth0Client.oauth.clientCredentialsGrant({
      audience: 'https://api.dex.chainstream.io'
    });

return response.data.access_token;
```

**Example 2: With Webhook access**

```javascript theme={null}
import { AuthenticationClient } from 'auth0';

const auth0Client = new AuthenticationClient({
    domain: `dex.asia.auth.chainstream.io`,
    clientId: 'your client id',
    clientSecret: 'your client secret'
  });

const response = await auth0Client.oauth.clientCredentialsGrant({
      audience: 'https://api.dex.chainstream.io',
      scope: 'webhook.read webhook.write'
    });

return response.data.access_token;
```

**Example 3: With KYT access**

```javascript theme={null}
import { AuthenticationClient } from 'auth0';

const auth0Client = new AuthenticationClient({
    domain: `dex.asia.auth.chainstream.io`,
    clientId: 'your client id',
    clientSecret: 'your client secret'
  });

const response = await auth0Client.oauth.clientCredentialsGrant({
      audience: 'https://api.dex.chainstream.io',
      scope: 'kyt.read kyt.write'
    });

return response.data.access_token;
```

**Example 4: With multiple scopes**

```javascript theme={null}
import { AuthenticationClient } from 'auth0';

const auth0Client = new AuthenticationClient({
    domain: `dex.asia.auth.chainstream.io`,
    clientId: 'your client id',
    clientSecret: 'your client secret'
  });

const response = await auth0Client.oauth.clientCredentialsGrant({
      audience: 'https://api.dex.chainstream.io',
      scope: 'webhook.read webhook.write kyt.read kyt.write'
    });

return response.data.access_token;
```

## Using SDKs

After generating the JWT token, you can use it to initialize the SDK:

### JavaScript SDK

```javascript theme={null}
import { ChainStreamClient } from "@chainstream-io/sdk";

// jwtToken generated from previous step
const dex = new ChainStreamClient("your-jwt-token");
```

<Note>
  Make sure to replace the placeholder values with your actual API credentials.
</Note>
