> 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-usdt-purchase-order.md).

# 创建usdt能量买单

### 接口调用

<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）                                                                                                            |
| tradeType<mark style="color:red;">\*</mark>     | String | fastTrade                                                                                                                 |
| sourceFlag<mark style="color:red;">\*</mark>    | String | 渠道来源（需要双方约定一个名称来代表三方的渠道）                                                                                                  |
| orderType<mark style="color:red;">\*</mark>     | String | ENERGY                                                                                                                    |
| pledgeDay<mark style="color:red;">\*</mark>     | String | <p>租用时长，单位（天）</p><p>支持0-30天</p><p>(<code>pledgeDay</code>, <code>pledgeHour</code> ，<code>pledgeMinute</code> 不能同时为0)</p> |
| pledgeHour<mark style="color:red;">\*</mark>    | String | <p>租用时长，单位（小时）</p><p>取值0、1、3</p>                                                                                          |
| pledgeMinute<mark style="color:red;">\*</mark>  | String | <p>租用时长，单位（分钟）</p><p>取值0、10</p>                                                                                           |
| extraTrxNum<mark style="color:red;">\*</mark>   | String | <p>用户想要额外接收到的trx数量<br>有效传值0或者\[0.8, 500]，0表示只需要能量，不需要获得trx</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: '0',
    pledgeHour: '0',
    pledgeMinute: '10',
    orderType: 'ENERGY',
    pledgeNum: 32000,
    sourceFlag: 'tronLink',
    extraTrxNum: '0.8',
    pledgeBandwidthNum: '0'
}
//调用创建能量买单接口
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>

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