v2 — Extend with Private Key
A complete working example that extends an existing resource delegation by paying for it with a locally signed transaction built from your private key.
This is a full, runnable example showing how to extend an existing resource delegation using the v2 Extend Orders API while paying with a transaction signed locally from your private key.
The flow has two API calls:
POST /v2/get-extendable-delegates— estimates which delegates can be extended and how much TRX it will cost (totalEstimateTrx).POST /v2/extend-request— submits the extend request together with asignedTxthat pays TronSave the estimated amount.
Between those two calls you build and sign a TRX transfer to TronSave's receiver address using your own private key, so TronSave never holds your funds.
This example uses TronWeb to build and sign the transfer. TronWeb version 5.3.2 is required.
npm i [email protected] @noble/[email protected]Read more: https://tronweb.network/docu/docs/5.3.2/Release%20Note/
Configuration
Before running, set the following values:
TRONSAVE_API_URL
TronSave API base URL. Mainnet: https://api.tronsave.io.
RECEIVER
The address that receives the extended resource delegation.
RESOURCE_TYPE
ENERGY or BANDWIDTH. Optional — defaults to ENERGY.
REQUESTER_ADDRESS
The address that requests (and pays for) the extension.
PRIVATE_KEY
Private key for REQUESTER_ADDRESS, used to sign the TRX transfer locally.
TRON_FULL_NODE
TRON full node used by TronWeb to build the transaction (e.g. https://api.trongrid.io).
TRONSAVE_RECEIVER_ADDRESS
The TronSave address that receives your payment. Mainnet: TWZEhq5JuUVvGtutNgnRBATbF8BnHGyn4S. Testnet: TATT1UzHRikft98bRFqApFTsaSw73ycfoS.
Keep your private key secret. Run this code only in a trusted server environment — never expose PRIVATE_KEY in client-side or browser code.
See Environments for the full list of mainnet and testnet endpoints, and the Extend Orders API reference for endpoint details.
Full example
The PHP getSignedTx() function above is a placeholder. PHP has no official TronWeb SDK, so you must build and sign the TRX transfer with a TRON-compatible signing library before sending the extend request.
The Python get_signed_tx() function above is a placeholder. Use a TRON signing library such as tronpy to build and sign the TRX transfer before sending the extend request. Note that the example also references time.time() but the import time line is commented out — uncomment or add import time before running.
How it works
Estimate.
GetEstimateExtendDatacalls/v2/get-extendable-delegateswithextendTo,receiver,requester, an optionalmaxPriceAccepted, andresourceType. The response includesextendData(the delegates that can be extended) andtotalEstimateTrx(the cost in SUN).Sign. If
extendDatais non-empty,GetSignedTxbuilds a TRX transfer oftotalEstimateTrxfromREQUESTER_ADDRESStoTRONSAVE_RECEIVER_ADDRESSand signs it locally withPRIVATE_KEY.Submit.
SendExtendRequestpostsextendData,receiver, and thesignedTxto/v2/extend-request. On success the response contains anorderId.
maxPriceAccepted is an upper bound on the price (in SUN) you are willing to pay to extend. If the order book price exceeds it, fewer delegates may be returned in extendData.
Next steps
Extend Orders API reference — full request and response schemas for
get-extendable-delegatesandextend-request.Authentication — compare the private-key/signed-transaction flow with the API key flow.
Order types — understand how extend orders relate to other order types.
Last updated