개발자 문서
트론 에너지 임대 API 레퍼런스: REST 엔드포인트 및 통합
TronEnergy 에너지 위임을 위한 완전한 REST API 문서. POST /delegate 엔드포인트, HMAC 인증, 요청/응답 형식, 오류 코드 및 속도 제한.
기본 URL:
https://api.tronnrg.com
인증: 필요 없음. 모든 엔드포인트는 공개입니다.
속도 제한: IP당 초당 20개 요청
결제 주소: TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx (API 전용, 수동 임대 제외) 작동 방식
세 가지 단계. API 키 없음, 가입 없음, 지갑 연결 없음. 소유권은 암호화로 입증됩니다.
- TRX 전송 — 결제 주소로 4 TRX (또는 그 이상)를 전송하세요. 4 TRX = 65,000 에너지. 8 TRX = 130,000. 선형입니다.
- 서명 — 메시지
{tx_hash}:{delegate_to}를 TRX를 전송한 지갑으로 서명하세요. 이는 위임을 승인했음을 증명합니다. - 요청 —
POST /delegate함께tx_hash,delegate_to, 그리고signature를 사용하여 요청하세요. 에너지는 약 3초 내에 도착합니다.
결제 주소
TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx
API 결제 주소만. 이 주소는 API를 통한 프로그래밍 통합용입니다. 수동 에너지 임대에는 사용하지 마세요. 수동 임대 주소는 다르며 에서 확인할 수 있습니다.tronnrg.com.
이 주소로 TRX를 전송하세요. 결제의 거래 해시가 위임을 실행하는 토큰입니다. 각 해시는 한 번만 사용할 수 있습니다.
| 전송한 TRX | 위임한 에너지 | 사용 사례 |
|---|---|---|
| 4 TRX | 65,000 | 기존 지갑으로 표준 USDT 전송 (최소 주문) |
| 8 TRX | 130,000 | 첫 수신자에게 USDT 전송 |
| 16 TRX | 260,000 | 한 주문 내 표준 전송 4건 |
| 40 TRX | 650,000 | 표준 전송 10건 |
| 100 TRX | 1,625,000 | 약 25건의 표준 전송 — 소규모 플랫폼에 일반적 |
| 1,000 TRX | 16,250,000 | 최대 주문, 약 250건의 표준 전송 |
| 그 사이의 모든 금액 | trx × 16,250 | 완전 선형입니다. 단계, 패키지, 할인 없음. |
공식:
energy = trxSent × 16,250. 범위: 최소 4 TRX (65,000 에너지), 최대 1,000 TRX (16,250,000 에너지). 둘 다 API 수준에서 적용되며 — 최소값 이하의 금액은 below_minimum으로 거부되고 환불되며, 최대값 초과의 금액은 위임 전에 거부됩니다.
POST /delegate
POST/delegate
에너지 위임을 신청합니다. 이미 온체인 결제 주소로 TRX를 전송했어야 합니다. 트랜잭션 해시, 수신자 주소, 발신자임을 증명하는 서명을 전달하세요.
| 매개변수 | 유형 | 설명 | |
|---|---|---|---|
| tx_hash | string | 필수 | TRX 결제의 64자 16진수 해시 |
| delegate_to | string | 필수 | 에너지를 받을 트론 주소 |
| signature | string | 필수 | tronWeb.trx.signMessageV2() of tronWeb.trx.signMessageV2(). 결제 발신자임을 증명합니다. |
curl -X POST https://api.tronnrg.com/delegate \
-H "Content-Type: application/json" \
-d '{"tx_hash":"TX_HASH","delegate_to":"TWallet","signature":"SIG"}'
const result = await fetch('https://api.tronnrg.com/delegate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
tx_hash: 'YOUR_TX_HASH',
delegate_to: 'TWalletAddress',
signature: 'YOUR_SIGNATURE',
}),
}).then(r => r.json());
if (result.error) {
console.error(result.error, result.message);
} else {
console.log('Delegated:', result.energy, 'energy');
console.log('Ref:', result.ref);
}
import requests
response = requests.post('https://api.tronnrg.com/delegate', json={
'tx_hash': 'YOUR_TX_HASH',
'delegate_to': 'TWalletAddress',
'signature': 'YOUR_SIGNATURE',
})
result = response.json()
if 'error' in result:
print(f"Error: {result['error']} - {result['message']}")
else:
print(f"Delegated: {result['energy']} energy")
print(f"Delegation tx: {result['delegations'][0]['tx']}")
print(f"Ref: {result['ref']}")
$ch = curl_init('https://api.tronnrg.com/delegate');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'tx_hash' => 'YOUR_TX_HASH',
'delegate_to' => 'TWalletAddress',
'signature' => 'YOUR_SIGNATURE',
]),
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
if (isset($result['error'])) {
echo "Error: " . $result['message'];
} else {
echo "Delegated: " . $result['energy'] . " energy";
}
var client = new HttpClient();
var content = new StringContent(
JsonSerializer.Serialize(new {
tx_hash = "YOUR_TX_HASH",
delegate_to = "TWalletAddress",
signature = "YOUR_SIGNATURE"
}),
Encoding.UTF8, "application/json"
);
var response = await client.PostAsync("https://api.tronnrg.com/delegate", content);
var json = await response.Content.ReadAsStringAsync();
var result = JsonSerializer.Deserialize<JsonElement>(json);
if (result.TryGetProperty("error", out var err))
Console.WriteLine($"Error: {err}");
else
Console.WriteLine($"Delegated: {result.GetProperty("energy")} energy");
응답 200
{
"ref": "nrg_d_42",
"delegate_to": "TWalletAddress",
"energy": 65000,
"cost": 4,
"status": "delegated",
"delegations": [
{ "tx": "a1b2c3d4e5f6...your delegation tx hash", "energy": 65000 }
]
}
| 필드 | 유형 | 설명 |
|---|---|---|
| ref | string | TronNRG 참조 ID. 지원 문의 시 이를 기록하세요. |
| energy | number | 위임된 총 에너지 |
| cost | number | 청구된 TRX |
| status | string | 성공 시 "delegated" |
| delegations | array | 온체인 위임 트랜잭션 해시. 각 tx는 TronScan에서 검증 가능합니다. 이것이 영수증입니다. |
GET /health
GET/health
모니터링 및 가동시간 도구용 활동성 확인. API 프로세스가 실행 중일 때 200 OK를 반환합니다. 업스트림 노드나 공급자를 확인하지 않습니다.
응답 200
{ "status": "ok" }
오류 코드
모든 오류 응답에는 error (안정적이고 기계 판독 가능)과 message (사람이 읽을 수 있는 형식)이 있습니다. 코드에서 항상 error를 기준으로 전환하세요.
| 코드 | HTTP | 의미 |
|---|---|---|
invalid_tx_hash | 400 | 64자 16진수 문자열이 아닙니다 |
invalid_address | 400 | 유효한 트론 주소가 아닙니다 |
missing_signature | 400 | 서명이 제공되지 않았습니다 |
invalid_signature | 401 | 서명을 검증할 수 없습니다 |
signature_mismatch | 403 | 서명자 주소가 결제 발신자와 일치하지 않습니다 |
hash_already_used | 409 | 트랜잭션 해시가 이미 신청되었습니다 |
payment_verification_failed | 404 / 400 | 결제의 온체인 검증이 실패했습니다. message 필드를 읽어 구체적인 원인을 확인하세요: 트랜잭션을 아직 찾지 못함(404, 몇 초 후 다시 시도), 잘못된 수신자, TRX 전송이 아님, 또는 4 TRX 최소값 이하. |
delegation_failed | 400 / 500 | 공급자가 에너지를 전달할 수 없습니다. 결제가 검증된 후에 실패가 발생하면 환불이 자동으로 대기열에 추가됩니다. 이 경우 refund 객체를 확인하세요. |
rate_limited | 429 | 이 IP에서 초당 요청이 너무 많습니다. 제한은 초당 20개입니다. |
server_error | 500 | 예기치 않은 내부 오류입니다. 몇 초 후에 다시 시도하세요. |
const result = await fetch('https://api.tronnrg.com/delegate', { ... })
.then(r => r.json());
if (result.error) {
switch (result.error) {
case 'payment_verification_failed':
// Most common cause: tx not yet indexed. Wait 3s and retry.
// Read result.message for the specific cause.
break;
case 'hash_already_used':
// Already claimed. Don't retry.
break;
case 'signature_mismatch':
// Signer != payment sender. Sign with the same key that sent TRX.
break;
case 'delegation_failed':
// Refund queued automatically if payment was verified.
if (result.refund) console.log('Refund queued:', result.refund);
break;
}
}
result = requests.post('https://api.tronnrg.com/delegate', json=data).json()
if 'error' in result:
if result['error'] == 'payment_verification_failed':
# Most common cause: tx not yet indexed. Wait 3s and retry.
pass
elif result['error'] == 'hash_already_used':
# Already claimed. Don't retry.
pass
elif result['error'] == 'signature_mismatch':
# Signer != payment sender. Sign with the same key.
pass
elif result['error'] == 'delegation_failed':
# Refund queued automatically if payment was verified.
pass
if (isset($result['error'])) {
switch ($result['error']) {
case 'payment_verification_failed':
// Most common cause: tx not yet indexed. Wait 3s and retry.
break;
case 'hash_already_used':
// Already claimed. Don't retry.
break;
case 'signature_mismatch':
// Signer != payment sender. Sign with the same key.
break;
case 'delegation_failed':
// Refund queued automatically if payment was verified.
break;
}
}
환불
결제 확인 후 위임이 실패하면 TRX 환불이 자동으로 대기열에 추가되어 온체인 발신자 주소로 반환됩니다. 오류 응답에서 환불 객체를 확인하세요.
환불 포함 오류
{
"error": "delegation_failed",
"message": "Energy delegation failed. Your payment will be refunded.",
"ref": "nrg_d_43",
"refund": {
"type": "queued",
"to": "TSenderAddress",
"amount": 4
}
}
완전한 예제
전체 엔드투엔드 흐름: TRX 전송, 서명, 재시도를 통한 청구. 복사하여 실행하세요.
const API = 'https://api.tronnrg.com';
const ADDR = 'TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx';
async function rentEnergy(delegateTo, trxAmount = 4) {
// 1. Send TRX to the payment address
const payment = await tronWeb.trx.sendTransaction(ADDR, trxAmount * 1e6);
// 2. Sign: proves you are the sender
const message = `${payment.txid}:${delegateTo}`;
const signature = await tronWeb.trx.signMessageV2(message);
// 3. Claim delegation (retry if tx not indexed yet)
let result;
for (let i = 0; i < 3; i++) {
result = await fetch(`${API}/delegate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
tx_hash: payment.txid,
delegate_to: delegateTo,
signature,
}),
}).then(r => r.json());
if (!result.error) break;
if (result.error !== 'payment_verification_failed') throw new Error(result.message);
await new Promise(r => setTimeout(r, 3000));
}
if (result.error) throw new Error(result.message);
return result;
}
// Usage — send any amount between 4 and 1,000 TRX
const result = await rentEnergy('TWalletThatNeedsEnergy', 4); // 4 TRX → 65k energy
// rentEnergy(addr, 8) // → 130,000 energy (new-wallet transfer)
// rentEnergy(addr, 40) // → 650,000 energy (10 transfers)
// rentEnergy(addr, 1000) // → 16,250,000 energy (max)
console.log(result.energy); // trxAmount × 16,250
console.log(result.delegations[0].tx); // on-chain tx hash
console.log(result.ref); // "nrg_d_42"
import requests
import time
API = 'https://api.tronnrg.com'
ADDR = 'TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx'
def rent_energy(delegate_to, trx_amount=4):
# 1. Send TRX to ADDR (via your Tron library)
tx_hash = send_trx(ADDR, trx_amount) # your TRX send function
# 2. Sign: proves you are the sender
message = f'{tx_hash}:{delegate_to}'
signature = tron.trx.sign_message_v2(message)
# 3. Claim delegation (retry if tx not indexed yet)
for attempt in range(3):
result = requests.post(f'{API}/delegate', json={
'tx_hash': tx_hash,
'delegate_to': delegate_to,
'signature': signature,
}).json()
if 'error' not in result:
return result
if result['error'] != 'payment_verification_failed':
raise Exception(result['message'])
time.sleep(3)
raise Exception('Transaction not found after retries')
# Usage
result = rent_energy('TWalletThatNeedsEnergy', 4)
print(f"Delegated: {result['energy']} energy")
print(f"Delegation tx: {result['delegations'][0]['tx']}")
print(f"Ref: {result['ref']}")
<?php
$api = 'https://api.tronnrg.com';
$addr = 'TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx';
function rentEnergy($api, $txHash, $delegateTo, $signature) {
// 1. Send TRX to $addr (via iexbase/tron-api)
// $payment = $tron->sendTrx($addr, 4);
// $txHash = $payment['txid'];
// 3. Claim delegation (retry if tx not indexed yet)
for ($i = 0; $i < 3; $i++) {
$ch = curl_init("${api}/delegate");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'tx_hash' => $txHash,
'delegate_to' => $delegateTo,
'signature' => $signature,
]),
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
if (!isset($result['error'])) return $result;
if ($result['error'] !== 'payment_verification_failed')
throw new Exception($result['message']);
sleep(3);
}
throw new Exception('Transaction not found after retries');
}
// Usage
$result = rentEnergy($api, $txHash, 'TWalletThatNeedsEnergy');
echo "Delegated: " . $result['energy'] . " energy\n";
echo "Delegation tx: " . $result['delegations'][0]['tx'] . "\n";
echo "Ref: " . $result['ref'] . "\n";
# 1. Send TRX to TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx
# Pricing is linear at 16,250 energy per TRX.
# Min 4 TRX (65,000 energy), max 1,000 TRX (16.25M energy).
# (use your wallet or tronweb CLI)
# 2. Sign the message {tx_hash}:{delegate_to} (proves you are the sender)
# (use tronWeb.trx.signMessageV2 in your code)
# 3. Claim delegation with tx hash + signature
curl -X POST https://api.tronnrg.com/delegate \
-H "Content-Type: application/json" \
-d '{
"tx_hash": "YOUR_PAYMENT_TX_HASH",
"delegate_to": "TWalletThatNeedsEnergy",
"signature": "YOUR_SIGNATURE"
}'
# Response includes delegations[].tx — the on-chain hash you can verify on TronScan