About the API

Describe how to use the ChainZ API.

Preparations

  1. After joining the ChainZ Service, you must have authorization information and API key by creating credentials.

  2. You need to obtain an access token from the ChainZ API authorization server using the authorization data.

Chain ID is required to use ChainZ.

Chain ID of the ChainZ TestNet: 8768cb29-2417-4281-84b1-924b82ebb720 Chain ID of ChainZ MainNet: Contact us separately (support@chainz.biz)

Procedure for using the API

Using Account API

Common settings

  • ChainZ Account API URL: account-api.chainz.biz

Prerequisites

  • Chain ID required.

Input Information

  • Access Tokens & API Keys

  • User ID - Account identification information for the operator

  • Chain ID - Blockchain Identification Information

  1. To create a blockchain account for the user, enter the following in the terminal:

# Account API (Account Creation) usage example - Request
curl -X POST \
  "https://{ChainZ Account API URL}/api/v1/accounts" \
  -H  "accept: application/json" \
  -H "Authorization: Bearer {access token}” \
  -H “x-api-key: {API key}”
  -H 'Content-Type: application/json' \
  -d '{
  "userId": "{User ID}",
  "chainId": "{Chain ID}"
}'
# Account API (Account Creation) usage example - Response
{
  "id": "e0a476e3-8a1f-41a9-b67d-98703e816fe7",
  "userId": "test",
  "chainId": "8768cb29-2417-4281-84b1-924b82ebb720",
  "address": "0x508b8bc6c521e24c2eedd0f2280c7021b752efdb",
  "status": "ACTIVE"
}

2. To view the user's Blockchain account information, enter the following in the terminal:

# Account API (Account search) usage example - Request
curl -X GET \
    "https://{ChainZ Account API URL}/api/v1/accounts?userId={User ID}&chainId={Chain ID}" \
    -H  "accept: application/json" \
    -H "Authorization: Bearer {access token}” \
    -H “x-api-key: {API key}”
# Account API (Account search) usage example - Response
{
  "totalCount": 1,
  "data": [
    {
      "providerCode": "A1B1C1D1",
      "id": "051f3e8d-67ab-4d26-a42e-805b3b048e86",
      "userId": "user0001",
      "chainId": "5a9d9e56-ef2b-401c-a026-cedeed1ce457",
      "address": "0x5b55bac99d5d6678a35d1f9bd1ede1ad799d6902",
      "status": "ACTIVE",
      "createdAt": "2021-05-19T20:19:48.000Z",
      "updatedAt": "2021-05-20T05:19:48.000Z"
    }
  ]
}

Using Contract API

Common settings

  • ChainZ Contract API URL: contract-api.chainz.biz

Prerequisites (Smart Contract build information, etc.)

  • ABI and bytecode required among artifacts of Smart Contract

Input Information

  • Access Tokens & API Keys

  • ABI - Smart Contract build artifacts

  • Bytecode - Smart Contract build artifacts

  1. Registering Smart Contract Build Information (Artifacts)

