Docs

wallet/getaccountresource - Get TRON Account Re...

Get TRON account bandwidth and energy resources for transaction fee optimization. Monitor resource usage and manage stake efficiently with Dwellir RPC.

Optimize Transaction Costs

Dwellir's TRON endpoints help you monitor and optimize bandwidth/energy usage for zero-fee transactions. Track resources in real-time to minimize transaction costs on TRON.

Monitor your resources

Retrieves detailed information about an account's bandwidth and energy resources on the TRON network. Essential for managing transaction costs and optimizing resource usage.

When to Use This Method

wallet/getaccountresource is essential for:

  • Resource Monitoring - Track bandwidth and energy consumption
  • Fee Optimization - Determine if transactions will be free or require TRX
  • Staking Strategy - Plan TRX staking for bandwidth/energy
  • Transaction Planning - Estimate resource requirements
  • Wallet Management - Display resource status to users

Implementation Examples

Response Examples

Normal Account with Resources

JSON
{
  "freeNetLimit": 5000,
  "freeNetUsed": 1234,
  "NetLimit": 10000,
  "NetUsed": 2500,
  "EnergyLimit": 150000,
  "EnergyUsed": 45000,
  "tronPowerLimit": 1000000,
  "assetNetUsed": [],
  "assetNetLimit": []
}

New Account (Minimal Resources)

JSON
{
  "freeNetLimit": 5000,
  "freeNetUsed": 0
}

Account with Token-Specific Bandwidth

JSON
{
  "freeNetLimit": 5000,
  "freeNetUsed": 500,
  "NetLimit": 5000,
  "NetUsed": 1000,
  "EnergyLimit": 100000,
  "EnergyUsed": 25000,
  "tronPowerLimit": 500000,
  "assetNetUsed": [
    {
      "key": "1000001",
      "value": 100
    }
  ],
  "assetNetLimit": [
    {
      "key": "1000001", 
      "value": 1000
    }
  ]
}

Common Use Cases

1. Wallet Resource Dashboard

JavaScript
class WalletResourceDashboard {
  constructor(apiKey) {
    this.analyzer = new TronResourceAnalyzer(apiKey);
    this.updateInterval = null;
  }
  
  async createDashboard(address) {
    const resourceStatus = await this.analyzer.getResourceStatus(address);
    
    return {
      address: address,
      lastUpdated: new Date().toISOString(),
      status: {
        bandwidth: {
          percentage: resourceStatus.bandwidth.total.usagePercent,
          remaining: resourceStatus.bandwidth.total.remaining,
          status: this.getStatusLevel(resourceStatus.bandwidth.total.usagePercent),
          resetTime: this.calculateBandwidthReset()
        },
        energy: {
          percentage: resourceStatus.energy.usagePercent,
          remaining: resourceStatus.energy.remaining,
          status: this.getStatusLevel(resourceStatus.energy.usagePercent)
        }
      },
      capabilities: {
        canMakeFreeTransfers: resourceStatus.canMakeFreeTransactions,
        canCallContracts: resourceStatus.energy.remaining > 0,
        recommendedActions: resourceStatus.recommendations
      },
      estimatedCosts: await this.getEstimatedCosts(address)
    };
  }
  
  getStatusLevel(percentage) {
    if (percentage < 50) return 'good';
    if (percentage < 80) return 'warning';
    return 'critical';
  }
  
  calculateBandwidthReset() {
    const now = new Date();
    const tomorrow = new Date(now);
    tomorrow.setDate(tomorrow.getDate() + 1);
    tomorrow.setHours(0, 0, 0, 0);
    return tomorrow.toISOString();
  }
  
  async getEstimatedCosts(address) {
    const [transfer, trc20, contract] = await Promise.all([
      this.analyzer.estimateTransactionCost(address, 'transfer'),
      this.analyzer.estimateTransactionCost(address, 'trc20Transfer'),
      this.analyzer.estimateTransactionCost(address, 'smartContract')
    ]);
    
    return { transfer, trc20, contract };
  }
}

2. Smart Contract Gas Optimizer

JavaScript
class TronGasOptimizer {
  constructor(apiKey) {
    this.analyzer = new TronResourceAnalyzer(apiKey);
  }
  
