TRC10 下单

步骤说明

步骤一:通过 TronGrid 提供的接口服务触发智能合约创建订单事务(获取 ID)

步骤二:对事务进行签名

步骤三:广播事务

详细文档见 触发合约 和 API签名和广播流程。

合约地址

基础币种为TRC10且报价币种为TRX:4155ac3875ceaf0dfe45fe3ee7312b0994a8894097

合约方法

买入:buyOrder(trcToken,uint256,uint256,uint256)

卖出:sellOrder(trcToken,uint256,uint256,uint256)

参数说明

以下只对调用合约时部分参数进行说明。

call_value

消耗的 TRX 数量,单位:sun。当订单需要消耗 TRX 时必须填入,若数值不正确则可能导致下单失败。

例如:用户希望以10 TRX 每个的价格买入10个 BTT,则此处应该填入100000000。注:1 TRX 等于1000000 sun。

parameter

该字段为合约方法 buyOrder / sellOrder 需要传入的参数。

buyOrder 合约方法共有4个参数需要传入,每个参数都是一个长度为64的字符串,将这四个字符串首尾相连组成该parameter字段。

参数1:所要购买的 tokenID;将该值转换为16进制的数字字符串后,把该字符串之前不足64位字符的部分用0补齐。

参数2:购买数量;需要补齐精度,将该值转换为16进制的数字字符串后,把该字符串之前不足64位字符的部分用0补齐

参数3:消耗 TRX 数量;与 call_value 参数取值一致,将该值转换为16进制的数字字符串后,把该字符串之前不足64位字符的部分用0补齐。

参数4:购买价格;单位 sun,将该值转换为16进制的数字字符串后,把该字符串之前不足64位字符的部分用0补齐。

sellOrder 合约方法共有4个参数需要传入,每个参数都是一个长度为64的字符串,将这四个字符串首尾相连组成该 parameter 字段。

参数1:所要卖出 tokenID;将该值转换为16进制的数字字符串后,把该字符串之前不足64位字符的部分用0补齐

参数2:卖出数量;需要补齐精度,将该值转换为16进制的数字字符串后,把该字符串之前不足64位字符的部分用0补齐。

参数3:收入 TRX 数量;该值必须等于卖出价格乘卖出数量,否则挂单不会成功,单位 sun,将该值转换为16进制的数字字符串后,把该字符串之前不足64位字符的部分用0补齐。注:1 TRX 等于1000000 sun。

参数4:卖出价格;单位 sun,将该值转换为16进制的数字字符串后,把该字符串之前不足64位字符的部分用0补齐。

call_token_value

消耗 TRC10 token 数量;需要补齐精度。当订单需要消耗 TRC10 token时必须填入,若数值不正确则可能导致下单失败。

例如:用户希望以10 TRX 每个的价格卖出10个 BTT,则此处应该填入100000000。

token_id

需要消耗的 TRC10 token ID。

例如:用户希望以10 TRX 每个的价格卖出10个BTT,则此处应该填入1002000。

示例

用户 TLva2m6sx2Ya44kHUN2GZUF2PT5KcCNNUQ 提交一笔价格为0.54 TRX,数量为20的 TSY 买单

步骤一:调用 https://api.trongrid.io/wallet/triggersmartcontract 接口触发合约

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"
}

步骤二:调用 https://api.trongrid.io/wallet/gettransactionsign 接口获取签名

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"]
}

步骤三:调用 https://api.trongrid.io/wallet/broadcasttransaction 对交易进行广播

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
}