签名请求
ChainStream 使用 API 密钥对所有 API 调用进行认证。根据工作区环境类型,基础 API URL 将是以下之一:
- 主网:
https://api-dex.chainstream.io/
每个 API 请求必须包含以下请求头:
Authorization
- 此值应设置为 Bearer <Access Token>
。访问令牌是一个 Base64 编码的 JSON Web Token (JWT)。
生成 JWT 令牌
你可以使用以下代码生成 JWT 令牌:
JavaScript
import { AuthenticationClient } from 'auth0';
const auth0Client = new AuthenticationClient({
domain: `https://dex.asia.auth.chainstream.io/oauth/token`,
client_id: 'your client id',
client_secret: 'your client secret'
});
const response = await auth0Client.oauth.clientCredentialsGrant({
audience: 'https://api-dex.chainstream.io'
});
return response.data.access_token;
使用 SDK
生成 JWT 令牌后,你可以使用它来初始化 SDK:
JavaScript SDK
import { DexClient } from "@chainstream-io/dex";
const dex = new DexClient({
accessToken: "your-jwt-token" // 从上一步生成的令牌
});
请确保将示例中的占位值替换为你的实际 API 凭据。