The TRON Developer Hub

Welcome to the TRON developer hub. You'll find comprehensive guides and documentation to help you start working with TRON as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

TRC20-USDT Introduction

This article mainly describes how to use the Http interface of the TRC20-USDT contract.
TRC20-USDT is a smart contract based on TRC20 protocol.

Standard Interface Reference:
https://developers.tron.network/docs/trc10-token#section-trc10-trc20-comparison

TRC20 smart contract example:
https://github.com/tronprotocol/tron-contracts/tree/master/contracts/tokens/TRC20

Here are some examples of HTTP interfaces:

1.Deploy a contract

Example

curl -X POST  http://127.0.0.1:8090/wallet/deploycontract -d '{"abi":"[{\"constant\":false,\"inputs\":[{\"name\":\"key\",\"type\":\"uint256\"},{\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"key\",\"type\":\"uint256\"}],\"name\":\"get\",\"outputs\":[{\"name\":\"value\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]","bytecode":"608060405234801561001057600080fd5b5060de8061001f6000396000f30060806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631ab06ee58114604d5780639507d39a146067575b600080fd5b348015605857600080fd5b506065600435602435608e565b005b348015607257600080fd5b50607c60043560a0565b60408051918252519081900360200190f35b60009182526020829052604090912055565b600090815260208190526040902054905600a165627a7a72305820fdfe832221d60dd582b4526afa20518b98c2e1cb0054653053a844cf265b25040029","parameter":"","call_value":100,"name":"SomeContract","consume_user_resource_percent":30,"fee_limit":10,"origin_energy_limit": 10,"owner_address":"41D1E7A6BC354106CB410E65FF8B181C600FF14292"}'

Parameter abi: Abi
Parameter bytecode: Bytecode, default hexString
Parameter parameter: The list of the parameters of the constructor, It should be converted hexString
after encoded according to ABI encoder. If constructor has no parameter, this can be optional
Parameter consume_user_resource_percent: Consume user's resource percentage. It should be an
integer between [0, 100]. if 0, means it does not consume user's resource until the developer's resource has been used up
Parameter fee_limit: The maximum TRX burns for resource consumption
Parameter call_value: The TRX transfer to the contract for each call
Parameter call_token_value: The amount of trc10 token transfer to the contract for each call (Optional)
Parameter token_id: The id of trc10 token transfer to the contract (Optional)
Parameter owner_address: Owner address of the contract, default hexString
Parameter name: Contract name
Parameter origin_energy_limit: The maximum resource consumption of the creator in one execution or
creation
Parameter permission_id: Optional, for multi-signature use
Return: Transaction object
Note: The unit of TRX in the parameters is SUN

2.Trigger a contract function

Example

curl -X POST  http://127.0.0.1:8090/wallet/triggersmartcontract -d '{"contract_address":"4189139CB1387AF85E3D24E212A008AC974967E561","function_selector":"set(uint256,uint256)","parameter":"00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002","fee_limit":10,"call_value":100,"owner_address":"41D1E7A6BC354106CB410E65FF8B181C600FF14292"}'

Parameter contract_address: Contract address, default hexString
Parameter function_selector: Function call, must not leave a blank space
Parameter parameter: The parameter passed to 'function_selector', the format must match with the VM's requirement. You can use a js tool provided by remix to convert a parameter like [1,2] to the format that VM requires
Parameter fee_limit: The maximum TRX burns for resource consumption
Parameter call_value: The TRX transfer to the contract for each call
Parameter call_token_value: The amount of trc10 token transfer to the contract for each call
Parameter token_id: The id of trc10 token transfer to the contract
Parameter owner_address: Owner address that triggers the contract, default hexString
Parameter permission_id: Optional, for multi-signature use
Return: Transaction object
Note: The unit of TRX in the parameters is SUN.
The contract function can be divided into two types from the properties: constant function and non-constant function. Constant function is a function modified with view/pure/constant. The query result is returned directly and don’t need to be signed and broadcasted . A non-constant function will modify the data on blockchain , so need to be signed and broadcasted to blockchain. The function changes the contents of the data on the chain, such as transferring funds, changing the value of the internal variables of the contract, and so on.

