Tronsave
🇨🇳 Chinese
🇨🇳 Chinese
  • 📗INTRODUCTION
    • Tronsave是什么?
    • 什么选 Tronsave?
  • Buyer
    • 如何购买能量?
      • 在网站上购买
      • 如何在Telegram上购买能源
        • 1: 创建Telegram Tronsave帐户
        • 2: 如何存款
        • 3: 获取Tronsave API密钥
        • 4. 如何在 Telegram 上购买
    • 延长
      • 快速延长
      • 提高
  • 🏬Seller
    • 质押 2.0 (Stake 2.0)
    • 权限 (Permission)
    • 购买能源
      • 设置自动卖出 (Setup Auto Sell)
      • 手动出售
      • 卖出建议
  • DEVELOPER
    • 获取 API 密钥
      • 在网站上
      • 在Telegram上
    • 购买资源 (v2)
      • 使用签名交易 (Signed tx)
        • 估算TRX
        • 获取已签名交易
        • 创建订单
      • 使用 API 密钥
        • 获取内部账户信息
        • 获取订单簿 (Order book)
        • 获取估算 TRX (Estimate TRX)
        • 购买能源
        • 获取单个订单详情
        • 获取内部账户订单历史
    • 扩展订单 (v2)
      • 步骤 1:获取可扩展的委托人
      • 步骤 2:扩展请求
    • SDK 库
    • REST API v0
      • 通过 REST API 购买
        • 使用签名交易 (Signed tx)
          • 估算TRX
          • 获取已签名交易
          • 创建订单
          • Demo
        • 使用 API 密钥
          • 获取内部账户信息
          • 获取订单簿 (Order book)
          • 获取估算 TRX (Estimate TRX)
          • 购买能源
          • 获取单个订单详情
          • 获取内部账户订单历史
      • 订单延长使用API密钥
  • 🤝 Referrer
    • 推荐 (Referral)
  • 💡FAQ
    • 能源市场问题
    • 计算 TronSave 的年化收益率 (APY)
    • 如何在 Tronsave 中连接钱包?
    • 服务团队
  • 👨‍💻Full Code Example
    • Code Example (v2)
      • 使用私钥通过 API 购买能源
      • 使用 API 密钥通过 API 购买能源
      • 使用 API 密钥通过 API 扩展订单
      • 使用私钥通过 API 扩展订单
    • Code Exaample (v0)
      • 使用私钥通过 API 购买能源
      • 使用 API 密钥通过 API 购买能源
      • 使用API密钥通过API延长订单
Powered by GitBook
On this page
  • 选项 1:使用 API 密钥扩展订单
  • 选项 2:使用签名交易扩展订单
  1. DEVELOPER
  2. 扩展订单 (v2)

步骤 2:扩展请求

Previous步骤 1:获取可扩展的委托人NextSDK 库

Last updated 18 days ago

选项 1:使用 API 密钥扩展订单

POST https://api.tronsave.io/v2/extend-request

速率限制 (Rate limit): 每1秒15个请求。

通过密钥创建新的延长请求订单

Headers

名称
类型
描述

apikey*

String

Tronsave API密钥,适用于内部账

Request Body

名称
类型
描述

receiver*

String

接收资源的地址

extendData*

Array

resourceType

String

“ENERGY”或“BANDWIDTH”,默认: “ENERGY”

如果成功,返回订单 ID 数组。

{
    "error": false,
    "message": "Success",
    "data": {
        "orderId": "6819da2d4d1b2aadb0d44eee"
    }
}
{
    "MISSING_PARAMS": "请求体中缺少某些参数",
    "INVALID_PARAMS": "某些参数无效",
    "INTERNAL_ACCOUNT_NOT_FOUND": "内部账户不存在",
    "INTERNAL_BALANCE_ACCOUNT_TOO_LOW": "余额不足",
    "SOME_DELEGATE_CANNOT_EXTEND": "由于某些错误,此委托订单无法扩展。请稍后重试。"
}
{
    "API_KEY_REQUIRED": "请求头中缺少 API 密钥",
    "INVALID_API_KEY": "API 密钥不正确"
}
{
    "RATE_LIMIT": "已达到速率限制"
}

