快速开始
在 5 分钟内完成您的第一个 HashNut 支付。
前置要求
- 加密货币钱包(EVM 链使用 MetaMask,TRON 使用 TronLink)
- Node.js 18+(JavaScript 示例)或 Python 3.8+(Python 示例)
- API 凭证(从 HashNut 控制台 获取)
步骤 1:获取 API 凭证
- 访问 HashNut 控制台
- 连接您的钱包
- 创建账户(部署智能合约)
- 生成 API 密钥
- 复制您的
accessKeyId和apiKey
步骤 2:安装 SDK
- JavaScript/TypeScript
- Python
- Java
- cURL
npm install @hashnut/sdk
# 或
yarn add @hashnut/sdk
pip install hashnut-sdk
添加到您的 pom.xml:
<dependency>
<groupId>io.hashnut</groupId>
<artifactId>hashnut-sdk</artifactId>
<version>1.0.0</version>
</dependency>
无需安装 - 使用任何 HTTP 客户端即可!
步骤 3:创建您的第一个支付
- JavaScript/TypeScript
- Python
- Java
- cURL
import { HashnutClient } from '@hashnut/sdk';
const client = new HashnutClient({
baseUrl: 'https://testnet.hashnut.io',
accessKeyId: 'YOUR_ACCESS_KEY_ID',
apiKey: 'YOUR_API_KEY',
});
// 创建支付订单
const order = await client.orders.create({
merchantOrderId: `order-${Date.now()}`,
chainCode: 'erc20',
coinCode: 'usdt',
amount: 0.01,
callBackUrl: 'https://your-site.com/webhook',
frontendCallbackUrl: 'https://your-site.com/payment/success',
});
console.log('Payment URL:', order.paymentUrl);
// 将客户重定向到 order.paymentUrl
from hashnut import HashnutClient
client = HashnutClient(
base_url='https://testnet.hashnut.io',
access_key_id='YOUR_ACCESS_KEY_ID',
api_key='YOUR_API_KEY'
)
# 创建支付订单
order = client.orders.create(
merchant_order_id=f'order-{int(time.time())}',
chain_code='erc20',
coin_code='usdt',
amount=0.01,
callback_url='https://your-site.com/webhook',
frontend_callback_url='https://your-site.com/payment/success'
)
print(f'Payment URL: {order.payment_url}')
# 将客户重定向到 order.payment_url
import io.hashnut.HashnutClient;
import io.hashnut.models.CreateOrderRequest;
HashnutClient client = new HashnutClient(
"https://testnet.hashnut.io",
"YOUR_ACCESS_KEY_ID",
"YOUR_API_KEY"
);
// 创建支付订单
CreateOrderRequest request = CreateOrderRequest.builder()
.merchantOrderId("order-" + System.currentTimeMillis())
.chainCode("erc20")
.coinCode("usdt")
.amount(new BigDecimal("0.01"))
.callBackUrl("https://your-site.com/webhook")
.frontendCallbackUrl("https://your-site.com/payment/success")
.build();
Order order = client.orders().create(request);
System.out.println("Payment URL: " + order.getPaymentUrl());
// 将客户重定向到 order.getPaymentUrl()
curl -X POST 'https://testnet.hashnut.io/api/v3.0.0/pay/createPayOrderOnSplitWalletWithApiKey' \
-H 'hashnut-request-uuid: 550e8400-e29b-41d4-a716-446655440000' \
-H 'hashnut-request-timestamp: 1704067200000' \
-H 'hashnut-request-sign: <your-signature>' \
-H 'Content-Type: application/json' \
-d '{
"accessKeyId": "YOUR_ACCESS_KEY_ID",
"merchantOrderId": "order-123",
"chainCode": "erc20",
"coinCode": "usdt",
"amount": 0.01,
"callBackUrl": "https://your-site.com/webhook",
"frontendCallbackUrl": "https://your-site.com/payment/success"
}'
注意:您需要生成签名。详情请参阅 认证文档。
步骤 4:处理 Webhook
当支付完成时,HashNut 会向您的 callBackUrl 发送 webhook:
- JavaScript/TypeScript
- Python
- Java
// Express.js 示例
app.post('/webhook', async (req, res) => {
// 验证 webhook 签名(重要!)
const isValid = client.webhooks.verify(req);
if (!isValid) {
return res.status(401).send('Invalid signature');
}
const { payOrderId, merchantOrderId, state } = req.body;
// 更新您的数据库
if (state === 4) { // 支 付成功
await updateOrderStatus(merchantOrderId, 'paid');
}
res.send('success');
});
# Flask 示例
from flask import Flask, request
@app.route('/webhook', methods=['POST'])
def webhook():
# 验证 webhook 签名(重要!)
if not client.webhooks.verify(request):
return 'Invalid signature', 401
data = request.json
pay_order_id = data['payOrderId']
merchant_order_id = data['merchantOrderId']
state = data['state']
# 更新您的数据库
if state == 4: # 支付成功
update_order_status(merchant_order_id, 'paid')
return 'success'
// Spring Boot 示例
@PostMapping("/webhook")
public ResponseEntity<String> webhook(@RequestBody WebhookPayload payload) {
// 验证 webhook 签名(重要!)
if (!client.webhooks().verify(payload)) {
return ResponseEntity.status(401).body("Invalid signature");
}
if (payload.getState() == 4) { // 支付成功
orderService.updateStatus(payload.getMerchantOrderId(), "paid");
}
return ResponseEntity.ok("success");
}
步骤 5:测试您的集成
- 创建测试订单:使用上面的代码
- 在浏览器中打开支付链接
- 连接您的钱包(MetaMask 或 TronLink)
- 使用测试代币完成支付
- 检查您的 webhook - 您应该收到通知
下一步?
- 安装指南:详细设置说明
- 您的第一个支付:完整教程
- API 参考:探索所有端点
- Webhook 集成:正确设置 webhook
需要帮助?
- 查看 常见问题
- 查看 故障排除
- 加入我们的 Discord 社区
- 联系 support@hashnut.io
恭喜! 🎉 您已创建了第一个 HashNut 支付。现在探索 完整文档 以解锁 HashNut 的全部功能。