API TO'LOV MANZILI
TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx
TRX ushbu manzilga yuboring. Sizning tx xeshingiz energiya delegatsiyasini talab qilish uchun ishlatiladi.

PHP integratsiyasidan to'liq foydalanish iexbase/tron-api kutubxona. Har bir qadam mustaqil kod bloki bo'lib, uni loyihangizga nusxalashingiz mumkin. Har qanday PHP freymvorki yoki oddiy PHP bilan ishlaydi.

Talablar: PHP 7.4+, Composer, ext-gmp va ext-bcmath yoqilgan, moliyalashtirilgan Tron hamyon.
PHP da imzolash haqida: TronEnergy API hamyon imzosini talab qiladi tronWeb.trx.signMessageV2()... The iexbase/tron-api Kutubxona ushbu aniq imzolash ibtidoiy usulini oshkor qilmaydi, shuning uchun ushbu qo'llanma imzolash bosqichi uchun kichik Node.js yordamchisidan foydalanadi. Qolgan hamma narsa ( TRX yuborish, API chaqirish, USDT yuborish) PHP da qoladi. Agar sizda haqiqiy signMessageV2 imzosini ishlab chiqaradigan sof PHP imzolash yechimi bo'lsa, boshqa hech qanday bosqichni o'zgartirmasdan yordamchini almashtirishingiz mumkin.

Oqim

API kaliti yo'q. Ro'yxatdan o'tish yo'q. Kodingiz TRX TronEnergy to'lov manziliga zanjir orqali yuboradi, egalikni tasdiqlovchi xabarni imzolaydi va keyin delegatsiyani talab qiladi. Energy taxminan 3 soniyada yetib keladi. Keyin kodingiz delegatsiya qilingan energiya yordamida USDT yuboradi.

