# Demo

### Code demo <a href="#code-demo" id="code-demo"></a>

{% code fullWidth="false" %}

```javascript
const dataEstimateTrx = await fetch('https://api.tronsave.io/v0/estimate-trx', {
            method: 'POST',
            headers: {
                "Content-Type": "application/json",
            },
            body: JSON.stringify({
              "amount": 100000,
              "buy_energy_type": "MEDIUM",
              "duration_millisec": 259200000
   })
        })

        const { unit_price, duration_millisec, estimate_trx } = await dataEstimateTrx.json()
        console.log({ unit_price, duration_millisec, estimate_trx });

        const dataSendTrx = await tronWeb.transactionBuilder.sendTrx("TWZEhq5JuUVvGtutNgnRBATbF8BnHGyn4S", estimate_trx, 'BUYER_ADDRESS')
        const signed_tx = await tronWeb.trx.sign(dataSendTrx, 'PRIVATE_KEY');
        console.log(signed_tx);

        const dataCreateOrder = await fetch('https://api.tronsave.io/v0/buy-energy', {
            method: 'POST',
            headers: {
                "Content-Type": "application/json",
            },
            body: JSON.stringify({
                "resource_type": "ENERGY",
                unit_price,
                "allow_partial_fill": true,
                "target_address": "TM6ZeEgpefyGWeMLuzSbfqTGkPv8Z6Jm4X",
                duration_millisec,
                "tx_id": signed_tx.txID,
                signed_tx,
                "only_create_when_fulfilled":false,
                "max_price_accepted":200,
                "add_order_incomplete":false
            })
        })
        console.log(await dataCreateOrder.text());
```

{% endcode %}


---

# 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.tronsave.io/developer/rest-api-v0/buy-on-rest-api/use-signed-transaction/demo.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.