# Contract API (Smart Contract Deployment) usage example - Request
curl -X 'POST' \
  'https://{ChainZ Contract API URL}/api/v1/contract/artifacts' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer {access token}' \
  -H 'x-api-key: {API key}' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "storage",
  "version": "1.0.0",
  "abi": [{"inputs":[],"name":"retrieve","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"num","type":"uint256"}],"name":"store","outputs":[],"stateMutability":"nonpayable","type":"function"}],
  "bytecode": "608060405234801561001057600080fd5b5061012f806100206000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c80632e64cec11460375780636057361d146051575b600080fd5b603d6069565b6040516048919060c2565b60405180910390f35b6067600480360381019060639190608f565b6072565b005b60008054905090565b8060008190555050565b60008135905060898160e5565b92915050565b60006020828403121560a057600080fd5b600060ac84828501607c565b91505092915050565b60bc8160db565b82525050565b600060208201905060d5600083018460b5565b92915050565b6000819050919050565b60ec8160db565b811460f657600080fd5b5056fea264697066735822122062db17618d746a1967495ede611efc2c1e881cb29cbd6b40b23bd35a720c134c64736f6c63430008010033"
}'
# Contract API (Smart Contract Deployment) usage example - Response
{
  "id": "e5024600-c7eb-4327-959a-3ef8e09f0152",
  "providerCode": "A1B1C1D1",
  "name": "storage",
  "version": "1.0.0",
  "abi": [
    {
      "inputs": [],
      "name": "retrieve",
      "outputs": [
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        }
      ],
      "stateMutability": "view",
      "type": "function"
    },
    {
      "inputs": [
        {
          "internalType": "uint256",
          "name": "num",
          "type": "uint256"
        }
      ],
      "name": "store",
      "outputs": [],
      "stateMutability": "nonpayable",
      "type": "function"
    }
  ],
  "bytecode": "608060405234801561001057600080fd5b5061012f806100206000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c80632e64cec11460375780636057361d146051575b600080fd5b603d6069565b6040516048919060c2565b60405180910390f35b6067600480360381019060639190608f565b6072565b005b60008054905090565b8060008190555050565b60008135905060898160e5565b92915050565b60006020828403121560a057600080fd5b600060ac84828501607c565b91505092915050565b60bc8160db565b82525050565b600060208201905060d5600083018460b5565b92915050565b6000819050919050565b60ec8160db565b811460f657600080fd5b5056fea264697066735822122062db17618d746a1967495ede611efc2c1e881cb29cbd6b40b23bd35a720c134c64736f6c63430008010033",
  "upgradable": false,
  "status": "CREATED",
  "createdAt": "2021-05-31T03:33:30.531Z",
  "updatedAt": "2021-05-31T03:33:30.531Z"
}

Using Transaction API

Common settings

  • ChainZ Transaction API URL: tx-api.chainz.biz

Prerequisites

  • Chain ID required.

  • If it is a transaction that requires a signature

    • Account is created through the Account API (From Address)

  • If it is a contract transaction

    • Contract ID is registered through the Contract API

Input Information

  • Access Tokens & API Keys

  • Chain ID - Blockchain Identification Information

  • Client Request ID - The unique identification information of the provider in the Request

  • ...

  • Request ID - Unique identifying information in the Request

  • Callback URL - The HTTP endpoint address of the server that will receive the callback. (Optional)

  1. Transactions are sent using Transaction API. The transaction processing status can be checked with the ID value (RequestId) received in Response.

# Transaction API usage example - Request
curl -X POST "https://{ChainZ Transaction API URL}/api/v1/transactions/contract-deployment" \
    -H  "accept: application/json" \
    -H  "x-api-key: {API key}" \
    -H  "Authorization: Bearer {access token}" \
    -H  "Content-Type: application/json" \
    -d "{\"chain\":\"3033f611-5b06-4661-a4d1-d375bd8e442c\",\"clientReqId\":\"3fa85f64-5717-4562-b3fc-2c963f66aff6\",\"maxRetry\":3,\"isSync\":false,\"params\":{\"from\":\"0xceed092e9d5b134d3aff067dc049b937d0facf4a\",\"contractId\":\"e5024600-c7eb-4327-959a-3ef8e09f0152\",\"initParams\":[]}}"

ClientReqID (Client Request ID) creation rules follow the Universal Unique Identifier (UUID) convention. Please refer to the following to create a UUID for testing.

# Transaction API usage example - Response
{
  "status": "REQUESTED",
  "log": "{\"type\":\"CONTRACT_DEPLOYMENT\",\"isSync\":false,\"maxRetry\":3}",
  "timestamp": "2021-05-31T05:07:27.706Z",
  "id": "07b28242-735d-49f1-a05f-357ee7a86682"
}

2. To search the processing status of a transaction, do as follows.

Check the Log information using the Transaction search API (/api/v1/transactions/ {ReqID} /logs).

