# 使用签名交易 (Signed tx)

## ​[Buy API (Postman)](https://www.postman.com/tronsave/workspace/tronsave/folder/29749953-f1b11e2a-9ba0-4964-ab0e-35b48cfade4f)​ <a href="#buy-api-postman" id="buy-api-postman"></a>

## **使用签名交易购买能源流程** <a href="#shi-yong-qian-ming-jiao-yi-gou-mai-neng-yuan-liu-cheng" id="shi-yong-qian-ming-jiao-yi-gou-mai-neng-yuan-liu-cheng"></a>

### **步骤 1：准备钱包和私钥** <a href="#bu-zhou-1-zhun-bei-qian-bao-he-si-yao" id="bu-zhou-1-zhun-bei-qian-bao-he-si-yao"></a>

1. 确保您可以访问用于交易的钱包私钥。
2. 确认钱包中有足够的TRX余额以执行交易。

### **步骤 2：估算所需的TRX** <a href="#bu-zhou-2-gu-suan-suo-xu-de-trx" id="bu-zhou-2-gu-suan-suo-xu-de-trx"></a>

* 使用[估算TRX API](https://docs.tronsave.io/chinese/developer/rest-api-v0/buy-on-rest-api/use-signed-transaction/estimate-trx)来计算所需的TRX，用于目标能源数量和租赁时长。

### **步骤 3：生成签名交易** <a href="#bu-zhou-3-sheng-cheng-qian-ming-jiao-yi" id="bu-zhou-3-sheng-cheng-qian-ming-jiao-yi"></a>

* [​**选项 1**：使用钱包私钥自行编写函数生成签名交易。](https://docs.tronsave.io/chinese/developer/rest-api-v0/buy-on-rest-api/get-signed-transaction#xuan-xiang-1-shi-yong-qian-bao-si-yao-zi-xing-bian-xie-han-shu-sheng-cheng-qian-ming-jiao-yi)​
* [​**选项 2**：使用Tronsave的Get Signed Transaction API自动生成签名交易。](https://docs.tronsave.io/chinese/developer/rest-api-v0/buy-on-rest-api/get-signed-transaction#xuan-xiang-2-shi-yong-tronsave-de-get-signed-transaction-api-zi-dong-sheng-cheng-qian-ming-jiao-yi)​

### **步骤 4：创建订单** 使用[创建订单 API](https://docs.tronsave.io/chinese/developer/rest-api-v0/buy-on-rest-api/use-signed-transaction/create-order)完成交易。 <a href="#bu-zhou-4-chuang-jian-ding-dan-shi-yong-chuang-jian-ding-dan-api-wan-cheng-jiao-yi" id="bu-zhou-4-chuang-jian-ding-dan-shi-yong-chuang-jian-ding-dan-api-wan-cheng-jiao-yi"></a>

* 提交签名交易的响应结果（如果使用API）或您自定义的签名交易。
* 包含估算的TRX数量和其他所需参数来创建能源购买订单。

## 测试用API列表 - Nile 测试网 <a href="#api-list-for-testing-tron-nile-testnet" id="api-list-for-testing-tron-nile-testnet"></a>

{% tabs %}
{% tab title="测试\_API" %}

* **获取估算 TRX:** <mark style="color:orange;">`POST`</mark> `https://api-dev.tronsave.io/v0/estimate-trx`
* **获取已签名交易**: <mark style="color:orange;">`POST`</mark> `https://api-dev.tronsave.io/v0/signed-tx`
* **创建订单:** <mark style="color:orange;">`POST`</mark> `https://api-dev.tronsave.io/v0/buy-energy`
  {% endtab %}
  {% endtabs %}
