Automate Freeze Balance on Tron Blockchain using NodeJs with TronWeb/TronGrid

in #programming6 months ago (edited)

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: '',
    headers: { "TRON-PRO-API-KEY": AppKey },
    privateKey: privateKey,

function getBalance(acc) {
    return new Promise((resolve, reject) => {
        tronWeb.trx.getBalance(acc).then(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(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,
   { visible: false,
      { contract: [Array],
        ref_block_bytes: '356b',
        ref_block_hash: '5aad1c587783fe84',
        expiration: 1623501405000,
        timestamp: 1623501348040 },
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

My contributions

Delegation Service

  1. Voting Algorithm Updated to Favor those High Delegations!
  • Delegate 1000 to justyy: Link
  • Delegate 5000 to justyy: Link
  • Delegate 10000 to justyy: Link

Support me

If you like my work, please:

  1. Delegate SP:
  2. Vote @justyy as Witness:
  3. Set @justyy as Proxy:
    Alternatively, you can vote witness or set proxy here:


Your original post was deleted or renamed thus the voting were failed . Anyway, giving you a upvote here.

I see. Thanks for the reply.

Coin Marketplace

STEEM 0.67
TRX 0.10
JST 0.075
BTC 57100.04
ETH 4674.41
BNB 640.59
SBD 7.23