Files
explore/lib/api/luxnet/instance.ts
T
zeekay df89ce82e7 feat: integrate luxnet SDK for P-chain API calls
Replace hand-rolled JSON-RPC fetch client with [email protected].0 SDK.
P-chain hooks now use PlatformVMAPI methods directly.
2026-02-27 10:55:58 -08:00

35 lines
907 B
TypeScript

import Lux from 'luxnet';
import { getEnvValue } from 'configs/app/utils';
const CCHAIN_RPC_PATTERN = /\/ext\/bc\/C\/rpc$/;
const HTTPS_PORT = 443;
const HTTP_PORT = 80;
function parseRpcUrl(): { host: string; port: number; protocol: string } {
const rpcUrl = getEnvValue('NEXT_PUBLIC_NETWORK_RPC_URL');
if (!rpcUrl) {
throw new Error('NEXT_PUBLIC_NETWORK_RPC_URL is not configured');
}
const base = rpcUrl.replace(CCHAIN_RPC_PATTERN, '');
const url = new URL(base);
const defaultPort = url.protocol === 'https:' ? HTTPS_PORT : HTTP_PORT;
return {
host: url.hostname,
port: url.port ? Number(url.port) : defaultPort,
protocol: url.protocol.replace(':', ''),
};
}
let instance: Lux | undefined;
export function getLux(): Lux {
if (!instance) {
const { host, port, protocol } = parseRpcUrl();
instance = new Lux(host, port, protocol);
}
return instance;
}