PHP WebShell
Текущая директория: /var/www/bitcardoApp
Просмотр файла: tron_send_onefile.js
#!/usr/bin/env node
'use strict';
/**
* tron_send_onefile.js
* Single-file TRON broadcaster (TRX + USDT-TRC20).
*
* Usage examples:
* TRX:
* node tron_send_onefile.js --network https://api.trongrid.io --apiKey YOURKEY --pk YOUR_PRIVATE_KEY --to T... --coin TRX --amount 1.25
*
* USDT (TRC20):
* node tron_send_onefile.js --network https://api.trongrid.io --apiKey YOURKEY --pk YOUR_PRIVATE_KEY --to T... --coin USDT --amount 5.5 --contract YOUR_USDT_CONTRACT
*
* Notes:
* - Outputs JSON only (stdout).
* - Any debug/error details are also included in JSON (no console.log noise).
*/
const TronWebPkg = require('tronweb');
const TronWeb =
(TronWebPkg && TronWebPkg.TronWeb) ? TronWebPkg.TronWeb :
(TronWebPkg && TronWebPkg.default) ? TronWebPkg.default :
TronWebPkg;
function out(obj) {
process.stdout.write(JSON.stringify(obj));
}
function getArg(name) {
const idx = process.argv.indexOf(`--${name}`);
if (idx === -1) return null;
return process.argv[idx + 1] ?? null;
}
(async () => {
try {
const network = (getArg('network') || '').trim();
const apiKey = (getArg('apiKey') || '').trim();
let pk = (getArg('pk') || '').trim().replace(/^0x/i, '');
const to = (getArg('to') || '').trim();
const coinRaw = (getArg('coin') || '').trim().toUpperCase();
const amountStr = (getArg('amount') || '').trim();
const contract = (getArg('contract') || '').trim(); // USDT contract
const feeLimitSun = parseInt(getArg('feeLimitSun') || '15000000', 10); // 15 TRX default
if (!network) return out({ ok:false, error:'Missing --network' });
if (!pk) return out({ ok:false, error:'Missing --pk (private key)' });
if (!to) return out({ ok:false, error:'Missing --to' });
if (!coinRaw) return out({ ok:false, error:'Missing --coin (TRX or USDT)' });
if (!amountStr) return out({ ok:false, error:'Missing --amount' });
const amountNum = Number(amountStr);
if (!Number.isFinite(amountNum) || amountNum <= 0) {
return out({ ok:false, error:'Invalid --amount', amount: amountStr });
}
const headers = {};
if (apiKey) headers['TRON-PRO-API-KEY'] = apiKey;
const tronWeb = new TronWeb({
fullHost: network,
privateKey: pk,
headers
});
if (!tronWeb.isAddress(to)) {
return out({ ok:false, error:'Invalid recipient address', to });
}
// Normalize coin name
const coin = (coinRaw === 'USDT-TRC20' || coinRaw === 'USDT_TRC20' || coinRaw === 'USDTTRC20')
? 'USDT'
: coinRaw;
if (coin === 'TRX') {
const sun = Math.floor(amountNum * 1e6);
if (!(sun > 0)) return out({ ok:false, error:'TRX amount too small after conversion', sun });
const tx = await tronWeb.transactionBuilder.sendTrx(to, sun);
const signed = await tronWeb.trx.sign(tx);
const receipt = await tronWeb.trx.sendRawTransaction(signed);
if (!receipt || receipt.result !== true) {
return out({ ok:false, error:'TRX broadcast failed', receipt });
}
return out({ ok:true, coin:'TRX', txid: receipt.txid, receipt });
}
if (coin === 'USDT') {
if (!contract) return out({ ok:false, error:'Missing --contract for USDT' });
// USDT on TRON is typically 6 decimals
const amountInt = Math.floor(amountNum * 1e6);
if (!(amountInt > 0)) return out({ ok:false, error:'USDT amount too small after conversion', amountInt });
const ctr = await tronWeb.contract().at(contract);
// This sends a contract tx; tronweb usually returns txid string
const txid = await ctr.transfer(to, amountInt).send({
feeLimit: feeLimitSun,
shouldPollResponse: false
});
if (!txid || typeof txid !== 'string') {
return out({ ok:false, error:'USDT broadcast failed', txid });
}
return out({ ok:true, coin:'USDT', txid, feeLimitSun });
}
return out({ ok:false, error:'Unsupported coin', coinRaw });
} catch (e) {
return out({ ok:false, error:'Exception', detail: String(e?.message || e) });
}
})();
Выполнить команду
Для локальной разработки. Не используйте в интернете!