🔗質押 API

準備

如需使用API,請先登錄網頁端,完成API key的申請,再據此文檔詳情進行開發。

您可以點擊 这里 創建API key。

創建成功後,請務必記住以下信息:

  • Access Key: API訪問祕鑰

  • Private Key: 簽名認證加密所使用的祕鑰(僅申請時可見)

每個用戶可以創建20個API key,每個API key可以綁定10個ip地址

接口地址

https://stakingapi.xhash.com:18000

簽名認證

  • 所有接口採用私鑰簽名,公鑰驗籤的方式請求

  • 請求頭header中攜帶簽名信息,包含如下信息:

access_key: 您申請的 API Key 中的 Access Key
sign: 簽名信息,使用MD5withRSA簽名,MD5withRSA(requestBody+timestamp),沒有請求參數,requestBody爲""。
timestamp: 請求時間戳(毫秒)
  • 所有接口採用post請求,請求參數放入requestBody

如訪問/api/v1/xhash/getUserDailyIncome接口
header:
"access_key":"50CEA00402A84BFF9B47CF44A947DA0B"
"sign":"sEm3E4qD8fD7mb54SxJLKajf28gItAkHNjk44QJgrjRqh9XQX6xNMdhsKXSAabcfQ77Mpp/PI6i9hW1XPnfkrLKDlAeaTMXKWxQaRKryzB99p782Re0mRoWFW1iZcvaUFzgb3aY3Oj7/xD0Qz6Y+cg/SZGM6KcTC2IL3PosoWPk="
"timestamp":"1666854104527"

requestBody:
{
    "pageNum": 1,
    "pageSetNum": 10
}
  • 統一返回格式

  {
      "code": "",
      "data": object,
      "msg": ""
  }
  
  code="200" 爲操作成功,其餘失敗

Example

String accessKey = "A95B2CFA7B1940B799EFCE792AD...";
String privateKey = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAMQzb3GI8fTGUUXaZsZxnLBWnihO9iSua4z7v9tY...";
String url = "https://stakingapi.xhash.com:18000/api/v1/xhash/getUserDailyIncome";

Map<String, Object> requestBody = new HashMap<>();
requestBody.put("pageNum", 1);
requestBody.put("pageSetNum", 10);

String content = new GsonBuilder().serializeNulls().create().toJson(requestBody);

long timestamp = System.currentTimeMillis();
System.out.println(content + timestamp);
String sign = RSACoder.sign((content + timestamp).getBytes(), privateKey);

HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("access_key",accessKey);
httpHeaders.add("timestamp",timestamp + "");
httpHeaders.add("sign",sign);

HttpEntity<String> httpEntity = new HttpEntity<>(content, httpHeaders);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> result = restTemplate.postForEntity(url, httpEntity, String.class);
System.out.println(result);

接口詳情

獲取用戶餘額和未支付金額

HTTP request

POST /api/v1/xhash/getUserStatus

Body 请求参数

返回參數

參數名

数据類型

描述

備註

clBalance

number

共識層餘額

Gwei

waitPayment

number

執行層待支付餘額

Gwei

返回示例

{
  "code": "200",
  "data": {
    "clBalance": 1446286721091,
    "waitPayment": 1596525011
  },
  "msg": "Success"
}

獲取用戶詳情

HTTP request

POST /api/v1/xhash/getUserDetailStatus

Body 请求参数

返回參數

參數名

数据類型

描述

備註

validatorsOnline

int

驗證者在線數量

validatorsOffline

int

驗證者離線數量

totalBalance

string

共識層總餘額

Gwei

totalChange

string

執行層+共識層 總收益

Gwei

hoursIncome24

string

執行層+共識層 24小時收益

Gwei

partailWithdrawalsAmount

number

共識層總提取

Gwei

waitPayment

string

執行層待支付

Gwei

pendingPayment

string

執行層支付中

Gwei

paid

string

執行層已支付

Gwei

avgRealApr

float

所有驗證者平均年化

返回示例

{
    "code": "200",
    "data": {
        "validatorsOnline": 45,
        "validatorsOffline": 0,
        "totalBalance": "1440081374281",
        "totalChange": "48615375055.435027176",
        "hoursIncome24": "236051566.84745468",
        "partailWithdrawalsAmount": 35685091263,
        "waitPayment": "400428103.199571345",
        "pendingPayment": "0",
        "paid": "13441757945.295420862",
        "avgRealApr": 0.05681605041
    },
    "msg": "Success"
}

獲取用戶每日收益

HTTP request

POST /api/v1/xhash/getUserDailyIncome

Body 请求参数

參數名

数据類型

是否必填

默認值

描述

pageNum

int

true

-

頁數

pageSetNum

int

true

-

每頁條數

返回參數

參數名

数据類型

描述

備註

userId

int

用戶id

totalReward

float

總收益

Eth

clReward

float

共識層收益

Eth

elReward

float

執行層收益

Eth

mevReward

float

執行層MEV收益

Eth

txReward

float

執行層手續費收益

Eth

rewardDay

int

收益日期

second

validatorNum

int

當日產生收益的驗證者數量

total

int

記錄總條數

返回示例