Example

    "extendData":[
        {
            "delegator": "TFwUFWr3QV376677Z8VWXxGUAMFSSSSSSS",
            "isExtend": true,
            "extraAmount": 0,
            "extendTo": 1746702000
        },
        {
            "delegator": "TFwUFWr3QV376677Z8VWXxGUAMFFFFFFFF",
            "isExtend": true,
            "extraAmount": 0,
            "extendTo": 1746702000
        },
        ...
    ],
    "receiver": "TFwUFWr3QV376677Z8VWXxGUAMF1111111",
    "resourceType": "BANDWIDTH"
}
{
  "apikey": <YOUR_API_KEY>
}
{
    "error": false,
    "message": "Success",
    "data": {
        "orderId": "6819da2d4d1b2aadb0d44eee"
    }
}

示例代码

const SendExtendRequest = async (extendTo, maxPriceAccepted) => {
    const url = TRONSAVE_API_URL + `/v2/extend-request`
    // Get estimate extendable delegates
    const estimateResponse = await GetEstimateExtendData(extendTo, maxPriceAccepted)
    const extendData = estimateResponse.data?.extendData
    if (extendData && extendData.length) { 
        const body = {
            extendData: extendData,
            receiver: RECEIVER,
        }
        const data = await fetch(url, {
            method: "POST",
            headers: {
                'apikey': API_KEY,
                "content-type": "application/json",
            },
            body: JSON.stringify(body)
        })
        const response = await data.json()
        /**
         * Example response 
         {
            error: false,
            message: 'Success',
            data: { orderId: '680b5ac7b09a385fb3d582ff' }
            }
         */
        return response
    }
    return []
}
function sendExtendRequest(int $extendTo, int $maxPriceAccepted): array {
    $url = TRONSAVE_API_URL . "/v2/extend-request";
    $estimateResponse = getEstimateExtendData($extendTo, $maxPriceAccepted);
    $extendData = $estimateResponse['data']['extendData'] ?? [];

    if (!empty($extendData)) {
        $body = [
            'extendData' => $extendData,
            'receiver' => RECEIVER,
        ];

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'apikey: ' . API_KEY,
            'Content-Type: application/json'
        ]);
        $response = curl_exec($ch);
        curl_close($ch);
        return json_decode($response, true);
    }

    return [];
}
def send_extend_request(extend_to: int, max_price_accepted: int) -> Dict[str, Any]:
    """Send extend request"""
    url = f"{TRONSAVE_API_URL}/v2/extend-request"
    headers = {
        'apikey': API_KEY,
        'Content-Type': 'application/json'
    }
    
    estimate_response = get_estimate_extend_data(extend_to, max_price_accepted)
    extend_data = estimate_response.get('data', {}).get('extendData', [])

    if extend_data:
        body = {
            'extendData': extend_data,
            'receiver': RECEIVER,
        }
        
        response = requests.post(url, headers=headers, json=body)
        return response.json()

    return {}

选项 2:使用签名交易扩展订单

POST https://api.tronsave.io/v2/extend-request

速率限制 (Rate limit): 每1秒15个请求。

Request Body

名称
类型
描述

receiver*

String

接收资源的地址

extendData*

Array

resourceType

String

“ENERGY”或“BANDWIDTH”,默认: “ENERGY”

signedTx

SignedTransaction

