⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

wallet/freezebalancev2

Resource Management V2

Dwellir's TRON infrastructure supports the latest Stake 2.0 mechanism for efficient resource management. Stake TRX to get bandwidth/energy while earning rewards and voting rights.

Start staking TRX →

Freeze (stake) TRX balance to obtain bandwidth or energy resources using the Stake 2.0 mechanism. Staked TRX earns rewards and provides voting power for Super Representatives.

Use Cases

wallet/freezebalancev2 is essential for:

  • Resource Acquisition - Get bandwidth for transactions
  • Energy Generation - Power smart contract interactions
  • Reward Earning - Earn staking rewards (~4-7% APR)
  • Governance Participation - Gain voting power for SRs
  • DApp Operations - Ensure smooth contract execution

Parameters

ParameterTypeRequiredDescription
owner_addressstringYesAddress staking TRX (Base58 or Hex)
frozen_balancenumberYesAmount to stake in SUN (1 TRX = 1,000,000 SUN)
resourcestringYesResource type: "BANDWIDTH" or "ENERGY"
visiblebooleanNoUse Base58 format (default: true)
permission_idnumberNoPermission ID for multi-sig accounts

Request Example

{
"owner_address": "TRX6Q82wMqWNbCCmJPLz9mR8AZwqvUU2pN",
"frozen_balance": 10000000000,
"resource": "ENERGY",
"visible": true
}

Response Fields

FieldTypeDescription
txidstringTransaction ID
visiblebooleanAddress format used
raw_dataobjectTransaction raw data
raw_data.contractarrayContract details
raw_data.ref_block_bytesstringReference block bytes
raw_data.ref_block_hashstringReference block hash
raw_data.expirationnumberTransaction expiration time
raw_data.timestampnumberTransaction timestamp

Implementation Examples

# Freeze TRX for ENERGY
curl -X POST "https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/freezebalancev2" \
-H "Content-Type: application/json" \
-d '{
"owner_address": "TRX6Q82wMqWNbCCmJPLz9mR8AZwqvUU2pN",
"frozen_balance": 10000000000,
"resource": "ENERGY",
"visible": true
}'

# Freeze TRX for BANDWIDTH
curl -X POST "https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/freezebalancev2" \
-H "Content-Type: application/json" \
-d '{
"owner_address": "TRX6Q82wMqWNbCCmJPLz9mR8AZwqvUU2pN",
"frozen_balance": 5000000000,
"resource": "BANDWIDTH",
"visible": true
}'

# Parse response with jq
curl -s -X POST "https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/freezebalancev2" \
-H "Content-Type: application/json" \
-d '{
"owner_address": "TRX6Q82wMqWNbCCmJPLz9mR8AZwqvUU2pN",
"frozen_balance": 10000000000,
"resource": "ENERGY",
"visible": true
}' | jq '{
txid: .txid,
resource: .raw_data.contract[0].parameter.value.resource,
amount_sun: .raw_data.contract[0].parameter.value.frozen_balance,
amount_trx: (.raw_data.contract[0].parameter.value.frozen_balance / 1000000),
expiration: .raw_data.expiration
}'

# Script to calculate and stake optimal amounts
#!/bin/bash
API_KEY="YOUR_API_KEY"
ADDRESS="TRX6Q82wMqWNbCCmJPLz9mR8AZwqvUU2pN"

# Function to stake TRX
stake_trx() {
local amount_sun=$1
local resource=$2

echo "Staking $((amount_sun / 1000000)) TRX for $resource..."

response=$(curl -s -X POST \
"https://api-tron-mainnet.n.dwellir.com/$API_KEY/wallet/freezebalancev2" \
-H "Content-Type: application/json" \
-d "{
\"owner_address\": \"$ADDRESS\",
\"frozen_balance\": $amount_sun,
\"resource\": \"$resource\",
\"visible\": true
}")

txid=$(echo "$response" | jq -r '.txid')

if [ "$txid" != "null" ]; then
echo "✓ Transaction created: $txid"
echo " Please sign and broadcast this transaction"
else
echo "✗ Failed to create transaction"
echo "$response" | jq .
fi
}

# Calculate resources needed
echo "=== Resource Staking Calculator ==="
echo

read -p "Daily transactions expected: " daily_tx
read -p "Daily smart contract calls expected: " daily_contracts

# Calculate requirements (approximate)
bandwidth_needed=$((daily_tx * 250))
energy_needed=$((daily_contracts * 50000))

trx_for_bandwidth=$((bandwidth_needed / 1000))
trx_for_energy=$((energy_needed / 280))

echo
echo "Resource Requirements:"
echo " Bandwidth needed: $bandwidth_needed"
echo " Energy needed: $energy_needed"
echo
echo "TRX to stake:"
echo " For Bandwidth: $trx_for_bandwidth TRX"
echo " For Energy: $trx_for_energy TRX"
echo " Total: $((trx_for_bandwidth + trx_for_energy)) TRX"
echo

read -p "Proceed with staking? (y/n): " confirm

