2. RESTful 接口
2.1 账户接口
(1) 获取新钱包
接口:/v1/wallet/new,GET方法
返回参数:
参数 | 类型 | 说明 |
---|---|---|
success | Boolean | 请求结果 |
wallet | Object | 钱包 |
address | String | 钱包地址 |
secret | String | 私钥 |
注:新获取的钱包为未激活。激活方式:使用支付接口从已激活账户中向新账户转账0.6个SDA。
例子:
https://cable.sdchain.io/v1/wallet/new
返回结果:
{
"wallet": {
"address": "6wDwUi99cwgiEv8Zb3whNUzqWpyi7Jm6KX",
"secret": "ss6Vi*************pDAJ"
},
"success": true
}
(2) 获得账户余额
接口:/v1/accounts/balances/{:address},GET方法
接口参数:
参数 | 类型 | 说明 |
---|---|---|
address | String | 用户的六域链地址 |
请求参数:
参数 | 类型 | 说明 |
---|---|---|
currency | String | 通证名称 |
counterparty | String | 发行商地址 |
marker | String | 下一页参数 |
limit | String | 每页显示条数,当值为“all”时返回全部 |
返回参数:
参数 | 类型 | 说明 |
---|---|---|
success | Boolean | 请求结果 |
ledger | Integer | 区块高度 |
balances | Array | 余额,对象数组 |
value | String | 数量 |
currency | String | 通证符号 |
counterparty | String | 发行方,当通证为SDA时为空 |
例子:
https://cable.sdchain.io/v1/accounts/balances/6faLUhmp9gNgS9jXS3rAWbg8hFfi9PbWH5
返回结果:
{
"ledger": 92261,
"balances": [
{
"value": "1959.99994",
"currency": "SDA",
"counterparty": ""
}
],
"success": true
}
2.2 账户设置
(1) 查看账户信息
接口:/v1/accounts/settings/{:address},GET方法
接口参数:
参数 | 类型 | 说明 |
---|---|---|
address | String | 六域链地址 |
返回参数:
参数 | 类型 | 说明 |
---|---|---|
success | Boolean | 请求结果 |
settings | Object | 设置信息 |
account | String | 六域链地址 |
default_spread | String | 是否能流通 默认false,作为发行商时设置为true |
例子:
https://cable.sdchain.io/v1/accounts/settings/6hZD8GnU3j9qcCCf9b9yaJbuZUNtWEV9Zc
返回结果:
{
"settings": {
"account": "6hZD8GnU3j9qcCCf9b9yaJbuZUNtWEV9Zc",
"default_spread": false
},
"success": true
}
(2) 账户设置
接口:/v1/accounts/settings/{:address},POST方法
接口参数:
参数 | 类型 | 说明 |
---|---|---|
address | String | 六域链地址 |
提交参数:
参数 | 类型 | 说明 |
---|---|---|
secret | String | 私钥 |
settings | Object | 设置信息 |
default_spread | String | 是否能流通 默认false,作为发行商时设置为true |
返回参数:
参数 | 类型 | 说明 |
---|---|---|
success | Boolean | 请求结果 |
hash | String | 交易hash |
ledger | String | 区块高度 |
state | String | 交易状态 |
settings | Object | 设置信息 |
account | String | 六域链地址 |
default_spread | String | 是否能流通,默认false,作为发行商时设置为true |
例子:
https://cable.sdchain.io/v1/accounts/settings/6hZD8GnU3j9qcCCf9b9yaJbuZUNtWEV9Zc
提交的数据:
{
"secret": "snoNfF********fgXvmT3c",
"settings": {
"default_spread":false
}
}
返回结果:
{
"settings": {
"default_spread": false
},
"hash": "113085DCB6783C8E8C6689F2F4C07CC8DC5BA8461F9E3E99C4984FBB0DE3C115",
"ledger": "354718",
"state": "pending",
"success": true
}
2.3 支付接口
(1) 支付请求
接口:/v1/accounts/payments/{:source_address}?submit=true,POST方法
接口参数:
参数 | 类型 | 说明 |
---|---|---|
address | String | 六域链地址 |
提交参数:
参数 | 类型 | 说明 |
---|---|---|
secret | String | 私钥 |
payment | Object | 支付对象 |
source_account | String | 发起账号 |
destination_account | String | 目标账号 |
destination_tag | String(Integer) | 转账标志(可选) |
amount | Object | 支付金额对象 |
value | String | 数量 |
currency | String | 通证名称 |
issuer | String | 发行商地址,currency等于SDA时为空 |
memos | Array | 备注数组(可选) |
memo_type | String(字母+数字) | 备注类型 |
memo_data | String | 备注内容 |
返回参数:
参数 | 类型 | 说明 |
---|---|---|
success | Boolean | 请求结果 |
hash | String | 支付交易Hash |
status_url | String | 查看交易状态的地址 |
例子:
https://cable.sdchain.io/v1/accounts/payments/6faLUhmp9gNgS9jXS3rAWbg8hFfi9PbWH5
提交的数据:
{
"secret": "saNYbpu4*************3Hhg8kRu",
"payment": {
"source_account": "6faLUhmp9gNgS9jXS3rAWbg8hFfi9PbWH5",
"destination_account": "6PrXdWVoXzmGCmi56wTFTC3e6xezLWh2dc",
"amount":{
"value": "5.01",
"currency": "SDA",
"issuer": ""
},
"memos": [
{
"memo_type": "memos",
"memo_data": "第一笔交易"
}
]
}
}
返回结果:
{
"hash": "12C323E8DEAF789B790E4837438E5E59E95CA888979B4BE1311CA4BEDAF7C05E",
"status_url": "https://cable.sdchain.io/v1/accounts/payments/6faLUhmp9gNgS9jXS3rAWbg8hFfi9PbWH5/12C323E8DEAF789B790E4837438E5E59E95CA888979B4BE1311CA4BEDAF7C05E",
"success": true
}
(2)获得支付信息
接口:/v1/accounts/payments/{:address}/{:hash},GET方法
接口参数:
参数 | 类型 | 说明 |
---|---|---|
address | String | 六域链地址 |
hash | String | 交易Hash |
返回参数:
参数 | 类型 | 说明 |
---|---|---|
success | Boolean | 请求结果 |
hash | String | 交易Hash |
ledger | String | 区块高度 |
state | String | 状态(validated :已完成;pending:交易中) |
source_account | String | 付款方 |
destination_account | String | 收款方 |
direction | String | 交易类型 |
amount | Object | 交易金额对象 |
timestamp | String | 交易时间(UTC) |
date | Integer | 交易时间(s) |
fee | String | 费率 |
memos | Array | 支付的备注,对象数组 |
memo_type | String | 备注类型(hex值) |
memo_data | String | 备注内容(hex值) |
返回结果:
{
"hash": "12C323E8DEAF789B790E4837438E5E59E95CA888979B4BE1311CA4BEDAF7C05E",
"ledger": "86520",
"state": "validated",
"source_account": "6faLUhmp9gNgS9jXS3rAWbg8hFfi9PbWH5",
"destination_account": "6PrXdWVoXzmGCmi56wTFTC3e6xezLWh2dc",
"destination_tag": "",
"amount": {
"currency": "SDA",
"value": "20",
"issuer": ""
},
"currency": "SDA",
"issuer": "",
"direction": "outgoing",
"timestamp": "2018-03-06T08:15:42.000Z",
"date": 1520324142,
"fee": "0.000012",
"memos": [
{
"memo_type": "6D656D6F73",
"memo_data": "E7ACACE4B880E7AC94E4BAA4E69893"
}
],
"success": true
}
(3)获得支付历史
接口:/v1/accounts/payments/{:address},GET方法
接口参数:
参数 | 类型 | 说明 |
---|---|---|
address | String | 六域链地址 |
请求参数:
参数 | 类型 | 说明 |
---|---|---|
source_account | String | 支付方的六域链地址,可选 |
destination_account | String | 收款方的六域链地址,可选 |
direction | String | 交易类型,可选值incoming:收款,outgoing:支付,可选 |
start_ledger | Integer | 起始区块高度,可选 |
end_ledger | Integer | 结束区块高度,可选 |
per_page | Integer | 每页数量,可选 |
page | Integer | 页码,可选 |
返回参数:
参数 | 类型 | 说明 |
---|---|---|
success | Boolean | 请求结果 |
payments | Array | 支付历史,同交易记录中的信息 |
例子:
https://cable.sdchain.io/v1/accounts/payments/6faLUhmp9gNgS9jXS3rAWbg8hFfi9PbWH5?per_page=2&page=1
{
"payments": [
{
"hash": "BB4839ABD6484C4AC814F1C3AF651A1FE5808703BA9D6901CC2E14EF677784D7",
"ledger": "1125346",
"source_account": "6faLUhmp9gNgS9jXS3rAWbg8hFfi9PbWH5",
"destination_account": "6JmTAjeQpXUMZACgGRNwvUG9EMSZmcBXU6",
"amount": {
"currency": "SDA",
"value": "0.02",
"issuer": ""
},
"direction": "outgoing",
"timestamp": "2018-04-18T10:58:50.000Z",
"date": 1524049130,
"fee": "0.0001",
"memos": [
{
"memo_type": "6D656D6F",
"memo_data": "546869732069732061206D656D6F21"
}
]
},
{
"hash": "81F36B67F23DF5E4D651EBA39537239E02A1F78534A48F05C010C4CF852F1768",
"ledger": "1125346",
"source_account": "6faLUhmp9gNgS9jXS3rAWbg8hFfi9PbWH5",
"destination_account": "6JmTAjeQpXUMZACgGRNwvUG9EMSZmcBXU6",
"amount": {
"currency": "SDA",
"value": "0.02",
"issuer": ""
},
"direction": "outgoing",
"timestamp": "2018-04-18T10:58:50.000Z",
"date": 1524049130,
"fee": "0.0001"
}
],
"success": true
}
2.4 授信接口
(1)查看授信记录
接口:/v1/accounts/trustlines/{:address},GET方法
接口参数:
参数 | 类型 | 说明 |
---|---|---|
address | String | 六域链地址 |
返回参数:
参数 | 类型 | 说明 |
---|---|---|
success | Boolean | 请求结果 |
trustlines | Object | 授信信息 |
account | String | 六域链地址 |
currency | String | 通证名称 |
counterparty | String | 授信方 |
limit | String | 限制持有的最大数量 |
reciprocated_limit | String | 对方限制持有的最大数量 |
例子:
https://cable.sdchain.io/v1/accounts/trustlines/6hZD8GnU3j9qcCCf9b9yaJbuZUNtWEV9Zc
返回结果:
{
"ledger": 355849,
"validated": true,
"trustlines": [
{
"account": "6hZD8GnU3j9qcCCf9b9yaJbuZUNtWEV9Zc",
"counterparty": "6E7gcs7TS3by2iZCXrjYZkD2HthJcph34y",
"currency": "USD",
"limit": "500",
"reciprocated_limit": "0"
}
],
"success": true
}
(2)授信/取消授信
接口:/v1/accounts/trustlines/{:address},POST方法
接口参数:
参数 | 类型 | 说明 |
---|---|---|
address | String | 六域链地址 |
提交参数:
参数 | 类型 | 说明 |
---|---|---|
secret | String | 私钥 |
trustline | Object | 授信信息 |
currency | String | 通证名称 |
counterparty | String | 授信方 |
limit | String | 限制持有的最大数量(取消授信时,设置为0,生效前提:余额为0) |
account_allows_sdchaining | Boolean | 取消授信时,设置为false,生效前提:余额为0 |
返回参数:
参数 | 类型 | 说明 |
---|---|---|
success | Boolean | 请求结果 |
hash | String | 交易hash |
ledger | String | 区块高度 |
state | String | 交易状态 |
trustline | Object | 授信信息 |
currency | String | 通证名称 |
counterparty | String | 授信方 |
limit | String | 限制持有的最大数量 |
例子:
https://cable.sdchain.io/v1/accounts/trustlines /6hZD8GnU3j9qcCCf9b9yaJbuZUNtWEV9Zc
提交的数据:
{
"secret": "snoNfFVWPK******vefgXvmT3c",
"trustline": {
"limit": "110",
"currency": "AAA",
"counterparty": "6E7gcs7TS3by2iZCXrjYZkD2HthJcph34y "
}
}
返回结果:
{
"trustline": {
"account": "6hZD8GnU3j9qcCCf9b9yaJbuZUNtWEV9Zc",
"limit": "110",
"currency": "AAA",
"counterparty": "6E7gcs7TS3by2iZCXrjYZkD2HthJcph34y",
"account_allows_sdchaining": true,
"account_trustline_frozen": false
},
"hash": "D8E82E7303B5E8F0B1312F7C2BCB9159A265DE8AD9D773081169224EDD28B1F3",
"ledger": "355976",
"state": "pending",
"success": true
}
2.5 交易历史接口
(1) 获取交易历史
接口:/v1/accounts/transactions/{:address},GET方法
接口参数:
参数 | 类型 | 说明 |
---|---|---|
address | String | 六域链地址 |
请求参数:
参数 | 类型 | 说明 |
---|---|---|
type | String | payment,offercreate,offercancel,trustset,可提供多个用“,”隔开 |
start_ledger | Integer | 起始区块高度,可选 |
end_ledger | Integer | 结束区块高度,可选 |
per_page | Integer | 每页数量,可选 |
page | Integer | 页码,可选 |
返回参数:
参数 | 类型 | 说明 |
---|---|---|
success | Boolean | 请求结果 |
transactions | Array | 交易对象数组 |
hash | String | 交易hash |
ledger | String | 区块高度 |
state | String | 状态 |
account | String | 发起地址 |
date | Integer | 交易时间(s) |
time | String | 交易时间(UTC) |
type | String | 类型 |
fee | String | 费率 |
result | String | 结果 |
price | String | 单价(type=offercreate) |
pair | String | 交易对(type=offercreate) |
seq | Integer | 订单编号(type=offercreate) |
destination_tag | Integer | 交易标志 |
counterparty | String | 对方地址(type=payment) |
amount | Object | 数量对象 |
currency | String | 币种 |
value | String | 数量 |
counterparty | String | 发行商地址 |
effects | Array | 影响 |
effect | String | 影响类型 |
seq | Integer | 订单编号 |
price | String | 单价 |
pair | String | 交易对 |
amount | Object | 数量对象 |
memos | Array | 备注 |
例子:
返回结果:
{
"transactions": [
{
"hash": "BB4839ABD6484C4AC814F1C3AF651A1FE5808703BA9D6901CC2E14EF677784D7",
"ledger": "1125346",
"state": "validated",
"account": "6faLUhmp9gNgS9jXS3rAWbg8hFfi9PbWH5",
"date": 1524049130,
"time": "2018-04-18T10:58:50.000Z",
"type": "outgoing",
"fee": "0.0001",
"result": "tesSUCCESS",
"counterparty": "6JmTAjeQpXUMZACgGRNwvUG9EMSZmcBXU6",
"amount": {
"currency": "SDA",
"value": "0.02",
"issuer": ""
},
"effects": [],
"memos": [
{
"memo_type": "6D656D6F",
"memo_data": "546869732069732061206D656D6F21"
}
]
},
{
"hash": "81F36B67F23DF5E4D651EBA39537239E02A1F78534A48F05C010C4CF852F1768",
"ledger": "1125346",
"state": "validated",
"account": "6faLUhmp9gNgS9jXS3rAWbg8hFfi9PbWH5",
"date": 1524049130,
"time": "2018-04-18T10:58:50.000Z",
"type": "outgoing",
"fee": "0.0001",
"result": "tesSUCCESS",
"counterparty": "6JmTAjeQpXUMZACgGRNwvUG9EMSZmcBXU6",
"amount": {
"currency": "SDA",
"value": "0.02",
"issuer": ""
},
"effects": []
}
],
"success": true
}
(2) 获取交易详情
接口:/v1/transactions/{:hash},GET方法
接口参数:
参数 | 类型 | 说明 |
---|---|---|
hash | String | 交易hash |
返回参数:
参数 | 类型 | 说明 |
---|---|---|
success | Boolean | 请求结果 |
transaction | Object | 交易对象 |
hash | String | 交易hash |
ledger | String | 区块高度 |
state | String | 状态 |
account | String | 发起地址 |
date | Integer | 交易时间(s) |
time | String | 交易时间(UTC) |
type | String | 类型 |
fee | String | 费率 |
result | String | 结果 |
price | String | 单价(type=offercreate) |
pair | String | 交易对(type=offercreate) |
seq | Integer | 订单编号(type=offercreate) |
destination_tag | Integer | 交易标志 |
counterparty | String | 对方地址(type=payment) |
amount | Object | 数量对象 |
currency | String | 币种 |
value | String | 数量 |
counterparty | String | 发行商地址 |
effects | Array | 影响 |
effect | String | 影响类型 |
seq | Integer | 订单编号 |
price | String | 单价 |
pair | String | 交易对 |
amount | Object | 数量对象 |
memos | Array | 备注 |
返回结果:
{
"transaction": {
"hash": "BB4839ABD6484C4AC814F1C3AF651A1FE5808703BA9D6901CC2E14EF677784D7",
"ledger": "1125346",
"state": "validated",
"date": 1524049130,
"type": "Payment",
"fee": "0.0001",
"result": "tesSUCCESS",
"account": "6faLUhmp9gNgS9jXS3rAWbg8hFfi9PbWH5",
"destination": "6JmTAjeQpXUMZACgGRNwvUG9EMSZmcBXU6",
"amount": {
"currency": "SDA",
"value": "0.02",
"issuer": ""
},
"effects": [],
"memos": [
{
"memo_type": "6D656D6F",
"memo_data": "546869732069732061206D656D6F21"
}
]
},
"success": true
}
2.6 服务器基本信息接口
(1) 获取默认费率
接口:/v1/transaction-fee,GET方法
返回参数:
参数 | 类型 | 说明 |
---|---|---|
success | Boolean | 请求结果 |
fee | String | 当前默认费率 |
例子:
https://cable.sdchain.io/v1/transaction-fee
返回结果:
{
"fee": "0.0001",
"success": true
}
(2) 获取服务器信息
接口:/v1/server,GET方法
返回参数:
参数 | 类型 | 说明 |
---|---|---|
success | Boolean | 请求结果 |
sdchaind_server_status | Object | 六域链服务器状况 |
complete_ledgers | String | 完成的区块 |
server_state | String | 服务器状况 |
reserve_base | Double | 激活至少需要的SDA数量 |
reserve_inc | Double | 授信一个冻结的SDA数量 |
例子:
https://cable.sdchain.io/v1/server
返回结果:
{
"sdchaind_server_status": {
"complete_ledgers": "1-2520216",
"server_state": "full",
"reserve_base": 0.6,
"reserve_inc": 0.2
},
"success": true
}
2.7 智能合约接口
(1) 部署智能合约
接口:/v1/accounts/smartContract/{:address},POST方法
接口参数:
参数 | 类型 | 说明 |
---|---|---|
address | String | 六域链地址 |
提交参数:
参数 | 类型 | 说明 |
---|---|---|
secret | String | 私钥 |
smartContract | String | 智能合约代码(lua) |
返回参数:
参数 | 类型 | 说明 |
---|---|---|
success | Boolean | 请求结果 |
hash | String | 交易hash |
ledger | String | 区块高度 |
state | String | 交易状态 |
smartContract | String | 智能合约代码 |
例子:
https://cable.sdchain.io/v1/accounts/smartContract/6hZD8GnU3j9qcCCf9b9yaJbuZUNtWEV9Zc
{
"secret": "snoNfF********fgXvmT3c",
"smartContract":" for i=10,1,-1 do print(i);print(\"Hello SmartContract\");end; "
}
返回结果:
{
"smartContract": " for i=10,1,-1 do print(i);print(\"Hello SmartContract\");end; ",
"hash": "3B5FC73019C8CA77791D6BAA3D8D80FC9AD5AC87797574CE76C457B3A5287E5F",
"ledger": "256901",
"state": "pending",
"success": true
}
(2) 调用智能合约
接口:/v1/smartContract/{:hash},POST方法
接口参数:
参数 | 类型 | 说明 |
---|---|---|
hash | String | 智能合约hash |
提交参数:
参数 | 类型 | 说明 |
---|---|---|
secret | String | 私钥 |
txJson | Object | 提交参数 |
返回参数:
参数 | 类型 | 说明 |
---|---|---|
success | Boolean | 请求结果 |
smart_contract | String/Object | 返回结果 |
提交的数据:
{
"txJson": {
"option1":"123"
}
}
返回结果:
{
"smart_contract": "my smart contract success",
"success": true
}