3.Query the total amount of tokens

Example

curl -X POST  https://api.shasta.trongrid.io/wallet/triggersmartcontract -d '{"contract_address":"41CD82C21BEC772F7F42DD6E681872F824893B5658","function_selector":"totalSupply()","fee_limit":0,"call_value":0,"owner_address":"417A15ED907BF11729668F8179AE898A7CF30104E1"}'

Return result:
{"result":{"result":true},"constant_result":["0000000000000000000000000000000000000000000000000000000000002710"],"transacti
on":{"ret":[{}],"txID":"c3b6f1dbe1561f7c251402307a2b37c6405caca2441496a2e13a0b7edc94f3b2","raw_data":
{"contract":[{"parameter":{"value":{"data":"18160ddd","owner_address":"417a15ed907bf11729668f8179ae898a7cf30104e1","contract_addr
ess":"41cd82c21bec772f7f42dd6e681872f824893b5658"},"type_url":"type.googleapis.com/protocol.Tri
ggerSmartContract"},"type":"TriggerSmartContract"}],"ref_block_bytes":"4655","ref_block_hash":"7dae3
21a1898cb63","expiration":1552390728000,"timestamp":1552390671220},"raw_data_hex":"0a0246552
2087dae321a1898cb6340c0d2ca8d972d5a6d081f12690a31747970652e676f6f676c65617069732e6
36f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412340a15417a15ed907
bf11729668f8179ae898a7cf30104e1121541cd82c21bec772f7f42dd6e681872f824893b5658220418160
ddd70f496c78d972d"}}

constant_result is the amount of this TRC20 token.
Hex:0000000000000000000000000000000000000000000000000000000000002710
Convert to decimal:10000

4.Query the token name

Example

curl -X POST  https://api.shasta.trongrid.io/wallet/triggersmartcontract -d '{"contract_address":"41AD03159CE01993FB702ED27D84346DD9D1043291","function_selector":"name()","fee_limit":0,"call_value":0,"owner_address":"41517591D35D313BF6A5E33098284502B045E2BC08"}'

Return result:
{"result":{"result":true},"constant_result":["000000000000000000000000000000000000000000000000000000000000002000000000
0000000000000000000000000000000000000000000000000000000a546574686572205553
4400000000000000000000000000000000000000000000"],"transaction":{"ret":[{}],"txID":"9ff00d0ec3debdb0241ccb4c38d52484bc37ed4d8ee2d3a059c5eaafa45a0a59","raw_data":
{"contract":[{"parameter":{"value":{"data":"06fdde03","owner_address":"417a15ed907bf11729668f8179ae898a7cf30104e1","contract_addr
ess":"41cd82c21bec772f7f42dd6e681872f824893b5658"},"type_url":"type.googleapis.com/protocol.Tri
ggerSmartContract"},"type":"TriggerSmartContract"}],"ref_block_bytes":"fd2f","ref_block_hash":"00ae14
6da61c55b4","expiration":1552531200000,"timestamp":1552531141569},"raw_data_hex":"0a02fd2f220
800ae146da61c55b44080b0c8d0972d5a6d081f12690a31747970652e676f6f676c65617069732e636
f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412340a15417a15ed907bf1
1729668f8179ae898a7cf30104e1121541cd82c21bec772f7f42dd6e681872f824893b5658220406fdde0
370c1e7c4d0972d"}}

constant_result is Hex type
Hex: 0000000000000000000000000000000000000000000000000000000000000020000000000
000000000000000000000000000000000000000000000000000000a5465746865722055534
400000000000000000000000000000000000000000000
Convert to decimal:Tether USD

5.Query the abbreviation

Example

curl -X POST  https://api.shasta.trongrid.io/wallet/triggersmartcontract -d '{"contract_address":"41CD82C21BEC772F7F42DD6E681872F824893B5658","function_selector":"symbol()","fee_limit":0,"call_value":0,"owner_address":"417A15ED907BF11729668F8179AE898A7CF30104E1"}'

Return result:
{"result":{"result":true},"constant_result":["000000000000000000000000000000000000000000000000000000000000002000000000
0000000000000000000000000000000000000000000000000000000354542400000000000
00000000000000000000000000000000000000000000000"],"transaction":{"ret":[{}],"txID":"04be55fe05cf0361b41f492b6ab1080b69a52c4bd3b36b3d5c9ffbfb1292ff0a","raw_data":
{"contract":[{"parameter":{"value":{"data":"95d89b41","owner_address":"417a15ed907bf11729668f8179ae898a7cf30104e1","contract_addr
ess":"41cd82c21bec772f7f42dd6e681872f824893b5658"},"type_url":"type.googleapis.com/protocol.Tri
ggerSmartContract"},"type":"TriggerSmartContract"}],"ref_block_bytes":"fdb9","ref_block_hash":"585e0
549e3ab2e81","expiration":1552531614000,"timestamp":1552531555719},"raw_data_hex":"0a02fdb922
08585e0549e3ab2e8140b0d2e1d0972d5a6d081f12690a31747970652e676f6f676c65617069732e6
36f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412340a15417a15ed907
bf11729668f8179ae898a7cf30104e1121541cd82c21bec772f7f42dd6e681872f824893b5658220495d8
9b4170878bded0972d"}}

6.Query precision

Example

curl -X POST  https://api.shasta.trongrid.io/wallet/triggersmartcontract -d '{"contract_address":"41CD82C21BEC772F7F42DD6E681872F824893B5658","function_selector":"decimals()","fee_limit":0,"call_value":0,"owner_address":"417A15ED907BF11729668F8179AE898A7CF30104E1"}'

Return result:
{"result":{"result":true},"constant_result":["0000000000000000000000000000000000000000000000000000000000000006"],"transacti
on":{"ret":[{}],"txID":"96f4ad0e590f64b8b8603486ec92293cd670174127715efd56d1e8190ab62b61","raw_data":
{"contract":[{"parameter":{"value":{"data":"313ce567","owner_address":"417a15ed907bf11729668f8179ae898a7cf30104e1","contract_addr
ess":"41cd82c21bec772f7f42dd6e681872f824893b5658"},"type_url":"type.googleapis.com/protocol.Tri
ggerSmartContract"},"type":"TriggerSmartContract"}],"ref_block_bytes":"fd86","ref_block_hash":"b67fb8
7c769f4246","expiration":1552531461000,"timestamp":1552531403244},"raw_data_hex":"0a02fd86220
8b67fb87c769f42464088a7d8d0972d5a6d081f12690a31747970652e676f6f676c65617069732e636f
6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412340a15417a15ed907bf11
729668f8179ae898a7cf30104e1121541cd82c21bec772f7f42dd6e681872f824893b56582204313ce567
70ece3d4d0972d"}}

7.Query balance

Example

curl -X POST  https://api.shasta.trongrid.io/wallet/triggersmartcontract -d '{"contract_address":"41CD82C21BEC772F7F42DD6E681872F824893B5658","function_selector":"balanceOf(address)","parameter":"0000000000000000000000417A15ED907BF11729668F8179AE898A7CF30104E1","fee_limit":0,"call_value":0,"owner_address":"417A15ED907BF11729668F8179AE898A7CF30104E1"}'

Return result:
{"result":{"result":true},"constant_result":["00000000000000000000000000000000000000000000000000000000000001f4"],"transactio
n":{"ret":[{}],"txID":"04487f70af3451f6e29b662edf078e9b6309989802097c166800be7f42920558","raw_data":
{"contract":[{"parameter":{"value":{"data":"70a082310000000000000000000000417a15ed907bf11729668f8179ae898a7cf30104e1","ow
ner_address":"417a15ed907bf11729668f8179ae898a7cf30104e1","contract_address":"41cd82c21bec77
2f7f42dd6e681872f824893b5658"},"type_url":"type.googleapis.com/protocol.TriggerSmartContract"},"t
ype":"TriggerSmartContract"}],"ref_block_bytes":"8f0d","ref_block_hash":"eebd0bff83529376","expirati
on":1552446594000,"timestamp":1552446537549},"raw_data_hex":"0a028f0d2208eebd0bff8352937
640d0b79ca8972d5a8e01081f1289010a31747970652e676f6f676c65617069732e636f6d2f70726f74
6f636f6c2e54726967676572536d617274436f6e747261637412540a15417a15ed907bf11729668f8179a
e898a7cf30104e1121541cd82c21bec772f7f42dd6e681872f824893b5658222470a082310000000000
000000000000417a15ed907bf11729668f8179ae898a7cf30104e170cdfe98a8972d"}}

Hex:00000000000000000000000000000000000000000000000000000000000001f4
Convert to decimal: 500

8.USDT transfer:

1.Generate a transaction:

curl -X POST  https://api.shasta.trongrid.io/wallet/triggersmartcontract -d '{"contract_address":"41CD82C21BEC772F7F42DD6E681872F824893B5658","function_selector":"transfer(address,uint256)","parameter":"00000000000000000000004115208EF33A926919ED270E2FA61367B2DA3753DA0000000000000000000000000000000000000000000000000000000000000032","fee_limit":100000000,"call_value":0,"owner_address":"417A15ED907BF11729668F8179AE898A7CF30104E1"}'

Return result:
{"result":{"result":true},"transaction":{"txID":"9b0a8ab49fe685453d42b60c8a53b452bdd81c0e7c906eabd0967a188fcffda1","raw_data":
{"contract":[{"parameter":{"value":{"data":"a9059cbb00000000000000000000004115208ef33a926919ed270e2fa61367b2da3753da0
000000000000000000000000000000000000000000000000000000000000032","owner_addr
ess":"417a15ed907bf11729668f8179ae898a7cf30104e1","contract_address":"41cd82c21bec772f7f42dd
6e681872f824893b5658"},"type_url":"type.googleapis.com/protocol.TriggerSmartContract"},"type":"Trig
gerSmartContract"}],"ref_block_bytes":"b4a0","ref_block_hash":"c28712fc60d63941","expiration":15524
75457000,"fee_limit":100000000,"timestamp":1552475399081},"raw_data_hex":"0a02b4a02208c2871
2fc60d6394140e88bfeb5972d5aae01081f12a9010a31747970652e676f6f676c65617069732e636f6d2
f70726f746f636f6c2e54726967676572536d617274436f6e747261637412740a15417a15ed907bf11729
668f8179ae898a7cf30104e1121541cd82c21bec772f7f42dd6e681872f824893b56582244a9059cbb00
000000000000000000004115208ef33a926919ed270e2fa61367b2da3753da0000000000000000
00000000000000000000000000000000000000000000003270a9c7fab5972d900180c2d72f"}}

2.Sign transaction

curl -X POST  https://api.shasta.trongrid.io/wallet/gettransactionsign -d '{
"transaction":{"txID":"9b0a8ab49fe685453d42b60c8a53b452bdd81c0e7c906eabd0967a188fcffda1","raw_data":{"contract":[{"parameter":{"value":{"data":"a9059cbb00000000000000000000004115208ef33a926919ed270e2fa61367b2da3753da0000000000000000000000000000000000000000000000000000000000000032","owner_address":"417a15ed907bf11729668f8179ae898a7cf30104e1","contract_address":"41cd82c21bec772f7f42dd6e681872f824893b5658"},"type_url":"type.googleapis.com/protocol.TriggerSmartContract"},"type":"TriggerSmartContract"}],"ref_block_bytes":"b4a0","ref_block_hash":"c28712fc60d63941","expiration":1552475457000,"fee_limit":100000000,"timestamp":1552475399081}}, "privateKey": "***************************"}'

Return result:
{"signature":["6602dbce8037b3b540cd6af6e6f98724803b5c01a3a115340a94148ef02221577c72a57f042125c29b
599e9753ed6179b35106215598de8f59e09454b8a5211500"],"txID":"9b0a8ab49fe685453d42b60c8a
53b452bdd81c0e7c906eabd0967a188fcffda1","raw_data":{"contract":[{"parameter":{"value":
{"data":"a9059cbb00000000000000000000004115208ef33a926919ed270e2fa61367b2da3753da0
000000000000000000000000000000000000000000000000000000000000032","owner_addr
ess":"417a15ed907bf11729668f8179ae898a7cf30104e1","contract_address":"41cd82c21bec772f7f42dd
6e681872f824893b5658"},"type_url":"type.googleapis.com/protocol.TriggerSmartContract"},"type":"Trig
gerSmartContract"}],"ref_block_bytes":"b4a0","ref_block_hash":"c28712fc60d63941","expiration":15524
75457000,"fee_limit":100000000,"timestamp":1552475399081},"raw_data_hex":"0a02b4a02208c2871
2fc60d6394140e88bfeb5972d5aae01081f12a9010a31747970652e676f6f676c65617069732e636f6d2
f70726f746f636f6c2e54726967676572536d617274436f6e747261637412740a15417a15ed907bf11729
668f8179ae898a7cf30104e1121541cd82c21bec772f7f42dd6e681872f824893b56582244a9059cbb00
000000000000000000004115208ef33a926919ed270e2fa61367b2da3753da0000000000000000
00000000000000000000000000000000000000000000003270a9c7fab5972d900180c2d72f"}

3.Broadcast transaction

curl -X POST  https://api.shasta.trongrid.io/wallet/broadcasttransaction -d '{"signature":["6602dbce8037b3b540cd6af6e6f98724803b5c01a3a115340a94148ef02221577c72a57f042125c29b599e9753ed6179b35106215598de8f59e09454b8a5211500"],"txID":"9b0a8ab49fe685453d42b60c8a53b452bdd81c0e7c906eabd0967a188fcffda1","raw_data":{"contract":[{"parameter":{"value":{"data":"a9059cbb00000000000000000000004115208ef33a926919ed270e2fa61367b2da3753da0000000000000000000000000000000000000000000000000000000000000032","owner_address":"417a15ed907bf11729668f8179ae898a7cf30104e1","contract_address":"41cd82c21bec772f7f42dd6e681872f824893b5658"},"type_url":"type.googleapis.com/protocol.TriggerSmartContract"},"type":"TriggerSmartContract"}],"ref_block_bytes":"b4a0","ref_block_hash":"c28712fc60d63941","expiration":1552475457000,"fee_limit":100000000,"timestamp":1552475399081}}'

broadcast successful:
{'result': True}

broadcast failed:
{'code': 'SIGERROR', 'message': '76616c6964617465207369676e6174757265206572726f7220663666656666326137353731303138
3732313032336534643931363932376230626431653433336666376265386432653834303339613
73433643134616435353433663833323734313162653962613464323635616432663535366363326
63033643839616330373263326633373838663537366161303761366639356365313030206973207
369676e656420627920544e3775535a484c5071415a4e66484a6d424d6e32485939586f3772764c4
e65777820627574206974206973206e6f7420636f6e7461696e6564206f66207065726d69737369
6f6e2e'}

Judge if transaction success ,please refer to the below document:
https://developers.tron.network/docs/transaction#section-transaction-success

9.approve, transferFrom,allowance,increaseApproval,decreaseApproval

These interfaces need to be used together.
Example:
①approve()
Account A allows B to use 100 USDT.
Account A calls approve(B,100)
Call approve(B,100) again, it will overwrite the current value.
Then B can transfer from account A to account C. But the value must less than 100.
②transferFrom()
Account B transfer 10 tokens of account A to the account C.
Account B calls transferFrom(A, C, 10)
③allowance()
Query the balance of account B can transfer from account A.
Account B calls allowance(A, B)
④increaseApproval()
Increase the available USDT amount that account B can use.
Account A calls increaseApproval(B,250)
⑤decreaseApproval()
Reduce the available USDTs amount that account B can use.
decreaseApproval(B,100)

10.Other interface except http

Updated 3 months ago

TRC20-USDT Introduction


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.