Private Key Authentication
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();
Last updated