# create trx energy order

### Endpoint usage

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

The fields with \* are required, and the fields without \* are optional

#### Request Body

| Name                                            | Type   | Description                                                                                                                                                                                                                                                                                                                            |
| ----------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| fromAddress<mark style="color:red;">\*</mark>   | String | user address(wallet address for buyer)                                                                                                                                                                                                                                                                                                 |
| pledgeAddress<mark style="color:red;">\*</mark> | String | energy receiving address.                                                                                                                                                                                                                                                                                                              |
| pledgeNum<mark style="color:red;">\*</mark>     | int    | amount of energy                                                                                                                                                                                                                                                                                                                       |
| orderPrice                                      | String | <p>price(unit: sun)</p><p>When <code>tradeType</code> is equal to "freedom", it is optional and needs to be greater than 30</p><p>default:95</p><p>When <code>tradeType</code> is equal to "fastTrade" , it is not need.</p>                                                                                                           |
| orderType<mark style="color:red;">\*</mark>     | String | ENERGY                                                                                                                                                                                                                                                                                                                                 |
| sourceFlag<mark style="color:red;">\*</mark>    | String | Source channel (Both sides need to agree on a name to represent the channel of the third parties)                                                                                                                                                                                                                                      |
| tradeType                                       | String | <p>\[freedom, </p><p>fastTrade]</p><p>default: freedom</p>                                                                                                                                                                                                                                                                             |
| pledgeDay                                       | String | <p>Rental Time(unit: day)</p><p>When <code>tradeType</code> is equal to "freedom", it is required.  values: 3-30</p><p>When <code>tradeType</code> is equal to "fastTrade", it is optional. values: 1-30</p><p>（<br><code>pledgeDay</code>, <code>pledgeHour</code>, and <code>pledgeMinute</code> cannot be empty simultaneously）</p> |
| pledgeHour                                      | String | <p>Rental Time(unit: hour)</p><p>When <code>tradeType</code> is equal to "fastTrade", it is optional.</p><p>values: \[1, 3]</p>                                                                                                                                                                                                        |
| pledgeMinute                                    | String | <p>Rental Time(unit: minute)</p><p>When <code>tradeType</code> is equal to "fastTrade" , it is optional.</p><p>values: \[10]</p>                                                                                                                                                                                                       |
| pledgeBandwidthNum                              | String | The amount of additional bandwidth the user wants to receive. If 0 or no passed, it means no bandwidth is required.                                                                                                                                                                                                                    |

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

```javascript
{
    "resCode": 100,
    "resMsg": "Success",
    "data": {
        "orderId": "16zi4ynw_sdvn_qv8h_ujfc_crfsgyi07zat",
        "platformAddr": "TAdm9uEjiDge14T6AkZuo8vCNBEV1Fitmn",//trx recieving platform address
        "fromAddress": "TKghVbeEzvrV8GLK3YE1gRrjVHSf8rGB6k",//wallet address
        "pledgeAddress": "TKghVbeEzvrV8GLK3YE1gRrjVHSf8rGB6k",//energy recieving address
        "pledgeDay": 3,
        "source": "tronLink",
        "orderType": "ENERGY",
        "orderPrice": 110,
        "pledgeNum": 500,
        "pledgeTrxNum": 0.165
    }
}
```

{% endtab %}
{% endtabs %}

### code example

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

```
// example
const params = {
    fromAddress: 'TKghVbeEzvrV8GLK3YE1gRrjVHSf8rGB6k',
    pledgeAddress: 'TKghVbeEzvrV8GLK3YE1gRrjVHSf8rGB6k',
    tradeType: 'freedom',
    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 example

<figure><img src="https://3188465811-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fnv0Qbx2yTtH3TKQFd528%2Fuploads%2Fmyz6eb9tPicgrt2pL6gn%2F2.jpg?alt=media&#x26;token=49001699-e066-4f74-8f65-ed15a55003e9" alt=""><figcaption></figcaption></figure>
