Quick Start
Get your first HashNut payment working in 5 minutes.
Prerequisites
- A cryptocurrency wallet (MetaMask for EVM chains, TronLink for TRON)
- Node.js 18+ (for JavaScript examples) or Python 3.8+ (for Python examples)
- API credentials (get them from the HashNut Dashboard)
Step 1: Get Your API Credentials
- Visit the HashNut Dashboard
- Connect your wallet
- Create an account (deploys a smart contract)
- Generate an API key
- Copy your
accessKeyIdandapiKey
Step 2: Install the SDK
- JavaScript/TypeScript
- Python
- Java
- cURL
npm install @hashnut/sdk
# or
yarn add @hashnut/sdk
pip install hashnut-sdk
Add to your pom.xml:
<dependency>
<groupId>io.hashnut</groupId>
<artifactId>io-hashnut-web3-sdk</artifactId>
<version>2.0.0</version>
</dependency>
Repository: https://github.com/nuttybounty/hashnut-sdk/tree/3.1.0
No installation needed - use any HTTP client!
Step 3: Create Your First Payment
- JavaScript/TypeScript
- Python
- Java
- cURL
import { HashNutClient, HashNutService, CreatePayOrderRequest } from '@hashnut/sdk';
// Initialize SDK
const secretKey = 'YOUR_SECRET_KEY';
const accessKeyId = 'YOUR_ACCESS_KEY_ID';
const testMode = true; // true for testnet
const client = new HashNutClient(secretKey, testMode);
const service = new HashNutService(client);
// Create a payment order
const request = new CreatePayOrderRequest.Builder()
.withAccessKeyId(accessKeyId)
.withMerchantOrderId(`order-${Date.now()}`)
.withChainCode('erc20')
.withCoinCode('usdt')
.withAmount('0.01')
.build();
const response = await service.createPayOrder(request);
const order = response.data;
console.log('Payment URL:', order.paymentUrl);
// Redirect customer to order.paymentUrl
from hashnut import HashNutClient, HashNutService, CreatePayOrderRequest
from decimal import Decimal
# Initialize SDK
secret_key = 'YOUR_SECRET_KEY'
access_key_id = 'YOUR_ACCESS_KEY_ID'
test_mode = True # True for testnet
client = HashNutClient(secret_key, test_mode)
service = HashNutService(client)
# Create a payment order
request = CreatePayOrderRequest.Builder() \
.with_access_key_id(access_key_id) \
.with_merchant_order_id(f'order-{int(time.time())}') \
.with_chain_code('erc20') \
.with_coin_code('usdt') \
.with_amount(Decimal('0.01')) \
.build()
response = service.create_pay_order(request)
order = response.data
print(f'Payment URL: {order.payment_url}')
# Redirect customer to order.payment_url
import io.hashnut.client.HashNutClient;
import io.hashnut.client.HashNutClientImpl;
import io.hashnut.service.HashNutService;
import io.hashnut.service.HashNutServiceImpl;
import io.hashnut.model.request.CreatePayOrderRequest;
import io.hashnut.model.response.CreatePayOrderResponse;
import java.math.BigDecimal;
// Initialize the SDK
String secretKey = "YOUR_SECRET_KEY";
String accessKeyId = "YOUR_ACCESS_KEY_ID";
boolean testMode = true; // true for testnet
HashNutClient hashnutClient = new HashNutClientImpl(secretKey, testMode);
HashNutService hashNutService = new HashNutServiceImpl(hashnutClient);
// Create a payment order
CreatePayOrderRequest request = new CreatePayOrderRequest.Builder()
.withAccessKeyId(accessKeyId)
.withMerchantOrderId("order-" + System.currentTimeMillis())
.withChainCode("erc20")
.withCoinCode("usdt")
.withAmount(new BigDecimal("0.01"))
.build();
CreatePayOrderResponse response = hashNutService.createPayOrder(request);
HashNutOrder order = response.getData();
System.out.println("Payment URL: " + order.getPaymentUrl());
// Redirect customer to 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"
}'
Note: You need to generate the signature. See Authentication for details.
Step 4: Handle the Webhook
When a payment is completed, HashNut will send a webhook to your callBackUrl:
- JavaScript/TypeScript
- Python
- Java
// Express.js example
app.post('/webhook', async (req, res) => {
const { payOrderId, merchantOrderId, state } = req.body;
// Update your database
if (state === 4) { // Payment successful
await updateOrderStatus(merchantOrderId, 'paid');
}
res.send('success');
});
# Flask example
from flask import Flask, request
@app.route('/webhook', methods=['POST'])
def webhook():
data = request.json
pay_order_id = data['payOrderId']
merchant_order_id = data['merchantOrderId']
state = data['state']
# Update your database
if state == 4: # Payment successful
update_order_status(merchant_order_id, 'paid')
return 'success'
// Spring Boot example
@PostMapping("/webhook")
public ResponseEntity<String> webhook(@RequestBody WebhookPayload payload) {
if (payload.getState() == 4) { // Payment successful
orderService.updateStatus(payload.getMerchantOrderId(), "paid");
}
return ResponseEntity.ok("success");
}
Step 5: Test Your Integration
- Create a test order using the code above
- Open the payment URL in a browser
- Connect your wallet (MetaMask or TronLink)
- Complete the payment with test tokens
- Check your webhook - you should receive a notification
What's Next?
- Installation Guide: Detailed setup instructions
- Your First Payment: Complete tutorial
- API Reference: Explore all endpoints
- Webhook Integration: Set up webhooks properly
Need Help?
- Check the FAQ
- Review Troubleshooting
- Join our Discord community
- Contact support@hashnut.io
Congratulations! 🎉 You've created your first HashNut payment. Now explore the full documentation to unlock the full power of HashNut.