TRXMarket
Search…
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:
1
{
2
"contract_address": "4155ac3875ceaf0dfe45fe3ee7312b0994a8894097",
3
"owner_address": "417829b0adcb34405331a9910c646b5b71aeddc564",
4
"function_selector": "buyOrder(trcToken,uint256,uint256,uint256)",
5
"fee_limit": 1000000000,
6
"call_value": 10800000,
7
"parameter":"00000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d60"
8
}
Copied!
Response:
1
{
2
"result": {
3
"result": true
4
},
5
"transaction": {
6
"txID": "a5ff588fb894a7a3e1e30d8053a4af229256a992702cf96eef8a94f14f3ce6c4",
7
"raw_data": {
8
"contract": [{
9
"parameter": {
10
"value": {
11
"data": "92bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d60",
12
"owner_address": "417829b0adcb34405331a9910c646b5b71aeddc564",
13
"contract_address": "4155ac3875ceaf0dfe45fe3ee7312b0994a8894097",
14
"call_value": 10800000
15
},
16
"type_url": "type.googleapis.com/protocol.TriggerSmartContract"
17
},
18
"type": "TriggerSmartContract"
19
}],
20
"ref_block_bytes": "403f",
21
"ref_block_hash": "982eee329c44b3e0",
22
"expiration": 1559128395000,
23
"fee_limit": 1000000000,
24
"timestamp": 1559128336448
25
},
26
"raw_data_hex": "0a02403f2208982eee329c44b3e040f899ad9ab02d5af501081f12f0010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412ba010a15417829b0adcb34405331a9910c646b5b71aeddc56412154155ac3875ceaf0dfe45fe3ee7312b0994a8894097188097930522840192bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d6070c0d0a99ab02d90018094ebdc03"
27
}
28
Copied!
步骤二:调用 https://api.trongrid.io/wallet/gettransactionsign 接口获取签名
Bodydata:
1
{
2
"transaction": {
3
"txID": "a5ff588fb894a7a3e1e30d8053a4af229256a992702cf96eef8a94f14f3ce6c4",
4
"raw_data": {
5
"contract": [{
6
"parameter": {
7
"value": {
8
"data": "92bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d60",
9
"owner_address": "417829b0adcb34405331a9910c646b5b71aeddc564",
10
"contract_address": "4155ac3875ceaf0dfe45fe3ee7312b0994a8894097",
11
"call_value": 10800000
12
},
13
"type_url": "type.googleapis.com/protocol.TriggerSmartContract"
14
},
15
"type": "TriggerSmartContract"
16
}],
17
"ref_block_bytes": "403f",
18
"ref_block_hash": "982eee329c44b3e0",
19
"expiration": 1559128395000,
20
"fee_limit": 1000000000,
21
"timestamp": 1559128336448
22
},
23
"raw_data_hex": "0a02403f2208982eee329c44b3e040f899ad9ab02d5af501081f12f0010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412ba010a15417829b0adcb34405331a9910c646b5b71aeddc56412154155ac3875ceaf0dfe45fe3ee7312b0994a8894097188097930522840192bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d6070c0d0a99ab02d90018094ebdc03"
24
},
25
"privateKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
26
}
Copied!
Response:
1
{
2
"txID": "52523b1bd2dca85e331410a49882481931a1171547626885ddf6bdb66e4cd8b2",
3
"raw_data": {
4
"contract": [{
5
"parameter": {
6
"value": {
7
"data": "92bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d60",
8
"owner_address": "4195b0aae7bd38e267b77a638645b5ca9e478bab3d",
9
"contract_address": "4155ac3875ceaf0dfe45fe3ee7312b0994a8894097",
10
"call_value": 10800000
11
},
12
"type_url": "type.googleapis.com/protocol.TriggerSmartContract"
13
},
14
"type": "TriggerSmartContract"
15
}],
16
"ref_block_bytes": "42b7",
17
"ref_block_hash": "d02cf213e52af30d",
18
"expiration": 1559130303000,
19
"fee_limit": 1000000000,
20
"timestamp": 1559130244468
21
},
22
"raw_data_hex": "0a0242b72208d02cf213e52af30d4098d4a19bb02d5af501081f12f0010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412ba010a154195b0aae7bd38e267b77a638645b5ca9e478bab3d12154155ac3875ceaf0dfe45fe3ee7312b0994a8894097188097930522840192bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d6070f48a9e9bb02d90018094ebdc03",
23
"signature": ["77e2cb756ef2dde0ec3aa646e392f7687d15d5a0be0fa0f38e3956224f42f9e5dbeefe137d658cd1e3207edcfcba860d76a6389ba1671407835901f5d0ade7be00"]
24
}
25
Copied!
步骤三:调用 https://api.trongrid.io/wallet/broadcasttransaction 对交易进行广播
Bodydata:
1
{
2
"txID": "52523b1bd2dca85e331410a49882481931a1171547626885ddf6bdb66e4cd8b2",
3
"raw_data": {
4
"contract": [{
5
"parameter": {
6
"value": {
7
"data": "92bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d60",
8
"owner_address": "4195b0aae7bd38e267b77a638645b5ca9e478bab3d",
9
"contract_address": "4155ac3875ceaf0dfe45fe3ee7312b0994a8894097",
10
"call_value": 10800000
11
},
12
"type_url": "type.googleapis.com/protocol.TriggerSmartContract"
13
},
14
"type": "TriggerSmartContract"
15
}],
16
"ref_block_bytes": "42b7",
17
"ref_block_hash": "d02cf213e52af30d",
18
"expiration": 1559130303000,
19
"fee_limit": 1000000000,
20
"timestamp": 1559130244468
21
},
22
"raw_data_hex": "0a0242b72208d02cf213e52af30d4098d4a19bb02d5af501081f12f0010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412ba010a154195b0aae7bd38e267b77a638645b5ca9e478bab3d12154155ac3875ceaf0dfe45fe3ee7312b0994a8894097188097930522840192bf4d4600000000000000000000000000000000000000000000000000000000000f476400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000a4cb800000000000000000000000000000000000000000000000000000000000083d6070f48a9e9bb02d90018094ebdc03",
23
"signature": ["77e2cb756ef2dde0ec3aa646e392f7687d15d5a0be0fa0f38e3956224f42f9e5dbeefe137d658cd1e3207edcfcba860d76a6389ba1671407835901f5d0ade7be00"]
24
}
Copied!
Response:
1
{
2
"result": true
3
}
Copied!
Last modified 2yr ago
Copy link