> 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/create-trx-purchase-order.md).

# 创建trx能量买单

### 接口调用

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

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

#### Request Body

| Name                                            | Type   | Description                                                                                                                                                                 |
| ----------------------------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| fromAddress<mark style="color:red;">\*</mark>   | String | 用户地址（创建买单的钱包地址）                                                                                                                                                             |
| pledgeAddress<mark style="color:red;">\*</mark> | String | 能量                                                                                                                                                                          |
| pledgeNum<mark style="color:red;">\*</mark>     | int    | 能量数量（需大于15000）                                                                                                                                                              |
| orderPrice                                      | String | <p>价格</p><p>交易类型为freedom时，必选，支持30及以上数值</p><p>交易类型为fastTrade时，不可选</p>                                                                                                        |
| tradeType                                       | String | <p>交易类型（</p><p>freedom：自助交易，能量可以按照天冻结</p><p>fastTrade: 快速租赁，支持按分钟、小时和天租赁</p>                                                                                                |
| orderType<mark style="color:red;">\*</mark>     | String | ENERGY                                                                                                                                                                      |
| sourceFlag<mark style="color:red;">\*</mark>    | String | 渠道来源（需要双方约定一个名称来代表三方的渠道）                                                                                                                                                    |
| pledgeDay                                       | String | <p>租用时长，单位（天）</p><p>交易类型为freedom时，必选，支持3-30天</p><p>交易类型为fastTrade时，可选，支持1-30天</p><p>(<code>pledgeDay</code>, <code>pledgeHour</code> ，<code>pledgeMinute</code> 不能同时为空)</p> |
| pledgeHour                                      | String | <p>租用时长，单位（小时）</p><p>交易类型为fastTrade时，可选，取值1，3</p>                                                                                                                           |
| pledgeMinute                                    | String | <p>租用时长，单位（分钟）</p><p>交易类型为fastTrade时，可选，取值10</p>                                                                                                                            |
| pledgeBandwidthNum                              | String | <p>用户想要额外接收到的带宽数量                                                                                                                                                           |
| <br>传0或者不传，表示不需要租赁带宽</p>                        |        |                                                                                                                                                                             |

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

```javascript
{
    "resCode": 100,
    "resMsg": "Success",
    "data": {
        "orderId": "16zi4ynw_sdvn_qv8h_ujfc_crfsgyi07zat",
        "platformAddr": "TAdm9uEjiDge14T6AkZuo8vCNBEV1Fitmn",//转trx的目标地址
        "fromAddress": "TKghVbeEzvrV8GLK3YE1gRrjVHSf8rGB6k",//钱包地址
        "pledgeAddress": "TKghVbeEzvrV8GLK3YE1gRrjVHSf8rGB6k",//接收能量地址
        "pledgeDay": 3,
        "source": "tronLink",
        "orderType": "ENERGY",
        "orderPrice": 110,
        "pledgeNum": 500,
        "pledgeTrxNum": 0.165
    }
}
```

{% endtab %}
{% endtabs %}

### 调用示例

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

```
// example
const params = {
    fromAddress: 'TKghVbeEzvrV8GLK3YE1gRrjVHSf8rGB6k',
    pledgeAddress: 'TKghVbeEzvrV8GLK3YE1gRrjVHSf8rGB6k',
    tradeType: 'fastTrade',
    pledgeDay: '3',
    orderType: 'ENERGY',
    orderPrice: 110,
    pledgeNum: 32000,
    sourceFlag: 'tronLink'
}
//调用创建能量买单接口
const res = await axios.post('https://open.tronify.io/api/tronRent/addTronRentRecord',params)
console.log(res)
if(res.resCode === '100'){
    const orderId = res.data.orderId;
    const transaction = res.data.transaction;
    //签名交易数据
    const signedTx = await tronWeb.trx.sign(transaction)
    const params = {
        "orderId": orderId,
        "fromHash": signedTx.txID,
        "signedData": signedTx
    };
    //使用签名后的数据调用上传买单哈希接口，完成交易
    const rest = await axios.post('https://open.tronify.io/api/tronRent/uploadHash', params );
    console.log(rest)
    if(rest.resCode === '100'){
        // ...
    }

}
```

{% endtab %}
{% endtabs %}

### Postman 示例

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