ĐỊA CHỈ THANH TOÁN API
TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx
Gửi TRX đến địa chỉ này. Hash giao dịch của bạn được dùng để nhận ủy quyền năng lượng.

Tích hợp Python hoàn chỉnh bằng tronpy. Mỗi bước là một khối mã độc lập mà bạn có thể sao chép vào dự án của mình. Ví dụ từ đầu đến cuối nằm ở phía dưới.

Yêu cầu: Python 3.8+, tronpy được cài đặt (pip install tronpy), một ví Tron được tài trợ.

Quy trình

Không cần khoá API. Không cần đăng ký. Mã của bạn gửi TRX trên chuỗi đến địa chỉ thanh toán TronEnergy, ký một thông điệp chứng minh quyền sở hữu, rồi nhận ủy quyền năng lượng. Năng lượng đến trong khoảng 3 giây. Sau đó mã của bạn gửi USDT bằng năng lượng được ủy quyền.

Giá là tuyến tính: 16,250 Năng lượng trên mỗi TRX. Đơn hàng tối thiểu 4 TRX (65,000 Năng lượng — một chuyển USDT tiêu chuẩn), tối đa 1,000 TRX (16.25M Năng lượng). Số tiền bạn gửi xác định chính xác bao nhiêu Năng lượng quay lại — không có cấp độ hoặc gói. Để chuyển tiêu chuẩn duy nhất, gửi 4. Để chuyển ví mới, gửi 8. Để công việc hàng loạt, gửi nhiều hơn. Mã dưới đây sử dụng biến TRX_AMOUNT để bạn có thể thay đổi nó ở một nơi.

Từng bước

1. Thiết lập

thiết lập
import os, requests from tronpy import Tron from tronpy.keys import PrivateKey, keccak256 from coincurve import PrivateKey as CCKey # tronpy already depends on coincurve client = Tron() # mainnet — pass HTTPProvider(api_key=...) to avoid rate limits priv = PrivateKey(bytes.fromhex(os.environ['TRON_PRIVATE_KEY'])) sender = priv.public_key.to_base58check_address() API = 'https://api.tronnrg.com' ADDR = 'TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx' # API payment address USDT = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'

2. Gửi TRX

gửi thanh toán
TRX_AMOUNT = 4 # Linear: 16,250 energy per TRX. Min 4, max 1000. # 4 → 65k (standard) · 8 → 130k (new wallet) · 40 → 650k (10 transfers) payment = ( client.trx.transfer(sender, ADDR, TRX_AMOUNT * 1_000_000) .build().sign(priv).broadcast() ) print('Payment tx:', payment.txid)

3. Nhận Ủy Quyền Năng Lượng

yêu cầu ủy quyền năng lượng
# Sign: proves you are the sender. Must equal TronWeb signMessageV2 exactly: # keccak256("\x19TRON Signed Message:\n" + len + msg), secp256k1, v = rec + 27. def sign_message_v2(message, priv): msg = message.encode() prefix = b"\x19TRON Signed Message:\n" + str(len(msg)).encode() digest = keccak256(prefix + msg) raw = CCKey(priv.to_bytes()).sign_recoverable(digest, hasher=None) return '0x' + (raw[:64] + bytes([raw[64] + 27])).hex() msg = f"{payment.txid}:{sender}" sig = sign_message_v2(msg, priv) delegation = requests.post(f"{API}/delegate", json={ 'tx_hash': payment.txid, 'delegate_to': sender, 'signature': sig, }).json() if delegation.get('error'): raise Exception(delegation['message']) print('Energy delegated:', delegation['energy']) # TRX_AMOUNT × 16,250

4. Gửi USDT

gửi USDT
recipient = 'TRecipientWallet' contract = client.get_contract(USDT) tx = ( contract.functions.transfer(recipient, 10 * 1_000_000) .with_owner(sender).fee_limit(50_000_000) .build().sign(priv).broadcast() ) print('USDT sent:', tx.txid)

Xử Lý Lỗi

xử lý lỗi
result = requests.post(f"{API}/delegate", json=payload).json() if result.get('error'): err = result['error'] if err == 'payment_verification_failed': pass # Payment not yet indexed on-chain. Wait 3s and retry. elif err == 'hash_already_used': pass # Already claimed. Do not retry. elif err == 'signature_mismatch': pass # Sender of TRX != signer of the message. Sign with the same key. elif err == 'delegation_failed': pass # Provider could not deliver. Retry or contact support with result['ref'].

Ví Dụ Hoàn Chỉnh

Sao chép vào một tệp, đặt biến môi trường TRON_PRIVATE_KEY, và chạy nó. Script sẽ gửi TRX, ký thông điệp, nhận ủy quyền năng lượng với thử lại, rồi gửi USDT.

delegate_energy.py
import os, time, requests from tronpy import Tron from tronpy.keys import PrivateKey, keccak256 from coincurve import PrivateKey as CCKey client = Tron() # mainnet — pass HTTPProvider(api_key=...) to avoid rate limits priv = PrivateKey(bytes.fromhex(os.environ['TRON_PRIVATE_KEY'])) sender = priv.public_key.to_base58check_address() API = 'https://api.tronnrg.com' ADDR = 'TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx' USDT = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t' # Signature must match TronWeb signMessageV2 byte-for-byte. def sign_message_v2(message, priv): msg = message.encode() prefix = b"\x19TRON Signed Message:\n" + str(len(msg)).encode() digest = keccak256(prefix + msg) raw = CCKey(priv.to_bytes()).sign_recoverable(digest, hasher=None) return '0x' + (raw[:64] + bytes([raw[64] + 27])).hex() def claim_with_retry(tx_hash, delegate_to, signature, retries=3): for _ in range(retries): res = requests.post(f"{API}/delegate", json={ 'tx_hash': tx_hash, 'delegate_to': delegate_to, 'signature': signature, }).json() if not res.get('error'): return res if res['error'] != 'payment_verification_failed': raise Exception(res['message']) time.sleep(3) raise Exception('Transaction not found after retries') def main(): recipient = 'TRecipientWallet' trx_amount = 4 # min 4, max 1000 — you get trx_amount × 16,250 energy # 1. Send TRX (linear pricing: 16,250 energy per TRX) payment = ( client.trx.transfer(sender, ADDR, trx_amount * 1_000_000) .build().sign(priv).broadcast() ) print('Payment:', payment.txid) # 2. Claim delegation (the signature proves you sent the TRX) signature = sign_message_v2(f"{payment.txid}:{recipient}", priv) result = claim_with_retry(payment.txid, recipient, signature) print('Delegated:', result['energy'], 'energy') print('Delegation tx:', result['delegations'][0]['tx']) # verify on TronScan print('Ref:', result['ref']) # 3. Send USDT using the delegated energy contract = client.get_contract(USDT) tx = ( contract.functions.transfer(recipient, 10 * 1_000_000) .with_owner(sender).fee_limit(50_000_000) .build().sign(priv).broadcast() ) print('USDT sent:', tx.txid) if __name__ == '__main__': main()
Luôn bao gồm chữ ký. Nó chứng minh bạn là ví đã gửi TRX. Nếu không có nó, API sẽ từ chối yêu cầu với missing_signature.
Telegram WhatsApp