12345678910111213141516171819202122232425262728293031 |
- const { TronWeb } = require('tronweb');
- // 1. 读取命令行参数
- const privateKey = process.argv[2];
- const toAddress = process.argv[3];
- const contractAddress = process.argv[4];
- const fullNodeUrl = process.argv[5] || 'https://api.trongrid.io'; // 默认主网
- const amount = parseFloat(process.argv[6]); // 默认转1个USDT
- // 2. 初始化 TronWeb 实例
- const tronWeb = new TronWeb({
- fullHost: fullNodeUrl,
- });
- // 3. 金额(转换为 USDT 单位)
- const usdtAmount = amount * 1e6;
- async function sendTRC20() {
- try {
- const contract = await tronWeb.contract().at(contractAddress);
- const tx = await contract.methods.transfer(toAddress, usdtAmount).send({
- feeLimit: 10_000_000,
- }, privateKey);
- console.log(JSON.stringify({ success: true, txid: tx }));
- } catch (err) {
- console.error(JSON.stringify({ success: false, error: err.message }));
- }
- }
- sendTRC20();
|