import crypto from "crypto";
const GATEWAY_URL = "http://your-gateway:180";
const MERCHANT_TOKEN = process.env.XPAYLABS_TOKEN;
function signRequest(data) {
return crypto
.createHmac("sha256", MERCHANT_TOKEN)
.update(JSON.stringify(data), "utf8")
.digest("hex");
}
async function createPayout({ amount, symbol, chain, receiveAddress, orderId }) {
const data = { amount, symbol, chain, receiveAddress, orderId };
const payload = {
sign: signRequest(data),
timestamp: Math.floor(Date.now() / 1000),
nonce: crypto.randomUUID(),
data,
};
const response = await fetch(`${GATEWAY_URL}/v1/order/createPayout`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
const result = await response.json();
if (result.code !== 200) throw new Error(result.msg);
return result.data;
}
// 在 TRON 上向外部地址发送 50 USDT
const payout = await createPayout({
amount: "50.00",
symbol: "USDT",
chain: "TRON",
receiveAddress: "TYourExternalAddress...",
orderId: "payout_001",
});
console.log(`付款已创建: ${payout.orderId}`);