# Transaction API (Tx Receipt search) usage example - Request
curl -X GET "https://{ChainZ Transaction API URL}/api/v1/transactions/{Request ID}/logs" \
    -H  "accept: application/json" \
    -H  "x-api-key: {API key}" \
    -H  "Authorization: Bearer {access token}"
# Transaction API (Tx Receipt search) usage example - Response
{
  "logList": [
    {
      "status": "REQUESTED",
      "log": "{\"type\":\"CONTRACT_DEPLOYMENT\",\"isSync\":false,\"maxRetry\":3}",
      "timestamp": "2021-05-31T04:52:21.593Z"
    },
    {
      "status": "SUCCEEDED",
      "log": "{\"type\":\"CONTRACT_DEPLOYMENT\",\"isSync\":false,\"maxRetry\":3,\"txReceipt\":{\"blockHash\":\"0x7ff42b2c456eb03d57a72e5e17a83da9316c43ea5363409870686eea9f726a9b\",\"blockNumber\":\"0x2bef4\",\"contractAddress\":\"0x72ede34c09a5aa7276b8d655223d35a38fcb79ce\",\"cumulativeGasUsed\":\"0x1d023\",\"from\":\"0xceed092e9d5b134d3aff067dc049b937d0facf4a\",\"gasUsed\":\"0x1d023\",\"logs\":[],\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"status\":\"0x1\",\"to\":null,\"transactionHash\":\"0x7b0b826c5ec221a8dd616c17648e42b1e009e0efdc224ee63b5011c24da4ae64\",\"transactionIndex\":\"0x0\"}}",
      "timestamp": "2021-05-31T04:52:23.779Z"
    }
  ],
  "requestId": "c648c217-1260-4223-ba2c-9bdd0ee9b6e8",
  "pCode": "MW012345"
}

Transaction receipt can be confirmed from the txReceipt information by JSON parsing of the log data with the Response data status as 'Succeeded'.

Example of JSON parsing a log with status of 'SUCCEEDED'
{
  "type": "CONTRACT_DEPLOYMENT",
  "isSync": false,
  "maxRetry": 3,
  "txReceipt": {
    "blockHash": "0x7ff42b2c456eb03d57a72e5e17a83da9316c43ea5363409870686eea9f726a9b",
    "blockNumber": "0x2bef4",
    "contractAddress": "0x72ede34c09a5aa7276b8d655223d35a38fcb79ce",
    "cumulativeGasUsed": "0x1d023",
    "from": "0xceed092e9d5b134d3aff067dc049b937d0facf4a",
    "gasUsed": "0x1d023",
    "logs": [],
    "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "status": "0x1",
    "to": null,
    "transactionHash": "0x7b0b826c5ec221a8dd616c17648e42b1e009e0efdc224ee63b5011c24da4ae64",
    "transactionIndex": "0x0"
  }
}

Among the txReceipt information, you can check detailed information in the Block Explorer with lockHash, blockNumber, and transactionHash information. For more information, see Using BLOCK EXPLORER.

Using Token API

Common settings

  • ChainZ Token API URL: token-api.chainz.biz

Deploying Token Contracts

To deploy Token Contract, enter the following:

Prerequisites

  • Sender Account should be created through Token API or Account API.

Input Information

  • Chain ID - Blockchain Identification Information

  • Client Request ID - The unique identification information of the business provider in the Request

  • Sender - Token contract deployment account

  • Owner - The account that owns the token contract and holds the initially issued amount.

  • Name - The name of the token

  • Symbol - The symbol of the token

  • Amount - Initial amount of tokens issued

