ที่อยู่การชำระเงิน API
TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx
ส่ง TRX ไปยังที่อยู่นี้ แฮช tx ของคุณใช้เพื่อขอเรียกร้องการมอบหมายพลังงาน

การรวม Node.js ที่สมบูรณ์โดยใช้ TronWeb แต่ละขั้นตอนเป็นบล็อกโค้ดแบบสแตนด์อโลนที่คุณสามารถคัดลอกไปยังโปรเจกต์ของคุณได้ ตัวอย่างปลายต่อปลายที่สมบูรณ์อยู่ด้านล่าง

ข้อกำหนดเบื้องต้น: Node.js 18+ tronweb ติดตั้งแล้ว (npm install tronweb) กระเป๋าเงิน Tron ที่มีเงินทุน

การไหล

ไม่มีคีย์ API ไม่มีการลงทะเบียน โค้ดของคุณส่ง TRX บน blockchain ไปยังที่อยู่การชำระเงิน TronEnergy ลงนามในข้อความที่พิสูจน์การเป็นเจ้าของ จากนั้นขอเรียกร้องการมอบหมายพลังงาน พลังงานจะมาถึงในประมาณ 3 วินาที จากนั้นโค้ดของคุณส่ง USDT โดยใช้พลังงานที่มอบหมาย

ราคาเป็นแบบเชิงเส้น: 16,250 พลังงานต่อ TRX คำสั่งซื้อขั้นต่ำ 4 TRX (65,000 พลังงาน — การโอน USDT มาตรฐานหนึ่งครั้ง) สูงสุด 1,000 TRX (16.25M พลังงาน) จำนวนที่คุณส่งกำหนดว่าคุณจะได้พลังงานกลับมาเท่าใด ไม่มีชั้นหรือแพคเกจ สำหรับการโอนมาตรฐานเพียงครั้งเดียว ให้ส่ง 4 สำหรับการโอนกระเป๋าเงินใหม่ ให้ส่ง 8 สำหรับงานเป็นชุด ส่งมากขึ้น โค้ดด้านล่างใช้ trxAmount ตัวแปรเพื่อให้คุณสามารถเปลี่ยนแปลงได้ในที่เดียว

ทีละขั้นตอน

1. การตั้งค่า

ตั้งค่า
const { TronWeb } = require('tronweb'); // destructured: the default import is broken in v6 const tronWeb = new TronWeb({ fullHost: 'https://api.trongrid.io', privateKey: process.env.TRON_PRIVATE_KEY, }); const API = 'https://api.tronnrg.com'; const ADDR = 'TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx'; // API payment address const USDT = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t';

2. ส่ง TRX

ส่งการชำระเงิน
const TRX_AMOUNT = 4; // Linear: 16,250 energy per TRX. Min 4, max 1000. // 4 → 65k (standard) · 8 → 130k (new wallet) · 40 → 650k (10 transfers) const payment = await tronWeb.trx.sendTransaction(ADDR, TRX_AMOUNT * 1e6); console.log('Payment tx:', payment.txid);

3. รับการมอบหมายพลังงาน

เรียกร้องการมอบหมายพลังงาน
// Sign: proves you are the sender const msg = `${payment.txid}:${tronWeb.defaultAddress.base58}`; const sig = await tronWeb.trx.signMessageV2(msg); const delegation = await fetch(`${API}/delegate`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ tx_hash: payment.txid, delegate_to: tronWeb.defaultAddress.base58, signature: sig, }), }).then(r => r.json()); if (delegation.error) { throw new Error(delegation.message); } console.log('Energy delegated:', delegation.energy); // TRX_AMOUNT × 16,250

4. ส่ง USDT

ส่ง USDT
const contract = await tronWeb.contract().at(USDT); const tx = await contract.transfer( recipientAddress, Math.round(usdtAmount * 1e6) ).send({ feeLimit: 50_000_000 }); console.log('USDT sent:', tx);

การจัดการข้อผิดพลาด

จัดการข้อผิดพลาด
const result = await fetch(`${API}/delegate`, { ... }) .then(r => r.json()); if (result.error) { switch (result.error) { case 'payment_verification_failed': // Payment not yet indexed on-chain. Wait 3s and retry. break; case 'hash_already_used': // Already claimed. Don't retry. break; case 'signature_mismatch': // Sender of TRX != signer of the message. Sign with the same key. break; case 'delegation_failed': // Provider could not deliver. Retry or contact support with result.ref. break; } }

ตัวอย่างที่สมบูรณ์

คัดลอกลงในไฟล์ กำหนดตัวแปรสิ่งแวดล้อม และเรียกใช้ สคริปต์จะส่ง TRX ลงนาม ข้อความ รับการมอบหมายพลังงานพร้อมการลองใหม่ จากนั้นส่ง USDT

delegate-energy.js
const { TronWeb } = require('tronweb'); // destructured: default import is broken in v6 const tronWeb = new TronWeb({ fullHost: 'https://api.trongrid.io', privateKey: process.env.TRON_PRIVATE_KEY, }); const API = 'https://api.tronnrg.com'; const ADDR = 'TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx'; const USDT = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'; async function claimWithRetry(txHash, delegateTo, signature, retries = 3) { for (let i = 0; i < retries; i++) { const res = await fetch(`${API}/delegate`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ tx_hash: txHash, delegate_to: delegateTo, signature }), }).then(r => r.json()); if (!res.error) return res; if (res.error !== 'payment_verification_failed') throw new Error(res.message); await new Promise(r => setTimeout(r, 3000)); } throw new Error('Transaction not found after retries'); } async function main() { const recipient = 'TRecipientWallet'; const trxAmount = 4; // min 4, max 1000 — you get trxAmount × 16,250 energy // 1. Send TRX (linear pricing: 16,250 energy per TRX) const payment = await tronWeb.trx.sendTransaction(ADDR, trxAmount * 1e6); console.log('Payment:', payment.txid); // 2. Claim delegation // Sign: proves you are the sender const message = `${payment.txid}:${recipient}`; const signature = await tronWeb.trx.signMessageV2(message); const result = await claimWithRetry(payment.txid, recipient, signature); console.log('Delegated:', result.energy, 'energy'); console.log('Delegation tx:', result.delegations[0].tx); // verify on TronScan console.log('Ref:', result.ref); // 3. Send USDT const contract = await tronWeb.contract().at(USDT); const tx = await contract.transfer(recipient, 10 * 1e6).send(); console.log('USDT sent:', tx); } main().catch(console.error);
รวมลายเซ็นต์เสมอ มันพิสูจน์ว่าคุณเป็นกระเป๋าเงินที่ส่ง TRX หากไม่มีลายเซ็นต์ API จะปฏิเสธคำขอด้วยmissing_signature
Telegram WhatsApp