Sending TRX coin on TRON blockchain is easy. We can use the TronWeb library and here is the Javascript function to send Trx to a Tron wallet address:
async function sendTrx(fromAddress, toAddress, amount, privateKey, AppKey) {
let headers = null;
if (AppKey) {
headers = { "TRON-PRO-API-KEY": AppKey };
}
const tronWeb = new TronWeb({
fullHost: 'https://api.shasta.trongrid.io',
headers: headers,
privateKey: privateKey,
});
const tradeobj = await tronWeb.transactionBuilder.sendTrx(
tronWeb.address.toHex(toAddress),
amount * 1000 * 1000,
tronWeb.address.toHex(fromAddress)
);
const signedtxn = await tronWeb.trx.sign(
tradeobj,
privateKey
);
const receipt = await tronWeb.trx.sendRawTransaction(
signedtxn
);
return receipt;
}
Example usage:
(async function() {
const fromAddress = "TL.....";
const toAddress = "TN.....";
const amount = 1.2;
const privateKey = "key";
const AppKey = "Tron Pro API Key - Optional";
await sendTrx(fromAddress, toAddress, amount, privateKey, AppKey);
})();
You can sign up on TronGrid and get 3 free api key if you need more quota of API usage. For testnets such as Shasta or Nile, you don’t need the Tron Pro API key.
Send USDT TRC-20 Token instead? How to Send/Transfer USDT on Tron Blockchain using Tronweb?
Tron Blockchain
- TRON Blockchain: How to Send the USDT (TRC-20) Transacton using Python tronpy?
- How to Get Balance of TRX or USDT/USDD/USDC (TRC-20) Smart Contract Tokens on TRON Blockchain?
- Function to Return the USDT/USDD/USDC Contract Address on Tron Blockchain (Main Net, Nile, Shasta)
- How to Send/Transfer USDT/USDD/USDC on Tron Blockchain using Tronweb?
- Javascript Function to Send Trx on Tron Blockchain based on TronWeb
- How to Generate an Account on Tron Blockchain using Python SDK?
- How to Claim the Witness (Super Representative) Voting Rewards on Tron Blockchain using Node Js (Javascript)?
- Automate Freeze Balance on Tron Blockchain using NodeJs with TronWeb/TronGrid
- Python Tool of Base58 Decode Check
- TRON Blockchain: How to Check the Number of Peers the Tron Node is Connected to?
- TRON Blockchain: How to Check If a Node is synchronized and Fully Functional?
- How to Activate a TRON (TRX) Blockchain Wallet Address?
- Delayed Swap due to Numeric Underflow Bug by using Tron’s triggerSmartContract Method
–EOF (The Ultimate Computing & Technology Blog) —
Last Post: Teaching Kids Programming - Permutation of K out of N Visible Blocks via Top Down Dynamic Programming Algorithm
Next Post: Teaching Kids Programming - Largest Unique Number via Hash Table, Bucket Sorting and GroupBy Algorithms
