交易平台引入 sdk.js, 即可讓用戶在平台頁面直接操作買賣幣、充提幣等功能。平台只需提供按鈕,功能視窗由 SDK 負責。
1 — 後端:取得 Token
用平台 API Key 換取代表用戶身份的短期 JWT(1 小時有效)。
POST /api/v1/platform/user-token
x-api-key: <YOUR_PLATFORM_API_KEY>
Content-Type: application/json
{ "platformUserId": "user_123" }
// Response
{ "token": "eyJhbG…" }2 — 前端:引入 SDK
在頁面 head 引入一次,全站有效。
<script src="https://stellabit.cc/sdk.js"></script>3 — 呼叫功能
平台自訂按鈕樣式,點擊時呼叫對應方法。
Stellabit.open('buy', token)
Stellabit.open('sell', token)
Stellabit.open('deposit', token)
Stellabit.open('withdraw', token)
Stellabit.open('transfer', token)
Stellabit.open('peer', token)4 — 監聽關閉 / 顯示餘額
// 功能視窗關閉後觸發
Stellabit.onClose(() => {
refreshBalance()
})
// 選用:嵌入餘額數字(高度 80px)
<iframe
src="https://stellabit.cc/widget/balance?token=<TOKEN>"
style="border:none; width:200px; height:80px;"
/><!DOCTYPE html>
<html>
<head>
<script src="https://stellabit.cc/sdk.js"></script>
</head>
<body>
<!-- 選用:餘額顯示 -->
<iframe id="balance"
src="https://stellabit.cc/widget/balance?token=<TOKEN>"
style="border:none; width:200px; height:80px;" />
<!-- 平台自訂按鈕 -->
<button onclick="Stellabit.open('buy', token)">買幣</button>
<button onclick="Stellabit.open('sell', token)">賣幣</button>
<button onclick="Stellabit.open('deposit', token)">充幣</button>
<button onclick="Stellabit.open('withdraw', token)">提幣</button>
<script>
const token = '<從後端取得的 JWT Token>'
Stellabit.onClose(() => {
document.getElementById('balance')
.contentWindow
.postMessage({ type: 'stellabit:refresh' }, 'https://stellabit.cc')
})
</script>
</body>
</html>