# Token API usage example
curl -X 'POST' \
  'https://{ChainZ Token API URL}/api/v1/chains/{Chain ID}/deployments' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer {access token}' \
  -H 'x-api-key: {API key}' \
  -H 'Content-Type: application/json' \
  -d '{
  "clientReqId": "3fa85f64-5717-4562-b3fc-29682566afa6",
  "sender": "0xf5bea619d23d0dbd95488aa3a8e3e76a8bc7568d",
  "owner": "0xf5bea619d23d0dbd95488aa3a8e3e76a8bc7568d",
  "name": "Test Token",
  "symbol": "TST",
  "amount": 100000000000
}'
# Token API Usage Example (Token Contract Deployment) - Response
{
  "providerCode": "BQHQ6700",
  "chainId": "{Chain ID}",
  "clientReqId": "3fa85f64-5717-4562-b3fc-29682566afa6",
  "sender": "0xf5bea619d23d0dbd95488aa3a8e3e76a8bc7568d",
  "owner": "0xf5bea619d23d0dbd95488aa3a8e3e76a8bc7568d",
  "name": "Test Token",
  "symbol": "TST",
  "amount": 100000000000,
  "contractAddress": "0x46850f87a6df4fd83a7a70f7936da4b5129ce280",
  "txHash": "0x5c1cd8bb5ac9f129b73c4434adb2f7cd11905d58f690b03b1c87babe41c41ac8",
  "blockNumber": 2072977,
  "status": "SUCCESS",
  "createdAt": "2021-07-27T00:07:52.660Z"
}

Token Transfer

If you want to transfer your Token to the other party, enter it as follows.

Prerequisites

  • Token contract deployment address

  • Account creation (sender) through Token API or Account API

Input Information

  • Chain ID - Blockchain Identification Information

  • Contract Address - Token contract address

  • Client Request ID - The unique identification information of the business provider in the Request

  • Sender - The address of the account that sends the token

  • Recipient - The address of the account to receive the token

  • Amount - the token to be sent

# Token API Usage Example (Token Transfer) - Request
curl -X 'POST' \
  'https://{ChainZ Token API URL}/api/v1/chains/{Chain ID}/contracts/0x46850f87a6df4fd83a7a70f7936da4b5129ce280/transfer' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer {Access Token}' \
  -H 'x-api-key: {API Key}' \
  -H 'Content-Type: application/json' \
  -d '{
  "clientReqId": "3fa85f64-5717-4562-b3fc-2c962326afa6",
  "sender": "0xf5bea619d23d0dbd95488aa3a8e3e76a8bc7568d",
  "recipient": "0x82567d516a119a12262737397caff457f6725700",
  "amount": 1
}'
# Token API Usage Example (Token Transfer) - Response
{
  "providerCode": "BQHQ6700",
  "contractAddress": "0x46850f87a6df4fd83a7a70f7936da4b5129ce280",
  "chainId": {Chain ID},
  "clientReqId": "3fa85f64-5717-4562-b3fc-2c962326afa6",
  "sender": "0xf5bea619d23d0dbd95488aa3a8e3e76a8bc7568d",
  "recipient": "0x82567d516a119a12262737397caff457f6725700",
  "amount": 1,
  "txHash": "0x0318cff466e5965279f873e1ba1d2b4705e2dd7695d285a0909e927614d49c52",
  "blockNumber": 2073925,
  "status": "SUCCESS",
  "createdAt": "2021-07-27T00:39:33.283Z"
}

Search Token Balance

To search the balance of the token you hold, enter the following:

Prerequisites

  • Token contract deployment address

Input Information

  • Chain ID - Blockchain Identification Information

  • Contract Address - Token contract address

  • Owner Address - The address of the account whose balance you want to search

# Token API Usage Example (Token BalanceOf) - Request
curl -X 'GET' \
  'https://{ChainZ Token API URL}/api/v1/chains/{Chain ID}/contracts/0x46850f87a6df4fd83a7a70f7936da4b5129ce280/balanceOf/0xf5bea619d23d0dbd95488aa3a8e3e76a8bc7568d' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer {Access Token}' \
  -H 'x-api-key: {API Key}'
# Token API Usage Example (Token BalanceOf) - Response
100000000000

Last updated