# Preview Transaction

{% hint style="info" %}
**API Endpoints**

* **USDT:     POST** [**/client/wallets/send/token/preview**](https://xpay.stream/client/wallets/send/token/preview)
* **TRON:     POST** [**/client/wallets/send/tron/preview**](https://xpay.stream/client/wallets/send/tron/preview)
* **LN-BTC: POST** [**/client/wallets/send/ln/preview**](https://xpay.stream/client/wallets/send/ln/preview)
  {% endhint %}

***

{% hint style="info" %}
**Request Headers:**

Authorization: Bearer [\<access\_token>](/authentication-api.md)

Content-Type: application/json

**Request Body:**

```json
{
    "wallet": "<wallet_uuid>", // the source wallet uuid
    "destination" : "TDmx..Fx68" // Only for TRX or USDT withdrawal
    "amount": 20000000 // Only for TRX or USDT amount in SUN based (20 x 1000000)
    "paymentRequest": "LNINVOICE..." // Only for Case of Bitcoin LN Invoice
}
```

{% endhint %}

{% hint style="success" %}
**Success Response:**\
If the OTP is enabled *(success.data.isOTP: true),* broadcasting the transaction will require an OTP to be authorized. \
Note that 1 TRX = 1000000 SUN. Amounts are denominate in SUN, for both USDT and TRX, which means you have to divide the amounts by 1,000,000 for user presentation.

**`Example Below:`**

{% code lineNumbers="true" fullWidth="true" %}

```json
{
    "success": {
        "message": "Transfer Preview",
        "data": {
            "source": "TNQ...i2N",
            "destination": "TDmx..Fx68",
            "amount": 86000000, // Sending Raw Amount, to be divided by 1000000
            "requiredEnergy": 0, // Energy Required - In case of USDT
            "availableEnergy": 0, // Energy Available - In case of USDT
            "requiredBandwidthPoints": 100,  // Bandwith Required
            "availableBandwidthPoints": 600, // Bandwith Available
            "feeSUN": 1100000, // TRX Fees, divide feeSUN by 1000000
            "sunCostForBandwidth": 100000, // Bandwith Fees Cost in SUN 
            "sunCostForEnergy": 0,
            "accRes": {
                "freeNetLimit": 600,
                "TotalNetLimit": 43200000000,
                "TotalNetWeight": 84632720284,
                "TotalEnergyLimit": 50000000000000,
                "TotalEnergyWeight": 564258045519
            },
            "dstRes": {},
            // Additional case of TRX account creation
            // first time TRX received on new TRON Address destination
            "sunCostForAccountCreation": 1000000, 
            "isOTP": true
        }
    },
    "uuid": "4f49d932-fae5-479e-b8dd-0c8aee0be833"
}
```

{% endcode %}
{% endhint %}

***

{% tabs %}
{% tab title="CURL Example" %}
{% code lineNumbers="true" fullWidth="true" %}

```bash
curl 'https://apis.xpay.stream/client/wallets/send/tron/preview'                                            \
  -H 'Authorization: Bearer eyJhbGciO...RCf0'                                                               \
  -H 'Content-Type: application/json'                                                                       \
  --data-raw '{"wallet":"<wallet_uuid>","destination":"<destination_address>","amount":<amount_sun_based>}' 
```

{% endcode %}
{% endtab %}

{% tab title="NodeJS Example" %}
{% code lineNumbers="true" %}

```javascript
// npm i cross-fetch
const fetch = require("cross-fetch");

const API_URL = "https://apis.xpay.stream/client/wallets/find";

const method = "POST";

const headers = { 
    "Content-Type": "application/json",
    "Authorization: "Bearer <access_token>"
};

const body = JSON.stringify({
    "wallet": "698...cba", // wallet uuid
    "destination": "TDmx..Fx68", // to TRX address
    "amount": 86000000 // 86 USDT or TRX amount in SUN (x10000000) 
});

fetch(API_URL, { headers, body, method })
.then(async res =>  await res.json())
.then(result => {
    if(result.error)
        console.log("Transaction Preview Done", result);
    if(result.success)
        console.log("Transaction Preview Error", result);
})
.catch((err) => {
    console.error("Transaction Preview API Exception", err);
});
```

{% endcode %}

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.xpay.stream/transactions/preview-transaction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
