TRC10 Pending Order

Step-by-step Instructions

Step 1: Trigger the smart contract to create an order transaction (get ID) through the API service provided by TronGrid

Step 2: Sign the transaction

Step 3: Broadcast the transaction

Please refer to Contract Trigger, API Signature, and Broadcasting Process for detailed documentation.

Contract Address

The base token is TRC10 and the quote token is TRX: 4155ac3875ceaf0dfe45fe3ee7312b0994a8894097

Contract method

Buy in: buyOrder(trcToken, uint256, uint256, uint256)

Sell out: sellOrder(trcToken, uint256, uint256, uint256)

Parameter Description

The following descriptions are on the parameters involved in contract triggering.

call_value

TRX consumption calculated in sun. When an order consumes TRX, this has to be filled in. An incorrect value may result in failed order.

For example, if a user wishes to buy 10 BTT at a price of 10 TRX each, then the user should fill in 100,000,000 here. Note: 1 TRX = 1,000,000 sun.

parameter

This field is the required parameter for "buyOrder/sellOrder" contract method.

buyOrder contract method requires 4 parameters and each parameter is a 64-digit string. When the 4 strings are connected end to end, they make up the parameter.

Parameter 1: TokenID of the token to be purchased. Convert the number into a hex string of numbers. If the number of digits is under 64, add "0"s to the front of the string to make up for it.

Parameter 2: Purchase quantity. Convert the number to a hex string of numbers. If the number of digits is under 64, add "0"s to the front of the string to make up for it.

Parameter 3: TRX consumption. It is consistent with the value of the call_value parameter. Convert the number to a hex string of numbers. If the number of digits is under 64, add "0"s to the front of the string to make up for it.

Parameter 4: Purchase price. Convert the number to a hex string of numbers. If the number of digits is under 64, add "0"s to the front of the string to make up for it.

sellOrder contract method requires 4 parameters and each parameter is a 64-digit string. When the 4 strings are connected end to end, they make up the parameter.

Parameter 1: TokenID of the token to be sold. Convert the number into a hex string of numbers. If the number of digits is under 64, add "0"s to the front of the string to make up for it.

Parameter 2: Sold quantity. Convert the number to a hex string of numbers. If the number of digits is under 64, add "0"s to the front of the string to make up for it.

Parameter 3: TRX revenue. The value must be equal to the sold price multiples by the sold quantity, calculated in sun. Otherwise, the order cannot be put up successfully. Convert the number to a hex string of numbers. If the number of digits is under 64, add "0"s to the front of the string to make up for it.

Parameter 4: Sold price. Convert the number to a hex string of numbers. If the number of digits is under 64, add "0"s to the front of the string to make up for it.

call_token_value

The number of TRC10 tokens consumed; the decimal needs to be filled. If an order needs to consume TRC10 tokens, the value has to be filled in correctly. Otherwise, the order cannot be placed.

For example, if a user wishes to sell 10 BTT at a price of 10 TRX each, then the user should fill in 100,000,000 here.

token_id

The ID of the TRC10 token to be consumed.

For example, if a user wishes to sell 10 BTT at a price of 10 TRX each, then the user should fill in 1,002,000 here.

Example

User TLva2m6sx2Ya44kHUN2GZUF2PT5KcCNNUQ submits a buy order of 20 TSY at the price of 0.54 TRX.

Step 1: POST https://api.trongrid.io/wallet/triggersmartcontract to trigger contract

Bodydata:

{
"contract_address": "4155ac3875ceaf0dfe45fe3ee7312b0994a8894097",
"owner_address": "417829b0adcb34405331a9910c646b5b71aeddc564",
"function_selector": "buyOrder(trcToken,uint256,uint256,uint256)",
"fee_limit": 1000000000,
"call_value": 10800000,
"parameter":"00000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d60"
}

Response:

{
"result": {
"result": true
},
"transaction": {
"txID": "a5ff588fb894a7a3e1e30d8053a4af229256a992702cf96eef8a94f14f3ce6c4",
"raw_data": {
"contract": [{
"parameter": {
"value": {
"data": "92bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d60",
"owner_address": "417829b0adcb34405331a9910c646b5b71aeddc564",
"contract_address": "4155ac3875ceaf0dfe45fe3ee7312b0994a8894097",
"call_value": 10800000
},
"type_url": "type.googleapis.com/protocol.TriggerSmartContract"
},
"type": "TriggerSmartContract"
}],
"ref_block_bytes": "403f",
"ref_block_hash": "982eee329c44b3e0",
"expiration": 1559128395000,
"fee_limit": 1000000000,
"timestamp": 1559128336448
},
"raw_data_hex": "0a02403f2208982eee329c44b3e040f899ad9ab02d5af501081f12f0010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412ba010a15417829b0adcb34405331a9910c646b5b71aeddc56412154155ac3875ceaf0dfe45fe3ee7312b0994a8894097188097930522840192bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d6070c0d0a99ab02d90018094ebdc03"
}
}

