We want to freeze the available balance on Tron Blockchain account: this involves first getting available balance using TronWeb NodeJs Library, and then build a transaction using the Transaction Builder, sign the Transaction, and finally broadcast it.
You can get a Free API Key on TronGrid. And you can install the tronweb library using npm.
See following NodeJs code that freeze available balance on the given Tron wallet - you can do this every 24 hours.
const TrxAccount = "TL3SEY2dn4VfXXXXXXXXXXXXXXXXXXXXX5nte";
const AppKey = 'Tron-Grid-App-Key'
const privateKey = 'Private Key';
const TronWeb = require('tronweb');
const tronWeb = new TronWeb({
fullHost: 'https://api.trongrid.io',
headers: { "TRON-PRO-API-KEY": AppKey },
privateKey: privateKey,
});
function getBalance(acc) {
return new Promise((resolve, reject) => {
tronWeb.trx.getBalance(acc).then(result => {
resolve(result);
})
});
}
(async function() {
const sun = await(getBalance(TrxAccount));
const trx = tronWeb.fromSun(sun);
console.log("Balance of SUN = " + sun + " or " + trx + " TRX");
if (trx >= 1) {
const trans = await tronWeb.transactionBuilder.freezeBalance(sun, 3, "ENERGY", TrxAccount, TrxAccount, 1);
const signedtxn = await tronWeb.trx.sign(trans, privateKey);
const receipt = await tronWeb.trx.sendRawTransaction(signedtxn);
console.log(receipt);
console.log(trx + " TRX frozon!");
} else {
console.log("Not enough to Freeze!")
}
})();
The balance is in the unit of SUN - which you can convert to TRX using tronWeb.fromSun. And the amount needs to be at last 1 TRX to freeze.
Example output:
Balance of SUN = 12301995 or 12.301995 TRX
{ result: true,
txid:
'77c74b7e76c12a61f10XXXXXXXXXXXXXXXXXXXXXXXXXX0f6829b74ed',
transaction:
{ visible: false,
txID:
'77c74b7e76c12a61f10XXXXXXXXXXXXX5d0656e0f6829b74ed',
raw_data:
{ contract: [Array],
ref_block_bytes: '356b',
ref_block_hash: '5aad1c587783fe84',
expiration: 1623501405000,
timestamp: 1623501348040 },
raw_data_hex:
'0a023XXXXXXXXXXXXXXXXXXXXXXXXXXXX1a02f',
signature:
[ '5316c2f09XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXda4c01' ] } }
12.301995 TRX frozon!
Reposted to Blog
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Thank you for reading ^^^^^^^^^^^^^^^
NEW! Following my Trail (Upvote or/and Downvote)
Follow me for topics of Algorithms, Blockchain and Cloud.
I am @justyy - a Steem Witness
https://steemyy.com
My contributions
- Video Downloader
- Steem Blockchain Tools
- Free Cryptos API
- VPS Database
- Computing Technology Blog
- A few useless tools
- And some other online software/tools
- Merge Files/Videos
- LOGO Turtle Programming Chrome Extension
- Teaching Kids Programming - Youtube Channel and All Contents
Delegation Service
Support me
If you like my work, please:
- Buy Me a Coffee, Thanks!
- Become my Sponsor, Thanks!
- Voting for me:
https://steemit.com/~witnesses type in justyy and click VOTE
- Delegate SP: https://steemyy.com/sp-delegate-form/?delegatee=justyy
- Vote @justyy as Witness: https://steemyy.com/witness-voting/?witness=justyy&action=approve
- Set @justyy as Proxy: https://steemyy.com/witness-voting/?witness=justyy&action=proxy
Alternatively, you can vote witness or set proxy here: https://steemit.com/~witnesses
https://steemit.com/hive-101145/@grateful-life/2021-6-12-gratitude-journal-june-12th-2021
Hi justyy. You have missed one of my post.
Could you please check?
Thank you.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Your original post was deleted or renamed thus the voting were failed . Anyway, giving you a upvote here.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I see. Thanks for the reply.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit