Create order

Create an order using a Signed Transaction

POST https://api.tronsave.io/v2/buy-resource

Rate limit: 15 requests per 1 second

Request params

Field
Type
Description

resourceType

String

"ENERGY" or "BANDWIDTH", default: ENERGY

unitPrice

Number

The price unit is equal to SUN.

resourceAmount*

Number

The number of resources.

receiver*

String

Resource receiving address

durationSec

Number

The duration of the bought resource, time unit, is in seconds. Default 259200 (3 days)

sponsor

String

sponsor code

signedTx

SignedTransaction

Signed transaction, note that it is a JSON object (signed_tx in Step 2)

options

Object

optional

options.allowPartialFill

Boolean

Allow the order to be filled partially or not

options.onlyCreateWhenFulfilled

Boolean

[true]=> order only creates when it can be fulfilled

[false]=> order will create even if it can not be fulfilled

Default value: false

options.maxPriceAccepted

Number

Only create an order when the estimated price is less than this value.

options.preventDuplicateIncompleteOrders

Boolean

[true]=> Only create if no uncompleted order with the same parameters exists.

[false]=> Always create a new order, regardless of existing unfinished ones.

Default value: false

options.minResourceDelegateRequiredAmount

Number

The minimum resource amount delegated by a single provider.

Request params example

{
    "resourceType": "ENERGY",
    "receiver": "TFFbwz3UpmgaPT4UudwsxbiJf63t777777",
    "durationSec": 3600,
    "resourceAmount": 32000,
    "unitPrice": 80,
    "options": {
        "allowPartialFill": true,
        "onlyCreateWhenFulfilled": true,
        "preventDuplicateIncompleteOrders": false,
        "maxPriceAccepted": 100,
        "minResourceDelegateRequiredAmount": 100000
    },
    "signedTx": 
    {
        "visible": false,
        "txID": "795f8195893e8da2ef2f70fc3a1f2720f9077244c4b7b1c50c99c72fda675a32",
        "raw_data_hex": "0a02b32e2208ce1cb373c238875e4098fbd9a0eb325a68080112640a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412330a1541417ca6f74356a5d4454498e3f4856c945a04ab01121541055756f33f419278d9ea059bd2b21120e6add74818e0e5a40170b8a6d6a0eb32",
        "raw_data": {
            "contract": [
                {
                    "parameter": {
                        "value": {
                            "to_address": "41055756f33f419278d9ea059bd2b21120e6add748",
                            "owner_address": "41417ca6f74356a5d4454498e3f4856c945a04ab01",
                            "amount": 2700000
                        },
                        "type_url": "type.googleapis.com/protocol.TransferContract"
                    },
                    "type": "TransferContract"
                }
            ],
            "ref_block_bytes": "b32e",
            "ref_block_hash": "ce1cb373c238875e",
            "expiration": 1746778095000,
            "timestamp": 1746778035000
        },
        "signature": [
            "xxxxxxxxxxxxxxxxxxx"
        ]
    }
}

Responses

{
    "error": false,
    "message": "Success",
    "data": {
        "orderId": "6818426a65fa8ea36d119d2c"
    }
}

Example Code

const CreateOrder = async (resourceAmount, signedTx, receiverAddress, unitPrice, durationSec, options) => {
    const url = TRONSAVE_API_URL + "/v2/buy-resource";
    const body = {
        resourceType: RESOURCE_TYPE,
        resourceAmount,
        unitPrice,
        allowPartialFill: true,
        receiver: receiverAddress,
        durationSec,
        signedTx,
        options
    };
    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": "6809fdb7b9ba217a41d726fd"
     *     }
     * }
     */
    return response;
};

Last updated