{
  "code": "200",
  "data": {
    "pageNum": 1,
    "pageData": [
      {
        "userId": 123456,
        "totalReward": 0.15852195658793655,
        "clReward": 0.142707974,
        "elReward": 0.01581398258793658,
        "mevReward": 0.001352162267224239,
        "txReward": 0.014461820320712356,
        "rewardDay": 1666569600,
        "validatorNum": 2
      },
      ...
      ...
    ],
    "total": 27
  },
  "msg": "Success"
}

獲取用戶支付歷史記錄

HTTP Request

POST /api/v1/xhash/getUserPaymentHistory

Body 请求参数

參數名

数据類型

是否必填

默認值

描述

pageNum

int

true

-

頁數

pageSetNum

int

true

-

每頁條數

返回參數

參數名

数据類型

描述

備註

userId

int

user ID

realAmount

float

payment amount

Eth

chainAmount

float

execution-layer amount on chain

Eth

withHoldTxFee

float

tx fee withholding

Eth

realTxFee

float

tx fee on chain

Eth

retained

float

tx feen retained

Eth

txHash

string

tx hash on chain

status

int

payment status

0:paying, 1:finished

chainTime

int

the time on chain

updateTime

int

payment update time

total

int

number of all rewards

返回示例

{
  "code": "200",
  "data": {
    "pageNum": 1,
    "pageData": [
      {
        "userId": 123456,
        "realAmount": 0.148897612,
        "chainAmount": 0,
        "withHoldTxFee": 0.148897612,
        "realTxFee": 0,
        "retained": 0,
        "txHash": "",
        "status": 0,
        "chainTime": 0,
        "updateTime": 1666842847
      }
    ],
    "total": 1
  },
  "msg": "Success"
}

獲取用戶驗證者列表

HTTP Request

POST /api/v1/xhash/getUserValidatorList

Body 请求参数

參數名

数据類型

是否必填

默認值

描述

pageNum

int

true

-

頁數 [1,...]

pageSetNum

int

true

-

每頁條數 [10,100]

返回參數

參數名

数据類型

描述

備註

id

int

sequence id

userId

int

user ID

validatorIndex

int

validator index

validatorPublicKey

string

validator publicKey

totalIncome

int

consensus-layer income

Gwei

effectiveBalance

int

consensus-layer effective balance

Gwei

finalizedBalance

int

consensus-layer finalized balance

Gwei

currentBalance

int

consensus-layer balance

Gwei

currentEffectiveness

string

effectiveness

apr

float

apr by 7 day

node_status

string

validator status in xhash

chain_status

string

consensus-layer status

created_time

timestamp in xhash

second

total

int

number of all rewards

返回示例

{
  "code": "200",
  "data": {
    "pageNum": 1,
    "pageData": [
      {
        "id": 45,
        "userId": 123456,
        "validatorIndex": 429489,
        "validatorPublicKey": "0x827b58e886b0024022120a549a7a50bc2b44b51e0d09663d5f543c17fba3f2ec3faf30126979241d0fd1297838de74d8",
        "totalIncome": 118681206,
        "effectiveBalance": 32000000000,
        "finalizedBalance": 32118648446,
        "currentBalance": 32118648446,
        "currentEffectiveness": 99.01,
        "apr": 0.03623521,
        "node_status": "Active",
        "chain_status": "Active",
        "created_time": 1663310642
      },
      ...
      ...
    ],
    "total": 45
  },
  "msg": "Success"
}

獲取共識層提幣歷史記錄

HTTP Request

POST /api/v1/xhash/getUserPartailWithdrawals

Body 请求参数

參數名

数据類型

是否必填

默認值

描述

pageNum

int

true

-

頁數 [1,...]

pageSetNum

int

true

-

每頁條數 [10,100]

返回參數

參數名

数据類型

描述

備註

id

int

userId

int

用戶id

validatorIndex

int

validator index

validatorPublicKey

string

validator publicKey

blockSlot

int

slot

withdrawalIndex

int

withdrawal Index

address

string

共识层提取地址

amount

float

共识层提取金额

eth

createdTime

long

时间戳,秒

返回示例

{
    "code": "200",
    "data": {
        "pageNum": 1,
        "pageData": [
            {
                "id": 0,
                "userId": 101527,
                "validatorIndex": 429481,
                "validatorPublicKey": "0xac34188ca2c6ec29e40534229698d38fc733908c34eeecd77df0f477481344b10fcebbabbb9cc233a09390d1afb6121d",
                "blockSlot": 6281691,
                "withdrawalIndex": 1122084,
                "address": "0x0708f87a089a91c65d48721aa941084648562287",
                "amount": "0.012279707",
                "createdTime": 1682204315
            },
            ...
            ...
        ],
        "total": 135
    },
    "msg": "Success"
}

錯誤碼

code

message

200

Success

400

Param error

401

Authentication failed

403

Ip not on whitelist

404

Path Not Found

405

Request timestamp expire

429

Requests has exceeded the per second limit

500

Server error

4001

Select user balance failed

4002

Page invalid

4003

Select user reward failed

4004

Select user payments history failed

4005

Select validator list failed

最后更新于