> For the complete documentation index, see [llms.txt](https://docs-tron.tronify.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-tron.tronify.io/tron-api/earn-energy-by-stake.md).

# 质押获得能量

### 接口调用

<mark style="color:green;">`POST`</mark> `https://open.tronify.io/api/tronRent/createfreezeBalanceTransaction`

**以下参数带\*字段为必填，不带\*号为选填**

#### Request Body

| Name                                          | Type   | Description              |
| --------------------------------------------- | ------ | ------------------------ |
| saleAddress<mark style="color:red;">\*</mark> | String | 用户地址（创建质押交易的钱包地址）        |
| sourceFlag<mark style="color:red;">\*</mark>  | String | 渠道来源（需要双方约定一个名称来代表三方的渠道） |
| payTrxNum<mark style="color:red;">\*</mark>   | String | 质押trx数量                  |
| orderType<mark style="color:red;">\*</mark>   | String | 订单类型(ENERGY/BANDWIDTH)   |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    "resCode": 100,
    "resMsg": "Success",
    "data": {
        "visible": false,
        "txID": "05694544c56863032625dce3554e62220fd4b36d32172fd125d255123e4a0826",
        "raw_data": {
            "contract": [
                {
                    "parameter": {
                        "value": {
                            "resource": "ENERGY",
                            "frozen_balance": 400000000,
                            "owner_address": "41dcf5a07cfac1534c2410714d6ba6576f49c4a6d7"
                        },
                        "type_url": "type.googleapis.com/protocol.FreezeBalanceV2Contract"
                    },
                    "type": "FreezeBalanceV2Contract"
                }
            ],
            "ref_block_bytes": "717a",
            "ref_block_hash": "8fb56414b12b26fe",
            "expiration": 1682088777000,
            "timestamp": 1682088718991
        },
        "raw_data_hex": "0a02717a22088fb56414b12b26fe40a8aab7a2fa305a5b083612570a34747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e467265657a6542616c616e63655632436f6e7472616374121f0a1541dcf5a07cfac1534c2410714d6ba6576f49c4a6d7108088debe011801708fe5b3a2fa30"
    }
}
```

{% endtab %}

{% tab title="500: Internal Server Error " %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

### 调用示例

{% tabs %}
{% tab title="JavaScript" %}

```
// example
const params = {
    saleAddress: 'TKghVbeEzvrV8GLK3YE1gRrjVHSf8rGB6k',
    orderType: 'ENERGY',
    payTrxNum: 111,
    sourceFlag: 'tronLink'
}
 const res = await axios.post('https://open.tronify.io/api/tronRent/createfreezeBalanceTransaction',params)
 console.log(res)
 if(res.resCode === '100'){
    const signedTx = await tronWeb.trx.sign(res.data)
    const broastTx = await tronWeb.trx.sendRawTransaction(signedTx)
    return broastTx.txid
 }
```

{% endtab %}
{% endtabs %}

### Postman 示例

<figure><img src="/files/YY4apuPZT5zzz0w4FqXU" alt=""><figcaption></figcaption></figure>
