API 支付地址
TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx
向此地址发送 TRX。您的交易哈希用于领取能量委托。

使用 tronpy 的完整 Python 集成。每个步骤都是独立的代码块,您可以复制到项目中。完整的端到端示例在底部。

前置要求: Python 3.8+、tronpy 已安装(pip install tronpy),以及一个有资金的 TRON 钱包。

工作流程

无需 API 密钥。无需注册。您的代码在链上向 TronEnergy 支付地址发送 TRX,签名证明所有权,然后领取委托能量。能量将在约 3 秒内到达。然后您的代码使用委托能量发送 USDT。

定价是线性的:每 TRX 对应 16,250 能量。 最小订单 4 TRX(65,000 能量 — 一次标准 USDT 转账),最大 1,000 TRX(1,625 万能量)。您发送的金额决定了返回的能量数量 — 没有分级或套餐。单次标准转账,发送 4 TRX。新钱包转账,发送 8 TRX。批量工作,发送更多。下面的代码使用 TRX_AMOUNT 变量,便于在一个地方修改。

分步说明

1. 设置

设置
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. 发送 TRX

发送付款
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. 领取委托能量

领取委托
# 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. 发送 USDT

发送 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)

错误处理

错误处理
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'].

完整示例

将此代码复制到文件中,设置 TRON_PRIVATE_KEY 环境变量,然后运行。该脚本会发送 TRX、签名、重试领取委托能量,然后发送 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()
始终包含签名。 它证明您是发送 TRX 的钱包。没有它,API 会以 missing_signature 拒绝请求。
Telegram WhatsApp