# Delegate resource to another account

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://tron-mainnet.g.alchemy.com/v2/docs-demo/wallet/delegateresource

Delegates bandwidth or energy resources from one account to another. The delegator must have previously frozen TRX to obtain the resources.


Reference: https://www.alchemy.com/docs/chains/tron/tron-http-api-endpoints/tron-http-api-endpoints/delegate-resource-to-another-account

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://tron-mainnet.g.alchemy.com/v2/docs-demo/wallet/delegateresource \
  --header 'Content-Type: application/json' \
  --data '{
  "owner_address": "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g",
  "receiver_address": "TPswDDCAWhJAZGdHPidFg5nEf8TkNToDX1",
  "balance": 1000000,
  "resource": "BANDWIDTH",
  "lock": false,
  "visible": true
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    owner_address: 'TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g',
    receiver_address: 'TPswDDCAWhJAZGdHPidFg5nEf8TkNToDX1',
    balance: 1000000,
    resource: 'BANDWIDTH',
    lock: false,
    visible: true
  })
};

fetch('https://tron-mainnet.g.alchemy.com/v2/docs-demo/wallet/delegateresource', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://tron-mainnet.g.alchemy.com/v2/docs-demo/wallet/delegateresource"

payload = {
    "owner_address": "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g",
    "receiver_address": "TPswDDCAWhJAZGdHPidFg5nEf8TkNToDX1",
    "balance": 1000000,
    "resource": "BANDWIDTH",
    "lock": False,
    "visible": True
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://tron-mainnet.g.alchemy.com/v2/docs-demo/wallet/delegateresource"

	payload := strings.NewReader("{\n  \"owner_address\": \"TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g\",\n  \"receiver_address\": \"TPswDDCAWhJAZGdHPidFg5nEf8TkNToDX1\",\n  \"balance\": 1000000,\n  \"resource\": \"BANDWIDTH\",\n  \"lock\": false,\n  \"visible\": true\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://tron-mainnet.g.alchemy.com/v2/docs-demo/wallet/delegateresource")
  .header("Content-Type", "application/json")
  .body("{\n  \"owner_address\": \"TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g\",\n  \"receiver_address\": \"TPswDDCAWhJAZGdHPidFg5nEf8TkNToDX1\",\n  \"balance\": 1000000,\n  \"resource\": \"BANDWIDTH\",\n  \"lock\": false,\n  \"visible\": true\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://tron-mainnet.g.alchemy.com/v2/docs-demo/wallet/delegateresource");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"owner_address\": \"TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g\",\n  \"receiver_address\": \"TPswDDCAWhJAZGdHPidFg5nEf8TkNToDX1\",\n  \"balance\": 1000000,\n  \"resource\": \"BANDWIDTH\",\n  \"lock\": false,\n  \"visible\": true\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## Operation Specification

```yaml
path: /wallet/delegateresource
method: POST
operation:
  summary: Delegate resource to another account
  description: |
    Delegates bandwidth or energy resources from one account to another. The delegator must have previously frozen TRX to obtain the resources.
  tags:
    - Tron HTTP API Endpoints
  security:
    - apiKey: []
  requestBody:
    required: true
    content:
      application/json:
        schema:
          type: object
          required:
            - owner_address
            - receiver_address
            - balance
            - resource
          properties:
            owner_address:
              type: string
              description: Base58 address of the account delegating the resource.
              example: TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g
            receiver_address:
              type: string
              description: Base58 address of the account receiving the delegated resource.
              example: TPswDDCAWhJAZGdHPidFg5nEf8TkNToDX1
            balance:
              type: integer
              description: Amount of resource to delegate, in SUN (1 TRX = 1,000,000 SUN).
              example: 1000000
            resource:
              type: string
              enum:
                - BANDWIDTH
                - ENERGY
              description: Type of resource to delegate.
              example: BANDWIDTH
            lock:
              type: boolean
              description: Whether the delegated resource is locked.
              example: false
            visible:
              type: boolean
              description: Indicates if addresses are in base58 format.
              example: true
  responses:
    '200':
      description: Unsigned transaction object for delegating resource.
      content:
        application/json:
          schema:
            type: object
            properties:
              visible:
                type: boolean
              txID:
                type: string
              raw_data:
                type: object
              raw_data_hex:
                type: string
          examples:
            response:
              value:
                visible: true
                txID: d9f8c5a1e345617b3f4bcb9c5e3db4320dbf0c1a8e3a7a2f9c4d37ccefb25a61
                raw_data:
                  contract:
                    - parameter:
                        value:
                          owner_address: TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g
                          receiver_address: TPswDDCAWhJAZGdHPidFg5nEf8TkNToDX1
                          balance: 1000000
                          resource: BANDWIDTH
                          lock: false
                        type_url: type.googleapis.com/protocol.DelegateResourceContract
                      type: DelegateResourceContract
                  ref_block_bytes: abcd
                  ref_block_hash: 12345678abcdef12
                  expiration: 1762267590000
                  timestamp: 1762267531387
                raw_data_hex: 0a02abcd220812345678abcdef1240f0dad5faa4335a...
```
