ONTON API Setup
ONTON API Setup for SBT Claiming
Technical Integration
Now that you have all the necessary data, you can integrate ONTON API into your mini-application.
What you should have:
- ✅ API key from ONTON administrators
- ✅
event_uuid
of your approved event - ✅ Active event (current date within event timeframe)
API Request Structure
Endpoint:
POST https://app.onton.live/api/v1/reward
Request Headers:
Content-Type: application/json
accept: application/json
api-key: YOUR_API_KEY
Request Body:
{
"event_uuid": "303f3438-ee1e-4b69-95d5-e27f07dd83fe",
"reward_user_id": 123456789
}
Getting Telegram User ID
For Telegram mini-application use SDK to get user ID:
import { retrieveLaunchParams } from '@telegram-apps/sdk';
const { initData } = retrieveLaunchParams();
const userId = initData.user.id;
Implementation Examples
JavaScript/TypeScript:
async function rewardUser(eventUuid, apiKey) {
const { initData } = retrieveLaunchParams();
const userId = initData.user.id;
const response = await fetch('https://app.onton.live/api/v1/reward', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'accept': 'application/json',
'api-key': apiKey
},
body: JSON.stringify({
event_uuid: eventUuid,
reward_user_id: userId
})
});
if (response.ok) {
const result = await response.json();
// Open link for SBT claiming
window.open(result.data.reward_link, '_blank');
return true;
} else {
console.error('Error issuing SBT:', response.status);
return false;
}
}
Python (for server-side):
import requests
def reward_user(event_uuid, user_id, api_key):
url = "https://app.onton.live/api/v1/reward"
headers = {
"Content-Type": "application/json",
"accept": "application/json",
"api-key": api_key
}
data = {
"event_uuid": event_uuid,
"reward_user_id": user_id
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
result = response.json()
return result["data"]["reward_link"]
else:
print(f"Error: {response.status_code} - {response.text}")
return None
cURL for testing:
curl -X 'POST' \
'https://app.onton.live/api/v1/reward' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'api-key: your_api_key' \
-d '{
"event_uuid": "303f3438-ee1e-4b69-95d5-e27f07dd83fe",
"reward_user_id": 123456789
}'
Response Handling
Successful Response (200):
{
"status": "success",
"data": {
"reward_link": "https://t.me/id_app/start?startapp=DhXQyZ8Z4RaRc1Z6LytZ8mz1BwA58MjyHLB8ZVUnYMPNJ4AeajB"
}
}
Error Handling:
401 - Unauthorized:
{
"error": "Unauthorized: No Api Key provided"
}
- Check API key correctness
- Make sure
api-key
header is specified
400 - Bad Request:
{
"error": "Invalid request parameters or event not ongoing"
}
- Check
event_uuid
correctness - Make sure event is active (within specified dates)
- Check
reward_user_id
correctness
Important Limitations
Time Constraints:
- API works only during active event
- For permanent rewards specify long period (several years)
- When event is inactive you'll get "event not ongoing" error
Security:
- Never store API keys in open code
- Use environment variables
- Restrict access to API keys
Testing
Recommended order:
- Make sure event is active
- Test with your own Telegram ID
- Check API key and UUID correctness
- Verify that obtained link opens
Full integration example:
// Configuration
const CONFIG = {
apiKey: process.env.ONTON_API_KEY,
eventUuid: process.env.ONTON_EVENT_UUID
};
// SBT reward function
async function giveSBTReward() {
try {
const success = await rewardUser(CONFIG.eventUuid, CONFIG.apiKey);
if (success) {
// Show success notification
showSuccess('SBT reward issued!');
} else {
showError('Failed to issue reward');
}
} catch (error) {
console.error('Error issuing SBT:', error);
showError('An error occurred');
}
}
Conclusion
ONTON API integration allows you to create a powerful reward system in your mini-application. Key principles:
- Preparation - get all necessary data
- Testing - check API functionality
- Integration - embed into application logic
- Monitoring - track system performance
Remember about event time limitations and always check your event activity before issuing rewards.