> For the complete documentation index, see [llms.txt](https://docs.intentx.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.intentx.io/trading-api/typescript-sdk/examples/private-key-authentication.md).

# Private Key Authentication

```typescript
import { AllowedPermission } from "@intentx/core";
import { TradingSDK } from "@intentx/trading-sdk";
import dotenv from "dotenv";

dotenv.config();

async function privateKeyAuthenticationExample() {
  const tradingSDK = new TradingSDK({
    apiKey: process.env.API_KEY,
    baseUrl: process.env.API_BASE_URL ?? undefined,
  });

  await tradingSDK.authManager.loginWithPrivateKey(process.env.PRIVATE_KEY!);

  const apiKey = await tradingSDK.authManager.createApiKey();

  console.log(apiKey);

  const { apiKeyIdentifier: apiKeyId } =
    await tradingSDK.authManager.validateApiKey(apiKey);

  const TARGET_SUBACCOUNT = "0x52D953159a9a636944C9d96E14CB5DF0948323E9";

  // Delegating operational access to the api key
  try {
    await tradingSDK.authManager.delegateSubaccountApiPermission(
      TARGET_SUBACCOUNT,
      [AllowedPermission.ALL],
      apiKeyId
    );
  } catch (error) {
    console.error(error);
  }

  console.log("Delegated operational access to the api key");
}

privateKeyAuthenticationExample();
```
