# Buy Energy

{% openapi src="<https://4164384423-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa332YYkbT2p9snj9atS0%2Fuploads%2Fgit-blob-c00398efba28b9e10f511c661357b0977db5282b%2Fapi.json?alt=media&token=f3ac4d9e-a201-4b3b-a071-14a8f29c6b35>" path="/v1/order" method="post" %}
[api.json](https://4164384423-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa332YYkbT2p9snj9atS0%2Fuploads%2Fgit-blob-c00398efba28b9e10f511c661357b0977db5282b%2Fapi.json?alt=media\&token=f3ac4d9e-a201-4b3b-a071-14a8f29c6b35)
{% endopenapi %}

#### Key API: Create Order (POST /v1/order)

When creating an order via CatFee.IO’s API, please pay special attention to the following return values:

**`id` (Payment Hash / Order ID):**

* A unique identifier for each order.
* You can retrieve the order details using the `GET /v1/order/{id}` endpoint.

**`status` (Order Status):**

* Reflects the execution progress of the order.
* If `status` is `DELEGATE_SUCCESS`, the energy delegation has been successfully submitted to the TRON blockchain.

> **Note:** There is a very small chance (\~0.1%) that the transaction may fail to be broadcast to the blockchain.

**`confirm_status` (On-Chain Confirmation Status):**

* Confirms whether energy has been successfully delivered to the target address.
* If `confirm_status` is `DELEGATION_CONFIRMED`, the energy has been successfully sent and confirmed on-chain.

**`client_order_id` (Client-defined Order ID):**

* For idempotent requests. See: [API Idempotency Support](https://docs.catfee.io/en/getting-started/api-supports-idempotent-requests)

***

#### ❓How to Ensure Energy Has Been Successfully Sent?

You can confirm energy delivery through **two methods**:

**1. Query the energy balance of the target address via TRON API:**

Use the official TRON API or wallet tools (e.g., TronLink) to check the energy balance of the target address.

**Sample API Request (TRON Official Endpoint):**

```bash
curl --request POST \
     --url https://api.trongrid.io/wallet/getaccountresource \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "address": "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g",
  "visible": true
}'
```

Check fields such as `energy_limit` and `energy_used` in the response.

**2. Check the `confirm_status` of the order:**

Use `GET /v1/order/{id}` to retrieve order details.

If `confirm_status` is `DELEGATION_CONFIRMED`, the energy has been successfully confirmed on-chain.

***

#### Example Workflow

**1. Create Order**

**Request:**

```http
POST /v1/order?count=1&target_address=TRON_ADDRESS&period=1
Host: https://api.catfee.io
Headers:
  Content-Type: application/json
  CF-ACCESS-KEY: {api_key}
  CF-ACCESS-SIGN: {signature}
  CF-ACCESS-TIMESTAMP: {timestamp}
```

**Response:**

```json
{
  "code":0,
  "data":{
    "id": "abcd1234",
    "status": "DELEGATE_SUCCESS",
    "confirm_status": "UNCONFIRMED"
  }
}
```

**2. Query Order Status**

**Request:**

```http
GET /v1/order/abcd1234
Host: https://api.catfee.io
Headers:
  Content-Type: application/json
  CF-ACCESS-KEY: {api_key}
  CF-ACCESS-SIGN: {signature}
  CF-ACCESS-TIMESTAMP: {timestamp}
```

**Response:**

```json
{
  "code":0,
  "data":{
    "id": "abcd1234",
    "status": "DELEGATE_SUCCESS",
    "confirm_status": "DELEGATION_CONFIRMED"
  }
}
```

**3. Confirm Successful Energy Transfer**

If `confirm_status` is `DELEGATION_CONFIRMED`, energy has been successfully sent.

You may also use the TRON API to verify the target address’s energy balance.

***

#### FAQs

**Q: Order status is `DELEGATE_SUCCESS` but energy hasn’t arrived?**

* **Reason:** The transaction might not have been successfully broadcast (\~0.1% probability).
* **Solution:** Wait for a while and re-check the order status or verify on-chain via TRON block explorers.

**Q: Energy arrival is delayed?**

* **Reason:** Potential TRON network congestion.
* **Solution:** Ensure `confirm_status` is `DELEGATION_CONFIRMED`. This confirms energy delivery.

***

By tracking the `id` and `confirm_status` values and using on-chain validation, you can ensure energy transfers are reliable.\
If you still have questions, please contact CatFee customer support: [@CatFee\_James](https://t.me/CatFee_James)
