Blockchain API

This chapter contains the resource for the devlopement - token / block APIs and useful tutorials

Get Started

Protx provides collections of APIs that work together on the PROT platform to solve a variety of problems. Developers can build solutions using the PROT platform to meet the business needs.

Endpoint

The endpoints for Protx services are:

JsonRPC

JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol. Primarily this specification defines several data structures and the rules around their processing. It is transport agnostic in that the concepts can be used within the same process, over sockets, over http, or in many various message passing environments. It uses JSON (RFC 4627) as data format.

A rpc call is represented by sending a Request object to a Server. The Request object has the following members:

  • jsonrpc A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".

  • method A String containing the name of the method to be invoked. Method names that begin with the word rpc followed by a period character (U+002E or ASCII 46) are reserved for rpc-internal methods and extensions and MUST NOT be used for anything else.

  • params A Structured value that holds the parameter values to be used during the invocation of the method. This member MAY be omitted.

  • id An identifier established by the Client that MUST contain a String, Number, or NULL value if included. If it is not included it is assumed to be a notification. The value SHOULD normally not be Null and Numbers SHOULD NOT contain fractional parts

Request body:

{
    "jsonrpc": "2.0",
    "id": "7723",
    "method": "methodName",
    "params": {
        "key":"value"
    }
}

Response body (success):

{
    "jsonrpc":"2.0",
    "id": "7723",
    "result":{
        "TransactionID": "705e0c42118e8007dd5271a7c90bcff3a8ce496a6da6d5bb74e16655a1f3d01d",
        "resultData": "ec141e57d14ea0bbb0cb6a9c37abf06a7e323d77e170b0862d8575bebee078909999fd881ead6d208567cc5179f57b6833069cea332a7d2c3b359fbde85229c4"
    }
}

Response body (protocol error):

{
    "jsonrpc": "2.0",
    "id": "7723",
    "error": {
        "code": -32700,
        "msg": "parse error. not well formed"
    }
}

Response body (service error):

{
  "jsonrpc":"2.0",
  "id":"7723",
  "result":{
    "resultCode": "500",
    "resultMessage": "Error Message",
    "resultData": ""
  }
}

Example

curl --location --request POST 'https://test-api.protx.io/token' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "id": "1234",
    "method": "net_getTempKey",
    "params": {
        "address": "0xf9acd4c2d6a358113bfec174e34d2af01323028a",
        "keyType": "transfer"
    }
}'

Protocol Error

  • -32700 : parse error. not well formed

  • -32701 : parse error. unsupported encoding

  • -32702 : parse error. invalid character for encoding

  • -32600 : server error. invalid xml-rpc. not conforming to spec.

  • -32601 : server error. requested method not found

  • -32602 : server error. invalid method parameters

  • -32603 : server error. internal xml-rpc error

  • -32500 : application error

  • -32400 : system error

  • -32300 : transport error

Address and secretKey

You can create a new privateKey in the ServerWallet by using createAddress. The createAddress returns the created address, mnemonic, and secretKey values. You can restore the private key from the archived mnemonic using importAddress.

The secretKey is used as a secret when using serverWallet. If authentication is required when using the serverWallet, the hashKey generated through hash (tempKey + "|" + secretKey) is sent to the serverWallet to authenticate using the secretKey stored inside the wallet and the delivered tempKey.

hashKey = CryptoUtil.getSah256(tempKey +"|" + secretKey)

How to create a signature

When using APIs that generate transactions, such as createToken and transfer, you must create and pass a signature as a parameter. A signature can be created by calling signData. The transfer as an example. You hashed the string consisting of "fromAddress | toAddress | amount | hashKey" with sha256 and made the result into a hex string. You can get the signature value by passing this string as a parameter to signData.

String data = fromAddress + "|" + toAddress + "|" + amount + "|" + tempKey + "|" + hashKey;log.debug("data=" + data);
String hashData = CryptoUtil.getSha256(data);
resultMessage = tokenApiService.signData(fromAddress, hashData, tempKey, hashKey);

...

public static String getSha256(String msg) throws NoSuchAlgorithmException {
  MessageDigest md = MessageDigest.getInstance("SHA-256");
  md.update(msg.getBytes());
  byte[] mdBytes = md.digest();
  String mdStr = bytesToHex(mdBytes);
  return mdStr;
}

Last updated