  async optimizeContractCall(address, estimatedEnergy) {
    const resourceStatus = await this.analyzer.getResourceStatus(address);
    const energyRemaining = resourceStatus.energy.remaining;
    
    if (energyRemaining >= estimatedEnergy) {
      return {
        strategy: 'use_staked_energy',
        cost: 0,
        message: 'Use existing staked energy - free transaction'
      };
    }
    
    const energyNeeded = estimatedEnergy - energyRemaining;
    const trxCost = energyNeeded * 0.00014;
    
    // Calculate different strategies
    const strategies = [
      {
        strategy: 'pay_with_trx',
        cost: trxCost,
        message: `Pay ${trxCost.toFixed(6)} TRX for energy`
      },
      {
        strategy: 'stake_trx',
        cost: energyNeeded / 4000, // Simplified ratio
        message: `Stake ${(energyNeeded / 4000).toFixed(2)} TRX for energy`,
        benefits: 'Reusable energy for future transactions'
      },
      {
        strategy: 'rent_energy',
        cost: trxCost * 0.7, // Assume 30% savings
        message: `Rent energy for ${(trxCost * 0.7).toFixed(6)} TRX`,
        benefits: 'Lower cost for one-time use'
      }
    ];
    
    // Sort by cost
    strategies.sort((a, b) => a.cost - b.cost);
    
    return {
      energyNeeded,
      currentEnergy: energyRemaining,
      requiredEnergy: estimatedEnergy,
      recommendedStrategy: strategies[0],
      allStrategies: strategies
    };
  }
}

3. Resource Alert System

JavaScript
class TronResourceAlertSystem {
  constructor(apiKey) {
    this.analyzer = new TronResourceAnalyzer(apiKey);
    this.alertCallbacks = new Map();
    this.thresholds = {
      bandwidth: { warning: 1000, critical: 100 },
      energy: { warning: 20000, critical: 5000 }
    };
  }
  
  onAlert(type, callback) {
    if (!this.alertCallbacks.has(type)) {
      this.alertCallbacks.set(type, []);
    }
    this.alertCallbacks.get(type).push(callback);
  }
  
  async checkAndAlert(address) {
    try {
      const resourceStatus = await this.analyzer.getResourceStatus(address);
      
      // Check bandwidth alerts
      const bandwidthRemaining = resourceStatus.bandwidth.total.remaining;
      if (bandwidthRemaining <= this.thresholds.bandwidth.critical) {
        this.triggerAlert('bandwidth_critical', {
          address,
          remaining: bandwidthRemaining,
          severity: 'critical',
          message: 'Bandwidth critically low - transactions will cost TRX'
        });
      } else if (bandwidthRemaining <= this.thresholds.bandwidth.warning) {
        this.triggerAlert('bandwidth_warning', {
          address,
          remaining: bandwidthRemaining,
          severity: 'warning',
          message: 'Bandwidth running low'
        });
      }
      
      // Check energy alerts
      const energyRemaining = resourceStatus.energy.remaining;
      if (energyRemaining <= this.thresholds.energy.critical) {
        this.triggerAlert('energy_critical', {
          address,
          remaining: energyRemaining,
          severity: 'critical',
          message: 'Energy critically low - smart contracts will be expensive'
        });
      } else if (energyRemaining <= this.thresholds.energy.warning) {
        this.triggerAlert('energy_warning', {
          address,
          remaining: energyRemaining,
          severity: 'warning',
          message: 'Energy running low'
        });
      }
      
    } catch (error) {
      this.triggerAlert('error', {
        address,
        error: error.message,
        severity: 'error',
        message: 'Failed to check resources'
      });
    }
  }
  
  triggerAlert(type, data) {
    const callbacks = this.alertCallbacks.get(type) || [];
    callbacks.forEach(callback => {
      try {
        callback(data);
      } catch (error) {
        console.error('Alert callback error:', error);
      }
    });
  }
  
  setThreshold(resource, level, value) {
    if (this.thresholds[resource] && this.thresholds[resource][level] !== undefined) {
      this.thresholds[resource][level] = value;
    }
  }
}

Performance Tips

  1. Cache Resource Data - Resources update slowly, cache for 30-60 seconds
  2. Batch Monitoring - Check multiple addresses in sequence with slight delays
  3. Smart Polling - Increase check frequency when resources are low
  4. Alert Optimization - Use thresholds to avoid alert spam
JavaScript
// Optimized resource monitoring with smart intervals
class SmartResourceMonitor {
  constructor(apiKey) {
    this.analyzer = new TronResourceAnalyzer(apiKey);
    this.cache = new Map();
    this.dynamicIntervals = new Map();
  }
  
  async monitorWithSmartIntervals(address) {
    const resourceStatus = await this.analyzer.getResourceStatus(address);
    
    // Determine monitoring frequency based on resource levels
    const bandwidthPercent = resourceStatus.bandwidth.total.usagePercent;
    const energyPercent = resourceStatus.energy.usagePercent;
    
    let interval;
    if (bandwidthPercent > 90 || energyPercent > 90) {
      interval = 60000; // 1 minute for critical
    } else if (bandwidthPercent > 70 || energyPercent > 70) {
      interval = 300000; // 5 minutes for warning
    } else {
      interval = 1800000; // 30 minutes for normal
    }
    
    this.dynamicIntervals.set(address, interval);
    
    // Cache result
    this.cache.set(address, {
      data: resourceStatus,
      timestamp: Date.now(),
      ttl: Math.min(interval / 2, 60000) // Cache for half the interval, max 1 minute
    });
    
    return resourceStatus;
  }
}

Need help? Contact our support team or check the TRON documentation.