메인 콘텐츠로 건너뛰기

요청 서명

ChainStream은 모든 API 호출의 인증에 API 키를 사용합니다. 기본 API URL은 워크스페이스 환경 유형에 따라 다음 중 하나입니다:
  • 메인넷: https://api.chainstream.io/
각 API 요청에는 다음 헤더를 포함해야 합니다:
  • Authorization - 이 값은 Bearer <Access Token>으로 설정해야 합니다. 액세스 토큰은 Base64로 인코딩된 JSON Web Token(JWT)입니다.

JWT 토큰 생성

다음 코드를 사용하여 JWT 토큰을 생성할 수 있습니다. scope 매개변수는 선택 사항이며 특정 API 모듈에 대한 접근 권한을 제어합니다.

사용 가능한 스코프

현재 다음 스코프가 지원됩니다:
  • webhook.read - Webhook API 엔드포인트에 대한 읽기 접근
  • webhook.write - Webhook API 엔드포인트에 대한 쓰기 접근
  • kyt.read - KYT(Know Your Transaction) API 엔드포인트에 대한 읽기 접근
  • kyt.write - KYT API 엔드포인트에 대한 쓰기 접근
스코프를 지정하지 않으면 토큰은 모든 일반 API 엔드포인트에 접근할 수 있습니다. 스코프는 보호된 Webhook 또는 KYT 엔드포인트에 접근할 때만 필요합니다.

JavaScript

예제 1: 스코프 없음 (일반 API 접근)
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;
예제 2: Webhook 접근 포함
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;
예제 3: KYT 접근 포함
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;
예제 4: 여러 스코프 포함
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;

SDK 사용

JWT 토큰을 생성한 후, 이를 사용하여 SDK를 초기화할 수 있습니다:

JavaScript SDK

import { ChainStreamClient } from "@chainstream-io/sdk";

// jwtToken generated from previous step
const dex = new ChainStreamClient("your-jwt-token");
플레이스홀더 값을 실제 API 자격 증명으로 교체하세요.