Step 2: Calls https://api.trongrid.io/wallet/gettransactionsign to get signature

Bodydata:

{
"transaction": {
"txID": "a5ff588fb894a7a3e1e30d8053a4af229256a992702cf96eef8a94f14f3ce6c4",
"raw_data": {
"contract": [{
"parameter": {
"value": {
"data": "92bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d60",
"owner_address": "417829b0adcb34405331a9910c646b5b71aeddc564",
"contract_address": "4155ac3875ceaf0dfe45fe3ee7312b0994a8894097",
"call_value": 10800000
},
"type_url": "type.googleapis.com/protocol.TriggerSmartContract"
},
"type": "TriggerSmartContract"
}],
"ref_block_bytes": "403f",
"ref_block_hash": "982eee329c44b3e0",
"expiration": 1559128395000,
"fee_limit": 1000000000,
"timestamp": 1559128336448
},
"raw_data_hex": "0a02403f2208982eee329c44b3e040f899ad9ab02d5af501081f12f0010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412ba010a15417829b0adcb34405331a9910c646b5b71aeddc56412154155ac3875ceaf0dfe45fe3ee7312b0994a8894097188097930522840192bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d6070c0d0a99ab02d90018094ebdc03"
},
"privateKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}

Response:

{
"txID": "52523b1bd2dca85e331410a49882481931a1171547626885ddf6bdb66e4cd8b2",
"raw_data": {
"contract": [{
"parameter": {
"value": {
"data": "92bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d60",
"owner_address": "4195b0aae7bd38e267b77a638645b5ca9e478bab3d",
"contract_address": "4155ac3875ceaf0dfe45fe3ee7312b0994a8894097",
"call_value": 10800000
},
"type_url": "type.googleapis.com/protocol.TriggerSmartContract"
},
"type": "TriggerSmartContract"
}],
"ref_block_bytes": "42b7",
"ref_block_hash": "d02cf213e52af30d",
"expiration": 1559130303000,
"fee_limit": 1000000000,
"timestamp": 1559130244468
},
"raw_data_hex": "0a0242b72208d02cf213e52af30d4098d4a19bb02d5af501081f12f0010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412ba010a154195b0aae7bd38e267b77a638645b5ca9e478bab3d12154155ac3875ceaf0dfe45fe3ee7312b0994a8894097188097930522840192bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d6070f48a9e9bb02d90018094ebdc03",
"signature": ["77e2cb756ef2dde0ec3aa646e392f7687d15d5a0be0fa0f38e3956224f42f9e5dbeefe137d658cd1e3207edcfcba860d76a6389ba1671407835901f5d0ade7be00"]
}

Step 3: POST https://api.trongrid.io/wallet/broadcasttransaction to broadcast the transaction

Bodydata:

{
"txID": "52523b1bd2dca85e331410a49882481931a1171547626885ddf6bdb66e4cd8b2",
"raw_data": {
"contract": [{
"parameter": {
"value": {
"data": "92bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d60",
"owner_address": "4195b0aae7bd38e267b77a638645b5ca9e478bab3d",
"contract_address": "4155ac3875ceaf0dfe45fe3ee7312b0994a8894097",
"call_value": 10800000
},
"type_url": "type.googleapis.com/protocol.TriggerSmartContract"
},
"type": "TriggerSmartContract"
}],
"ref_block_bytes": "42b7",
"ref_block_hash": "d02cf213e52af30d",
"expiration": 1559130303000,
"fee_limit": 1000000000,
"timestamp": 1559130244468
},
"raw_data_hex": "0a0242b72208d02cf213e52af30d4098d4a19bb02d5af501081f12f0010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412ba010a154195b0aae7bd38e267b77a638645b5ca9e478bab3d12154155ac3875ceaf0dfe45fe3ee7312b0994a8894097188097930522840192bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d6070f48a9e9bb02d90018094ebdc03",
"signature": ["77e2cb756ef2dde0ec3aa646e392f7687d15d5a0be0fa0f38e3956224f42f9e5dbeefe137d658cd1e3207edcfcba860d76a6389ba1671407835901f5d0ade7be00"]
}

Response:

{
"result": true
}