NAV Navbar
java

소개

소개 내용 블라브라 ~~

인증토큰 생성

인증토큰을 생성하기 위해 아래의 코드를 참조 :


String token = "";
String apiKey = "<API_KEY>";
Algorithm algorithm = Algorithm.HMAC256(apiKey);

if(query == null) {
    token =  JWT.create()
            .withClaim("url", url)
            .withClaim("nonce", new Date().getTime())
            .sign(algorithm);
}

token = JWT.create()
          .withClaim("url", url)
          .withClaim("query", query)
          .withClaim("nonce", new Date().getTime())
          .sign(algorithm);

Make sure to replace API_KEY with your API key.

API 요청시 토큰을 생성하여 요청 헤더의 X-Authorization 의 값으로 설정하여 요청을 전송합니다. token 생성은 JWT(https://jwt.io) 형식을 따릅니다.

아래의 모든 API를 호출시 토큰을 생성하여 아래와 같이 헤더에 설정하여 API를 호출해야 합니다.

X-Authorization: <token>

지갑 API

지갑 생성

String apiUrl = "/wallet/api/account";
String password = "";
JSONObject param = new JSONObject();
param.put("password", password);

String token = getJwtToken(apiUrl,param.toJSONString());
HttpHeaders headers = new HttpHeaders();
headers.set("X-Authorization", token);
headers.add("content-type", "application/json; charset=UTF-8");
HttpEntity requetEntity = new HttpEntity(param.toJSONString(),
                                         headers);

ResponseEntity<String> resultEntity = restTemplate.exchange(
                                        baseUrl + apiUrl, 
                                        HttpMethod.POST, 
                                        equetEntity, 
                                        String.class);

샘플 결과 :

{
    "accountId": "0xf8734f3498feok48a6afbdc1f6c32vlk05ac63ea"
}

지갑 생성 후 지갑 주소를 반환한다.

HTTP Request

POST /wallet/api/account

Query Parameters

파라미터 필수여부 설명
password true 비밀번호

지갑 생성 (GBizCoinup용)

String apiUrl = "/wallet/api/gbiz-account";
String password = "";
Integer balance = 10;
JSONObject param = new JSONObject();
param.put("password", password);
param.put("balance", balance);

String token = getJwtToken(apiUrl,param.toJSONString());
HttpHeaders headers = new HttpHeaders();
headers.set("X-Authorization", token);
headers.add("content-type", "application/json; charset=UTF-8");
HttpEntity requetEntity = new HttpEntity(param.toJSONString(),
                                         headers);

ResponseEntity<String> resultEntity = restTemplate.exchange(
                                        baseUrl + apiUrl, 
                                        HttpMethod.POST, 
                                        equetEntity, 
                                        String.class);

샘플 결과 :

{
    "accountId": "0xf8734f3498feok48a6afbdc1f6c32vlk05ac63ea"
}

지갑 생성 후 지갑 주소를 반환한다.

HTTP Request

POST /wallet/api/gbiz-account

Query Parameters

파라미터 필수여부 설명
password true 비밀번호
balance true 초기잔고

지갑 잔고 조회

String accountId = "";
String apiUrl = "/wallet/api/account/" + accountId;

String token = getJwtToken(apiUrl,null);
HttpHeaders headers = new HttpHeaders();
headers.set("X-Authorization", token);
HttpEntity requetEntity = new HttpEntity(headers);

ResponseEntity<String> resultEntity = restTemplate.exchange(
                                        baseUrl + apiUrl, 
                                        HttpMethod.GET, 
                                        equetEntity, 
                                        String.class);

샘플 결과 :

{
  "code": "200",
  "message": "OK",
  "response": {
    "balanceOfCuc": 1000,
    "balanceOfEth": 10,
    "stateOfCuc" : "COMPLETE | PENDING"
  }
}

지갑의 잔고를 조회한다.

HTTP Request

GET /wallet/api/account/<accountId>

URL Parameters

파라미터 설명
accountId 지갑주소

트랜잭션 조회

String accountId = "";
String apiUrl = "/wallet/api/account/" + accountId + "/transfer";

String token = getJwtToken(apiUrl,null);
HttpHeaders headers = new HttpHeaders();
headers.set("X-Authorization", token);
HttpEntity requetEntity = new HttpEntity(headers);

ResponseEntity<String> resultEntity = restTemplate.exchange(
                                        baseUrl + apiUrl, 
                                        HttpMethod.GET, 
                                        equetEntity, 
                                        String.class);

샘플 결과 :

{
  "code": "200",
  "message": "OK",
  "response": {
    "totalCount" : 1,
    "page" : 1,
    "pageSize" : 10,
    "list" : [
      {
        "txHash" : "",
          "status" : "",
          "type" : "",
          "from" : "",
          "to" : "",
          "value" : 100,
          "timestamp" : ""
      }
    ]
  }
}

거래 내역을 조회한다.

HTTP Request

GET /wallet/api/account/<accountId>/transfer

URL Parameters

파라미터 설명
accountId 지갑 주소

코인 차감 처리

String apiUrl = "/wallet/api/minus-coin";
String accountId = "";
String recommenderId = "";
Long totalVal = 50; 
Long recommenderVal = 10; 
JSONObject param = new JSONObject();
param.put("accountId", accountId);
param.put("recommenderId", recommenderId);
param.put("value", totalVal);
param.put("recommenderValue", recommenderVal);

String token = getJwtToken(apiUrl,param.toJSONString());
HttpHeaders headers = new HttpHeaders();
headers.set("X-Authorization", token);
headers.add("content-type", "application/json; charset=UTF-8");
HttpEntity requetEntity = new HttpEntity(param.toJSONString(),
                                         headers);

ResponseEntity<String> resultEntity = restTemplate.exchange(
                                        baseUrl + apiUrl, 
                                        HttpMethod.POST, 
                                        equetEntity, 
                                        String.class);

샘플 결과 :

{
  "code": "200",
  "message": "OK",
  "response": {
    "txHash": "string",
    "mWallet" : "0xflejfe~~~",
    "usedCuc" : 10
  }
}

HTTP Request

POST /wallet/api/minus-coin

Request Body Parameters

파라미터 설명
accountId 지갑 주소
recommenderId 추천인 지갑 주소
value 총 차감 CUC
recommenderValue 추천인 부여 CUC

{ "accountId": "string", "recommenderId": "string", "totalValue": 0, "recommenderValue": 0

}

코인 차감 처리(다중 추천인)

String apiUrl = "/wallet/api/minus-coins";
String accountId = "";
String [] recommenderIds = [""];
Long totalVal = 50; 
Long [] recommenderVals = [10]; 
JSONObject param = new JSONObject();
param.put("accountId", accountId);
param.put("recommenderIds", new JSONArray(recommenderIds));
param.put("value", totalVal);
param.put("recommenderValue", new JSONArray(recommenderVals));

String token = getJwtToken(apiUrl,param.toJSONString());
HttpHeaders headers = new HttpHeaders();
headers.set("X-Authorization", token);
headers.add("content-type", "application/json; charset=UTF-8");
HttpEntity requetEntity = new HttpEntity(param.toJSONString(),
                                         headers);

ResponseEntity<String> resultEntity = restTemplate.exchange(
                                        baseUrl + apiUrl, 
                                        HttpMethod.POST, 
                                        equetEntity, 
                                        String.class);

샘플 결과 :

{
  "code": "200",
  "message": "OK",
  "response": {
    "txHash": "string",
    "mWallet" : "0xflejfe~~~",
    "usedCuc" : 10
  }
}

HTTP Request

POST /wallet/api/minus-coins

Request Body Parameters

파라미터 설명
accountId 지갑 주소
recommenderId 추천인 지갑 주소
value 총 차감 CUC
recommenderValue 추천인 부여 CUC

{ "accountId": "string", "recommenderId": ["string"], "totalValue": 0, "recommenderValue": [0]

}

출금요청 처리

String apiUrl = "/wallet/api/withdraw";
String accountId = "";
String toWalletAddr = "";
Long val = 10; 
JSONObject param = new JSONObject();
param.put("from", accountId);
param.put("to", toWalletAddr);
param.put("value", val);

String token = getJwtToken(apiUrl,param.toJSONString());
HttpHeaders headers = new HttpHeaders();
headers.set("X-Authorization", token);
headers.add("content-type", "application/json; charset=UTF-8");
HttpEntity requetEntity = new HttpEntity(param.toJSONString(),
                                         headers);

ResponseEntity<String> resultEntity = restTemplate.exchange(
                                        baseUrl + apiUrl, 
                                        HttpMethod.POST, 
                                        equetEntity, 
                                        String.class);

샘플 결과 :

{
  "code": "200",
  "message": "OK",
  "response": {
    "txHash": "string"
  }
}

HTTP Request

POST /wallet/api/withdraw

Request Body Parameters

파라미터 설명
from 보내는 사람 지갑 주소
to 받는 사람 지갑 주소
value 보낼 CUC 수량

{ "from": "string", "to": "string", "value": 0 }

입금 정보 조회

String latestTimestamp = "";
String apiUrl = "/wallet/api/deposit/transfer?latestTimestamp="+latestTimestamp;


String token = getJwtToken(apiUrl,null);
HttpHeaders headers = new HttpHeaders();
headers.set("X-Authorization", token);
headers.add("content-type", "application/json; charset=UTF-8");
HttpEntity requetEntity = new HttpEntity(param.toJSONString(),
                                         headers);

ResponseEntity<String> resultEntity = restTemplate.exchange(
                                        baseUrl + apiUrl, 
                                        HttpMethod.GET, 
                                        equetEntity, 
                                        String.class);

샘플 결과 :

{
  "code": "200",
  "message": "OK",
  "response": {
    "list": [
      {
        "txHash": "0xf83fef65d9a437734d62fc7d9321e168203e7fb810b9dda76120c26b8c2908d2",
        "status": "DONE",
        "from": "0xae6d2a7c11642c82243e859506fa5ecf4cda348a",
        "to": "0xef0a9fc19dd7b0dc3f24169ff85731e410e0bfaf",
        "value": 10,
        "timestamp": "1544960098",
        "exchDoneTimestamp": "1544960467"
      },
      {
        "txHash": "0x2f46d41f74ce75f6263be19e6f22aff64b8b3868cc43c6ef3359c08c2255de08",
        "status": "DONE",
        "from": "0xae6d2a7c11642c82243e859506fa5ecf4cda348a",
        "to": "0xef0a9fc19dd7b0dc3f24169ff85731e410e0bfaf",
        "value": 15,
        "timestamp": "1544960123",
        "exchDoneTimestamp": "1544960467"
      },
      {
        "txHash": "0x4c2891b0f682b130bedbbcbe409e2bb766e677c06d588d45d73e594f12160161",
        "status": "DONE",
        "from": "0xae6d2a7c11642c82243e859506fa5ecf4cda348a",
        "to": "0xef0a9fc19dd7b0dc3f24169ff85731e410e0bfaf",
        "value": 20,
        "timestamp": "1544960187",
        "exchDoneTimestamp": "1544960534"
      }
    ]
  }
}

HTTP Request

GET /wallet/api/deposit/transfer?latestTimestamp=<latestTimestamp>

Request Body Parameters

파라미터 설명
latestTimestamp 마지막 입금 정보의 타임스탬프 (데이터가 없을 경우 파라미터값을 제외)

환율 정보 조회

String apiUrl = "/wallet/api/exchange/rate;


String token = getJwtToken(apiUrl,null);
HttpHeaders headers = new HttpHeaders();
headers.set("X-Authorization", token);
headers.add("content-type", "application/json; charset=UTF-8");
HttpEntity requetEntity = new HttpEntity(param.toJSONString(),
                                         headers);

ResponseEntity<String> resultEntity = restTemplate.exchange(
                                        baseUrl + apiUrl, 
                                        HttpMethod.POST, 
                                        equetEntity, 
                                        String.class);

샘플 결과 :

{
  "code": "200",
  "message": "OK",
  "response": {
    "exchangeRate": "0.00026",
    "exchangeRateEthCuc": "0.00026",
    "exchangeRateKrwCuc": "1.3",
    "lastUpdate": "2019-06-21 10:12:31"
  }
}

HTTP Request

POST /wallet/api/exchange/rate;

Request Body Parameters

파라미터 설명

Errors

The Kittn API uses the following error codes:

Error Code Meaning
400 Bad Request -- Your request is invalid.
401 Unauthorized -- Your API key is wrong.
403 Forbidden -- The kitten requested is hidden for administrators only.
404 Not Found -- The specified kitten could not be found.
405 Method Not Allowed -- You tried to access a kitten with an invalid method.
406 Not Acceptable -- You requested a format that isn't json.
410 Gone -- The kitten requested has been removed from our servers.
418 I'm a teapot.
429 Too Many Requests -- You're requesting too many kittens! Slow down!
500 Internal Server Error -- We had a problem with our server. Try again later.
503 Service Unavailable -- We're temporarily offline for maintenance. Please try again later.