> For the complete documentation index, see [llms.txt](https://docs.tronsave.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tronsave.io/developers/code-examples.md).

# Code Examples

These pages contain complete, runnable scripts that walk through a full TronSave integration end to end — from building and signing a transaction to placing an order and confirming it was filled. Each example is self-contained: copy it, set your credentials, and run it.

The examples come in two flavors:

* **API Key** — authenticate with a TronSave API Key. Best for backend services that pay from a prepaid TronSave balance. See [Authentication](/developers/authentication.md).
* **Private Key** — sign and pay directly from a TRON account using its private key, no prepaid balance required.

{% hint style="info" %}
All examples use [TronWeb](https://tronweb.network/) `5.3.2`. Install it with:

```bash
npm i tronweb@5.3.2 @noble/secp256k1@1.7.1
```

Read more in the [TronWeb 5.3.2 release notes](https://tronweb.network/docu/docs/5.3.2/Release%20Note/).
{% endhint %}

{% hint style="warning" %}
Most examples reference the mainnet TronSave receiver address `TWZEhq5JuUVvGtutNgnRBATbF8BnHGyn4S`. When running against testnet (Nile), change it to `TATT1UzHRikft98bRFqApFTsaSw73ycfoS`. See [Environments & Networks](/developers/environments.md).
{% endhint %}

## v2 (current)

Use these examples for new integrations. They target the current TronSave API.

| **Example**                                                                                | **Auth**    | **Description**                                                             |
| ------------------------------------------------------------------------------------------ | ----------- | --------------------------------------------------------------------------- |
| [Buy Resources with an API Key](/developers/code-examples/buy-with-api-key.md)             | API Key     | Estimate cost and place a resource order paying from your TronSave balance. |
| [Buy Resources with a Private Key](/developers/code-examples/buy-with-private-key.md)      | Private Key | Sign and pay for a resource order directly from a TRON account.             |
| [Extend an Order with an API Key](/developers/code-examples/extend-with-api-key.md)        | API Key     | Extend an active delegation, paying from your TronSave balance.             |
| [Extend an Order with a Private Key](/developers/code-examples/extend-with-private-key.md) | Private Key | Extend an active delegation, signing and paying from a TRON account.        |

## v0 (legacy)

{% hint style="warning" %}
These are legacy v0 examples, kept for reference only. For new integrations use the v2 examples above.
{% endhint %}

| **Example**                                                                           | **Auth**    | **Description**                                                  |
| ------------------------------------------------------------------------------------- | ----------- | ---------------------------------------------------------------- |
| [Buy Energy with an API Key](/developers/code-examples/buy-with-api-key-1.md)         | API Key     | Legacy flow for buying Energy paying from your TronSave balance. |
| [Buy Energy with a Private Key](/developers/code-examples/buy-with-private-key-1.md)  | Private Key | Legacy flow for buying Energy signing from a TRON account.       |
| [Extend an Order with an API Key](/developers/code-examples/extend-with-api-key-1.md) | API Key     | Legacy flow for extending an active delegation with an API Key.  |

## Next steps

* [Quickstart](/developers/quickstart.md) — the shortest path to your first order.
* [API Reference](/developers/api-reference.md) — every endpoint these examples call.
* [SDK](/developers/sdk.md) (TypeScript, Rust, Python, Java, PHP) — a typed wrapper if you prefer not to call the HTTP API directly.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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/developers/code-examples.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.
