Skip to main content

wallet/undelegateresource

Reclaim previously delegated bandwidth or energy resources from another account.

Endpoint#

POST /wallet/undelegateresource

Parameters#

Required Parameters#

ParameterTypeDescription
owner_addressstringAccount address that delegated resources (base58)
receiver_addressstringAccount that received delegated resources (base58)
balancenumberAmount to undelegate in SUN (1 TRX = 1,000,000 SUN)
resourcestringResource type: "BANDWIDTH" or "ENERGY"

Optional Parameters#

ParameterTypeDescription
permission_idnumberPermission ID for multi-signature (default: 0)
visiblebooleanReturn base58 addresses (default: false returns hex)

Response#

Returns unsigned transaction containing the undelegation operation. Transaction must be signed and broadcast.

Response Fields#

  • txID - Transaction hash
  • raw_data - Transaction raw data
    • contract - Undelegation contract details
    • expiration - Transaction expiration timestamp
    • timestamp - Transaction creation timestamp
  • visible - Address format indicator

Important Notes#

Undelegation Rules#

  1. Lock Period Check: Cannot undelegate if resources are locked
  2. Immediate Effect: Resources return to owner immediately after confirmation
  3. Partial Undelegation: Can undelegate portions of delegated amount
  4. Resource Availability: Reclaimed resources are immediately available to owner
  5. No Waiting Period: Unlike unstaking, undelegation has no waiting period

Key Differences from Unstaking#

  • Undelegation: Returns delegated resources to owner (immediate)
  • Unstaking: Converts staked TRX back to liquid (14-day wait)

Implementation Examples#

# Basic undelegation of energy
curl -X POST https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/undelegateresource \
-H "Content-Type: application/json" \
-d '{
"owner_address": "TOwnerAddress...",
"receiver_address": "TReceiverAddress...",
"balance": 1000000000,
"resource": "ENERGY",
"visible": true
}'

# Undelegate bandwidth
curl -X POST https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/undelegateresource \
-H "Content-Type: application/json" \
-d '{
"owner_address": "TOwnerAddress...",
"receiver_address": "TReceiverAddress...",
"balance": 500000000,
"resource": "BANDWIDTH",
"visible": true
}'

# Check delegation index (to find all delegations)
curl -X POST https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/getdelegatedresourceaccountindex \
-H "Content-Type: application/json" \
-d '{
"value": "TOwnerAddress...",
"visible": true
}'

# Get specific delegation details
curl -X POST https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/getdelegatedresource \
-H "Content-Type: application/json" \
-d '{
"fromAddress": "TOwnerAddress...",
"toAddress": "TReceiverAddress...",
"visible": true
}'

# Check receiver's resource usage (to analyze efficiency)
curl -X POST https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/getaccountresource \
-H "Content-Type: application/json" \
-d '{
"address": "TReceiverAddress...",
"visible": true
}'

Example Response#

{
"visible": true,
"txID": "a9f4d3c2b1e8a7d6c5e4f3b2a1d9c8e7f6b5a4d3c2e1f9a8b7c6d5e4f3a2b1c8",
"raw_data": {
"contract": [
{
"parameter": {
"value": {
"owner_address": "TOwnerAddress...",
"receiver_address": "TReceiverAddress...",
"balance": 1000000000,
"resource": "ENERGY"
},
"type_url": "type.googleapis.com/protocol.UnDelegateResourceContract"
},
"type": "UnDelegateResourceContract"
}
],
"ref_block_bytes": "7c6d",
"ref_block_hash": "5e4f9b8a7c6d5e3f",
"expiration": 1702456849000,
"timestamp": 1702456789000
}
}

Undelegation Process Flow#

graph LR
A[Delegated Resources] --> B{Check Lock Status}
B -->|Locked| C[Wait for Unlock]
B -->|Unlocked| D[Initiate Undelegation]
C --> D
D --> E[Sign Transaction]
E --> F[Broadcast]
F --> G[Resources Returned to Owner]

style A fill:#2196F3
style B fill:#FF9800
style G fill:#4CAF50

Best Practices#

1. Check Lock Status First#

// Always check before attempting undelegation
const status = await checkUndelegationStatus(owner, receiver, resource);
if (!status.canUndelegate) {
console.log(`Cannot undelegate: ${status.reason}`);
return;
}

2. Monitor Utilization#

  • Regularly check delegation efficiency
  • Reclaim underutilized resources
  • Redistribute based on actual needs

3. Batch Operations#

  • Group multiple undelegations together
  • Reduces transaction costs
  • Easier to manage

4. Grace Period Management#

  • Track lock expiration dates
  • Set reminders for locked delegations
  • Plan undelegations in advance

Common Errors#

ErrorDescriptionSolution
No delegation foundNo resources delegated to receiverCheck delegation status first
Delegation is lockedResources are locked for periodWait for lock period to expire
Insufficient delegated balanceTrying to undelegate more than delegatedCheck current delegation amount
Invalid resource typeMust be BANDWIDTH or ENERGYUse correct resource string

Use Cases#

  • Resource Reallocation: Move resources to more active users
  • Cost Optimization: Reclaim resources from inactive accounts
  • Emergency Recovery: Quickly reclaim resources when needed
  • Delegation Cleanup: Remove old or unnecessary delegations
  • Efficiency Management: Optimize resource distribution based on usage