In Tron Blockchain, you can freeze your TRX assets as either energy or bandwidth, and then vote for your preferred witnesses (or called SR = Super Representative).
Each SR has a different ratio of voting distribution, and you can claim the rewards for your witness votes.
With the following Javascript code – you can run it at NodeJs e.g. node or nodejs.
It will first make a API call to trongrid to withdraw-balance, and it will return a JSON – which needs to be properly signed with your private key, and then final step is to broadcast the signed transaction.
const TrxAccount = "Tron Account";
const AppKey = 'Your APP Key at Tron Grid'
const privateKey = 'Your Private Key (Active Key)';
const fetch = require('node-fetch');
const url = 'https://api.trongrid.io/wallet/withdrawbalance';
const TronWeb = require('tronweb');
const tronWeb = new TronWeb({
fullHost: 'https://api.trongrid.io',
headers: { "TRON-PRO-API-KEY": AppKey },
privateKey: privateKey,
});
async function claimRewards() {
const options = {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'TRON-PRO-API-KEY': AppKey,
},
body: JSON.stringify({owner_address: TrxAccount, visible: true})
};
const res = await fetch(url, options);
if (res.ok) {
return await (res.json());
}
}
(async function() {
const tx = await claimRewards();
if (tx.Error) {
console.log(tx.Error);
} else {
console.log(tx);
const signedtxn = await tronWeb.trx.sign(tx, privateKey);
const receipt = await tronWeb.trx.sendRawTransaction(signedtxn);
console.log(receipt);
}
})();
Please note that you can only claim (withdraw) balance/rewards once every 24 hours. For example:
$ node claim-witness-voting-rewards.js
{ visible: true,
txID:
'd0d64fbdc5bbXXXXXXXXXXXXXXXXXXXXXXXX2d6d8afa2d7c4e366ea',
raw_data:
{ contract: [ [Object] ],
ref_block_bytes: '37e4',
ref_block_hash: '94da0dbee6007793',
expiration: 1623503307000,
timestamp: 1623503250641 },
raw_data_hex:
'0a0237e4220894daXXXXXXXXXXXXXXXXXXXXXXXXXXXXXa15416e7df7ae2caadc4d984697cf6dd3d483dc9fcce370d1c9d682a02f' }
{ result: true,
txid:
'd0d64fbdc5bbfd009674490e101a5XXXXXXXXXXXXXd7c4e366ea',
transaction:
{ visible: true,
txID:
'd0d64fbdc5bbfXXXXXXXXXXXXXXXXXXXXXXXXX7c4e366ea',
raw_data:
{ contract: [Array],
ref_block_bytes: '37e4',
ref_block_hash: '94da0dbee6007793',
expiration: 1623503307000,
timestamp: 1623503250641 },
raw_data_hex:
'0a0237e42208XXXXXXXXXXXXXXXXXXXXXXX416e7df7ae2caadc4d984697cf6dd3d483dc9fcce370d1c9d682a02f',
signature:
[ '19e22bbcf0caeXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0755ba72c49cf1d8b594e01' ] } }
$ node claim-witness-voting-rewards.js
{ Error:
'class org.tron.core.exception.ContractValidateException : The last withdraw time is 1623503250000, less than 24 hours' }
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 - Breadth First Search Algorithm to Find Bottom Left Tree Value
Next Post: GoLang: Find Bottom Left Tree Value via Depth First Search or Breadth First Search Algorithm