if [ "$confirm" = "y" ]; then
# Convert to SUN and stake
stake_trx $((trx_for_bandwidth * 1000000)) "BANDWIDTH"
sleep 2
stake_trx $((trx_for_energy * 1000000)) "ENERGY"
fi

Response Example

Successful Response

{
"visible": true,
"txID": "7a2e5c8f9b3d1a4e6f8c2b5d9e1a3f7c4b8d2e6a9c3f5b8d1e4a7c9f2b5d8e",
"raw_data": {
"contract": [
{
"parameter": {
"value": {
"owner_address": "TRX6Q82wMqWNbCCmJPLz9mR8AZwqvUU2pN",
"frozen_balance": 10000000000,
"resource": "ENERGY"
},
"type_url": "type.googleapis.com/protocol.FreezeBalanceV2Contract"
},
"type": "FreezeBalanceV2Contract"
}
],
"ref_block_bytes": "7ac7",
"ref_block_hash": "4d9bb8f8c9c59ac3",
"expiration": 1702456849000,
"timestamp": 1702456789000,
"fee_limit": 1000000000
},
"raw_data_hex": "0a0207ac722..."
}

Common Use Cases

1. Auto-Staking System

class AutoStakingSystem {
constructor(apiKey) {
this.staking = new TronStakingManager(apiKey);
this.minBalance = 1000; // Minimum TRX to keep unstaked
}

async autoStake(address, keepBalance = 1000) {
// Get current balance
const account = await this.getAccount(address);
const availableTRX = (account.balance / 1_000_000) - keepBalance;

if (availableTRX <= 0) {
return { message: 'Insufficient balance for staking' };
}

// Split 30% bandwidth, 70% energy (typical DApp usage)
const bandwidthTRX = Math.floor(availableTRX * 0.3);
const energyTRX = Math.floor(availableTRX * 0.7);

return await this.staking.stakeForResources(
address,
bandwidthTRX,
energyTRX
);
}
}

2. Resource Optimization

async function optimizeResources(address) {
const resources = await getAccountResource(address);

// Check utilization
const bandwidthUtil = resources.freeNetUsed / resources.freeNetLimit;
const energyUtil = resources.EnergyUsed / resources.EnergyLimit;

const recommendations = [];

if (bandwidthUtil > 0.8) {
recommendations.push({
action: 'STAKE',
resource: 'BANDWIDTH',
reason: 'High bandwidth utilization',
suggestedTRX: 1000
});
}

if (energyUtil > 0.8) {
recommendations.push({
action: 'STAKE',
resource: 'ENERGY',
reason: 'High energy utilization',
suggestedTRX: 5000
});
}

return recommendations;
}

3. Staking Pool Management

class StakingPool {
async distributeStakes(participants, totalTRX) {
const stakes = [];

for (const participant of participants) {
const share = (participant.contribution / 100) * totalTRX;

stakes.push({
address: participant.address,
amount: share,
resource: participant.preferredResource || 'ENERGY'
});
}

return this.executeStakes(stakes);
}
}

Resource Calculation

ResourceRateUsage
Bandwidth~1,000 per TRXRegular transactions
Energy~280 per TRXSmart contract calls
Voting Power1 vote per TRXSR voting

Staking Recommendations by Use Case

Use CaseBandwidth (TRX)Energy (TRX)Total
Basic Wallet1000100
DeFi User5005,0005,500
DApp Developer1,00020,00021,000
Exchange10,00050,00060,000

Error Handling

Error CodeDescriptionSolution
INVALID_RESOURCEInvalid resource typeUse "BANDWIDTH" or "ENERGY"
INSUFFICIENT_BALANCENot enough TRXCheck balance before staking
ACCOUNT_NOT_FOUNDAddress doesn't existVerify address validity
TAPOS_ERRORTransaction expiredRecreate with fresh block reference
async function safeStake(address, amount, resource) {
try {
// Check balance first
const account = await getAccount(address);
const balance = account.balance / 1_000_000;

if (balance < amount) {
throw new Error(`Insufficient balance: ${balance} TRX available`);
}

// Validate resource type
if (!['BANDWIDTH', 'ENERGY'].includes(resource)) {
throw new Error(`Invalid resource: ${resource}`);
}

// Create and return transaction
return await createFreezeTransaction(address, amount, resource);

} catch (error) {
console.error('Staking error:', error);
return {
success: false,
error: error.message
};
}
}

Best Practices

  1. Keep Reserve - Always keep 50-100 TRX unstaked for fees
  2. Balance Resources - Monitor usage and adjust stakes accordingly
  3. Batch Operations - Stake for both resources in one session
  4. Monitor Rewards - Track staking rewards and compound regularly
  5. Plan Unstaking - Remember 14-day waiting period for unstaking

Notes

  • Lock Period: Staked TRX has a minimum 14-day lock period
  • Rewards: Staking rewards are distributed every 6 hours
  • Voting Power: Staked TRX provides voting power for Super Representatives
  • Resource Recovery: Bandwidth recovers 24 hours, energy recovers based on consumption

Need help? Contact support or visit our TRON documentation.