1
TRX yuborish
Zanjirdagi to'lov manziliga 4 yoki undan ortiq TRX yuboring (min. 4, maksimal 1000).
2
Belgi
Yuboruvchi ekanligingizni isbotlash uchun tx_hash:delegate_to imzosini qo'ying.
3
Talab
tx xeshi va imzosi bilan POST /delegate. Energy ~3 soniyada yetib keladi.
Narxlar chiziqli: har bir TRX uchun 16 250 Energy . Minimal buyurtma 4 TRX (65 000 Energy — bitta standart USDT o'tkazmasi), maksimal 1000 TRX (16.25M Energy ). Siz yuborgan miqdor qancha Energy qaytarib berilishini aniq belgilaydi — darajalar yo'q, paketlar yo'q. Bitta standart o'tkazma uchun foydalaning $trxAmount = 4Yangi hamyon o'tkazmasi uchun foydalaning 8Ommaviy ish uchun ko'proq foydalaning. Quyidagi kod a dan foydalanadi $trxAmount o'zgaruvchan, shuning uchun uni bir joyda o'zgartirishingiz mumkin.

Bosqichma-bosqich

1. O'rnatish

bastakor
composer require iexbase/tron-api

2. Sozlash

setup.php
require_once 'vendor/autoload.php'; use IEXBase\TronAPI\Tron; $tron = new Tron(); $tron->setPrivateKey('YOUR_PRIVATE_KEY'); $tron->setAddress('YOUR_WALLET_ADDRESS'); $api = 'https://api.tronnrg.com'; $addr = 'TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx'; // API payment address $usdt = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'; // USDT contract
Hech qachon hisob ma'lumotlarini qattiq kodlamang. Shaxsiy kalitingizni muhit o'zgaruvchilari yoki maxfiylik menejeridan yuklang. Hech qachon maxfiyliklarni git ga yuklamang.

3. To'lov ma'lumotlarini oling (ixtiyoriy)

to'lov ma'lumotlarini olish
// Get pricing and payment address (optional, energy is always available) $supply = json_decode( file_get_contents("${api}/supply"), true ); echo "Pay to: " . $supply['pay_to'] . "\n"; echo "Energy per TRX: " . $supply['energy_per_trx'] . "\n";

4. TRX yuboring

TRX yuborish
// Send TRX to the API payment address — pricing is linear. // 16,250 energy per TRX. Min 4 TRX, max 1,000 TRX. // $trxAmount = 4 → 65,000 energy (standard USDT transfer) // $trxAmount = 8 → 130,000 energy (new wallet transfer) // $trxAmount = 40 → 650,000 energy (10 standard transfers) // $trxAmount = 1000 → 16,250,000 energy (max) $trxAmount = 4; $payment = $tron->sendTrx($addr, $trxAmount); if (!isset($payment['result']) || !$payment['result']) { throw new Exception('TRX transfer failed'); } $txHash = $payment['txid']; echo "Payment sent: ${txHash}\n";

5. Xabarni imzolang

API TRX yuborgan hamyon delegatsiyani so'rayotganini tasdiqlovchi imzoni talab qiladi. Biz buni kichik Node.js yordamchisi yordamida amalga oshiramiz. Uni quyidagicha saqlang. sign.js PHP faylingiz yonida:

sign.js
// Usage: node sign.js <tx_hash> <delegate_to> // Outputs the signature to stdout. Reads private key from TRON_PRIVATE_KEY env var. const { TronWeb } = require('tronweb'); const [, , txHash, delegateTo] = process.argv; const tronWeb = new TronWeb({ fullHost: 'https://api.trongrid.io', privateKey: process.env.TRON_PRIVATE_KEY, }); tronWeb.trx.signMessageV2(`${txHash}:${delegateTo}`) .then(sig => process.stdout.write(sig)) .catch(e => { console.error(e.message); process.exit(1); });

TronWeb xuddi shu papkaga o&#39;rnating: npm install tronwebKeyin uni PHP dan chaqiring:

PHP dan imzo
// Both the sender (in $tron) and the signer must be the SAME wallet. // Make sure TRON_PRIVATE_KEY in your environment matches the wallet that sent the TRX. $delegateTo = 'TWalletThatNeedsEnergy'; $signature = trim(shell_exec( sprintf('node sign.js %s %s', escapeshellarg($txHash), escapeshellarg($delegateTo) ) )); if (!$signature) { throw new Exception('Signing failed. Check that node and tronweb are installed and TRON_PRIVATE_KEY is set.'); } echo "Signed: " . substr($signature, 0, 20) . "...\n";

6. Delegatsiyani talab qiling

da&#39;vo delegatsiyasi
// $txHash, $delegateTo, and $signature are all defined in the previous steps. $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); echo "Energy: " . $result['energy'] . "\n"; echo "Ref: " . $result['ref'] . "\n";

7. USDT ni yuboring

AQSh dollarini yuborish
// Energy is now delegated. Send USDT. $contract = $tron->contract($usdt); $transfer = $contract->transfer($delegateTo, 10 * pow(10, 6)); echo "USDT sent: " . $transfer . "\n";

Xatolarni boshqarish

Da&#39;vo chaqiruvini kichik qayta urinish yordamchisiga o&#39;rang. Eng keng tarqalgan xatolik payment_verification_failed tx hali zanjirda indekslanmagan bo&#39;lsa - bir necha soniya kuting va bir marta qayta urinib ko&#39;ring.

xatolarni boshqarish
function claimDelegation($api, $txHash, $delegateTo, $signature, $retries = 3) { for ($i = 0; $i < $retries; $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; // Success } switch ($result['error']) { case 'payment_verification_failed': // Most common: tx not yet indexed. Wait and retry. sleep(3); continue 2; case 'hash_already_used': throw new Exception('This tx hash has already been claimed'); case 'signature_mismatch': throw new Exception('Signer does not match payment sender. Sign with the same wallet that sent TRX.'); case 'delegation_failed': // Refund queued automatically if payment was verified throw new Exception('Delegation failed: ' . $result['message']); default: throw new Exception($result['message'] ?? 'Unknown error'); } } throw new Exception('Transaction not found after retries'); }

To&#39;liq misol

delegate-energy.php
<?php require_once 'vendor/autoload.php'; use IEXBase\TronAPI\Tron; $tron = new Tron(); $tron->setPrivateKey(getenv('TRON_PRIVATE_KEY')); $tron->setAddress(getenv('TRON_WALLET_ADDRESS')); $api = 'https://api.tronnrg.com'; $addr = 'TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx'; try { $delegateTo = 'TRecipientWallet'; $trxAmount = 4; // min 4, max 1000 — energy = trxAmount × 16,250 // 1. Send TRX (linear pricing: 16,250 energy per TRX) $payment = $tron->sendTrx($addr, $trxAmount); $txHash = $payment['txid']; echo "Payment: ${txHash}\n"; // 2. Sign via Node helper (see Step 5 above) $signature = trim(shell_exec( sprintf('node sign.js %s %s', escapeshellarg($txHash), escapeshellarg($delegateTo) ) )); if (!$signature) throw new Exception('Signing failed'); // 3. Claim delegation (with retry) $result = claimDelegation($api, $txHash, $delegateTo, $signature); echo "Energy: " . $result['energy'] . "\n"; echo "Ref: " . $result['ref'] . "\n"; // 4. Send USDT (energy is now available) $contract = $tron->contract('TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'); $transfer = $contract->transfer($delegateTo, 10 * pow(10, 6)); echo "USDT sent: ${transfer}\n"; } catch (Exception $e) { echo "Error: " . $e->getMessage() . "\n"; }
Telegram WhatsApp