Example

    "extendData":[
        {
            "delegator": TGGVrYaT8XoosBEXPp6dmSZkoh11223344,
            "isExtend": true,
            "extraAmount": 0,
            "extendTo": 1746403201
        },
        ...
    ],
    "receiver": "TGGVrYaT8XoosBEXPp6dmSZkoh123456",
    "resourceType": "BANDWIDTH",
    "signedTx": {
      "visible": false,
      "txID": "446eed36e31249b98b201db2e81a3825b185f1a3d8b2fea348b24fc021e58e0d",
      "raw_data": {
        "contract": [
          {
            "parameter": {
              "value": {
                "amount": 5500000,
                "owner_address": "417a0d868d1418c9038584af1252f85d486502eec0",
                "to_address": "41055756f33f419278d9ea059bd2b21120e6add748"
              },
              "type_url": "type.googleapis.com/protocol.TransferContract"
            },
            "type": "TransferContract"
          }
        ],
        "ref_block_bytes": "0713",
        "ref_block_hash": "6c5f7686f4176139",
        "expiration": 1691465106000,
        "timestamp": 1691465046758
      },
      "raw_data_hex": "0a02071322086c5f7686f417613940d084b5999d315a68080112640a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412330a15417a0d868d1418c9038584af1252f85d486502eec0121541055756f33f419278d9ea059bd2b21120e6add74818e0fcb70670e6b5b1999d31",
      "signature": ["xxxxxxxxx"]
    }
}
{
    "error": false,
    "message": "Success",
    "data": {
        "orderId": "6819da2d4d1b2aadb0d44eee"
    }
}
  • 要创建签名交易,请按照此处的说明操作。

Example Code

const SendExtendRequest = async (extendTo, maxPriceAccepted) => {
    const url = TRONSAVE_API_URL + `/v2/extend-request`
    // Get estimate extendable delegates
    const estimateResponse = await GetEstimateExtendData(REQUESTER_ADDRESS, extendTo, maxPriceAccepted)
    const extendData = estimateResponse.data?.extendData
    // check if there are extendable delegates
    if (extendData && extendData.length) { 
        const totalEstimateTrx = estimateResponse.data?.totalEstimateTrx
        // Build a signed transaction by using the private key
        const signedTx = await GetSignedTx(totalEstimateTrx)
        const body = {
            extendData: extendData,
            receiver: RECEIVER,
            signedTx
        }
        const data = await fetch(url, {
            method: "POST",
            headers: {
                "content-type": "application/json",
            },
            body: JSON.stringify(body)
        })
        const response = await data.json()
        /**
         * Example response 
         {
            error: false,
            message: 'Success',
            data: { orderId: '680b5ac7b09a385fb3d582ff' }
            }
         */
        return response
    }
    return []
}
function sendExtendRequest(int $extendTo, int $maxPriceAccepted): array {
    $url = TRONSAVE_API_URL . "/v2/extend-request";
    $estimateResponse = getEstimateExtendData(REQUESTER_ADDRESS, $extendTo, $maxPriceAccepted);
    $extendData = $estimateResponse['data']['extendData'] ?? [];

    if (!empty($extendData)) {
        $totalEstimateTrx = $estimateResponse['data']['totalEstimateTrx'];
        $signedTx = getSignedTx($totalEstimateTrx);

        $body = [
            'extendData' => $extendData,
            'receiver' => RECEIVER,
            'signedTx' => $signedTx
        ];

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Content-Type: application/json'
        ]);
        $response = curl_exec($ch);
        curl_close($ch);
        return json_decode($response, true);
    }

    return [];
}
def send_extend_request(extend_to: int, max_price_accepted: int) -> Dict[str, Any]:
    """Send extend request"""
    url = f"{TRONSAVE_API_URL}/v2/extend-request"
    
    estimate_response = get_estimate_extend_data(REQUESTER_ADDRESS, extend_to, max_price_accepted)
    extend_data = estimate_response.get('data', {}).get('extendData', [])

    if extend_data:
        total_estimate_trx = estimate_response['data']['totalEstimateTrx']
        signed_tx = get_signed_tx(total_estimate_trx)

        body = {
            'extendData': extend_data,
            'receiver': RECEIVER,
            'signedTx': signed_tx
        }
        
        response = requests.post(url, json=body)
        return response.json()

    return {}

数组扩展数据。 从 API 预估中获取响应,。

数组扩展数据。 从 API 预估中获取响应,。

签名交易,请注意它是一个 JSON 对象 (在 中为 signedTx)

签名所需的 TRX 数量在 API 响应的 total_estimate_trx 字段中提供。-

API
Get Extendable Delegates
获取可扩展的委托人
获取可扩展的委托人
GET SIGNED