Skip to main content

Tutorial on Batch Creating Sub-Contracts for Payments

ยท 7 min read
Pay Protocol Support
Pay Protocol Support
Pay Protocol BD & Support Team

This document describes how to rapidly batch-create TRON sub-contracts for payment business. The core approach is: first activate TRX currency in the admin console, then generate sub-contract addresses by creating payment orders, and finally deploy the contracts by transferring a small amount of TRX (approximately 1.277 TRX, valued at around 0.5 USDT) to complete batch initialization at minimal cost.

Use Casesโ€‹

  • Payment business based on the TRON (TRC20) network
  • Merchants need to pre-provision large quantities of payment-collection sub-contract wallets to handle high-concurrency payment demands
  • Desire to reduce batch sub-contract creation costs by paying gas fees in TRX

Overall Process Flowโ€‹

StepOperationExecutor
1Enable TRX currency in admin console (wallet signature confirmation)Admin
2Call API to create payment orderMerchant System
3Call API to update payment info to TRX (currencyId: 1)Merchant System
4Retrieve generated sub-contract address from order detailsMerchant System
5Transfer 0.01 TRX to the addressOperations/Finance
6Wait for on-chain confirmation; sub-contract automatically deploysโ€”
7Repeat steps 2~6 for batch operationsMerchant System
8Disable TRX currency from admin console upon completionAdmin
Cost Breakdown

Each sub-contract transfer costs approximately 1.277 TRX (equivalent to around 0.5 USDT), comprising: 0.01 TRX transfer amount, 0.267 TRX bandwidth fee, and 1 TRX new address activation fee. Compared to deploying contracts directly using USDT, this significantly reduces gas costs.

Detailed Stepsโ€‹

1. Enable TRX Currency in Admin Consoleโ€‹

Log in to the admin console using an admin wallet, navigate to "System Configuration โ†’ Currency List", add the TRX currency, and confirm via wallet signature.

Admin console URL: https://adm.payprotocol.network/login

1.1 Select the currency to enableโ€‹

Click the "Manage Currencies" button. In the modal that appears, select TRX (TRX) from the dropdown list.

Manage currencies modal

Figure 1: Select TRX (TRX) from the dropdown in the "Manage Currencies" modal

1.2 Submit the activation requestโ€‹

After confirming that the selected currencies include Tether(TRC20) (USDT) and TRX (TRX), click the "Submit" button.

Submit activation request

Figure 2: Click "Submit" after confirming the selected currencies

1.3 Confirm wallet signatureโ€‹

The system will trigger your wallet to display a "Trigger Smart Contract" signature request, with an estimated gas fee of approximately 2.4785 TRX. Click the "Sign" button to complete the on-chain operation.

Signature confirmation

Figure 3: Click "Sign" in the wallet popup to complete TRX currency activation

Operation Tips

After successful signature, the TRX currency record will appear in the currency list, indicating successful activation. The system now has the capability to process TRX payments, and you can proceed to the next steps.

2. Call API to Create Payment Orderโ€‹

Create a payment order through the merchant API. Each order will correspond to an independent sub-contract wallet address.

API Documentation: Create Payment Order

Request Example

POST /payment/order/create
Content-Type: application/json

{
"chainId": 1,
"description": "A sample order",
"isLegalTender": 0,
"notifyUrl": "https://www.payment.com/api/notify",
"outTradeNo": "P2026010100000001",
"quoteAmount": "0.01",
"quoteCurrencySymbol": "TRX",
"redirectionUrl": "https://www.payment.com/order/redirect",
"tagId": 1
}

Upon successful API call, the response will include the order's unique identifier orderNo, which you'll need for subsequent steps.

Batch Calling Recommendations

It is recommended to loop this API call in your program, using a unique merchantOrderNo (merchant order number) for each call. Add an appropriate delay between calls (e.g., 200~500ms).

3. Update Payment Information to TRXโ€‹

After the order is created, call the "Update Payment Info" API to switch the order's payment currency to TRX. This is a critical step: by setting currencyId to 1 (TRX), the subsequent 0.01 TRX transfer will trigger sub-contract wallet generation with minimal gas cost.

API Documentation: Update Payment Info

Request Example

POST /payment/payInfo/update
Content-Type: application/json

{
"chainId": 1,
"currencyId": 1,
"outTradeNo": "P2026010100000001"
}

Key Parameters

ParameterDescriptionExample Value
orderNoOrder number returned after step 2P2026010100000001
currencyIdCurrency ID; TRX corresponds to 11
Important Notice

currencyId must be set to 1 (TRX's ID), otherwise subsequent TRX payments will not be recognized as valid. If the call fails, verify that TRX currency was successfully enabled in step 1.

4. Retrieve Sub-Contract Wallet Address from Orderโ€‹

After updating payment information, use the "Query Payment Order Details" or "Query Payment Page Info" API to retrieve the sub-contract wallet receiving address associated with the order.

Address Purpose

The payment collection sub-contract is the sub-contract wallet address that will be deployed. Save this address to your batch task list for transferring 0.01 TRX in subsequent steps.

5. Transfer 0.01 TRX to the Sub-Contract Addressโ€‹

Using any exchange or wallet (e.g., TronLink, Binance, OKX, etc.), transfer 0.01 TRX to the payment collection sub-contract address obtained in step 4.

6. Wait for Sub-Contract Wallet Deploymentโ€‹

After on-chain confirmation (typically within 1 minute), the system will detect the TRX transfer transaction and automatically trigger the sub-contract deployment logic. Once deployment completes, the new sub-contract wallet is ready to use as an independent payment-receiving address.

Ways to Confirm Sub-Contract Deployment Success

  • Query the address via the TRON blockchain explorer (e.g., Tronscan) to see contract creation transaction records
  • Receive order status change notifications via the merchant callback interface (notifyUrl)
  • Call the "Query Payment Order Details" API again to verify the order status has been updated

7. Batch Looping Operationsโ€‹

Encapsulate steps 2 through 6 in a program loop or batch processing script to batch-generate multiple sub-contract wallets.

8. Disable TRX Currency After Completionโ€‹

After batch creation is complete, disable TRX currency from the admin console to prevent accidental use of the TRX payment channel for regular payment collection operations.

Steps

  • Log in to the admin console using an admin wallet
  • Navigate to "System Configuration โ†’ Currency List"
  • Click "Manage Currencies", then in the dialog that appears, click the "ร—" next to TRX (TRX) to remove it
  • Click "Submit"
  • Confirm via wallet signature (similar to step 1.3)
Operation Instructions

The process for disabling TRX currency is identical to step 1 (enabling currency), with the only difference being: uncheck TRX from the dropdown list. After removal, already-deployed sub-contract wallets remain unaffected and continue functioning normally as payment-receiving addresses.