Contract API offers the following features.

  • Register, query, and modify contract resources
  • Deploy, query, modify contract and execute contract methods

Pre-requisites: Get API Authentication Token

To call a Contract API, you have to append an auth token to the header of an API. This is how to get your API auth token.

  1. Sign up at the Hive Console, go to AppCenter > Game List > Register new game.
  2. Create an new AppID at AppCenter > AppID List > Register new AppID.
    • Register new AppID: Web Login AppID
    • Purpose of use: Blockchain
    • AppID to use:Choose “automatically generated AppID” or “automatically generated AppID” with “Additional Information”
  3. Go to the the Hive Console > Blockchain > Search for API Authentication Key, select and search the game name, and get the ID and the Secret key.
  4. Insert the ID and the Secret key in the request body of auth-token API and call this API.
  5. You can get your API auth key as data.accessToken in the API responses.

Register Contract Resources

Registers the resources of a contract. Register the contract name (contractName), the contract description (contractDesc), and the bytecode and ABI/Scheme generated after the contract is compiled.

Request URL

Live URL https://bc-api.qpyou.cn/core/v1/contract/resource
Sandbox URL https://sandbox-bc-api.qpyou.cn/core/v1/contract/resource
HTTP Method POST
Content-Type application/json

Header Parameters

Field Name Description Type Required
Authorization The authentication token required to call APIs string Y
x-network the blockchain networks {ploygon, xpla} string Y

Request Body

Field Name Description Type Required
from the address of the contract owner string Y
contractName the contract name string Y
contractDesc the description for the contract string Y
contractAbi the application binary interface that is generated when the contract is compiled. file Y
contractBytecode the byte code that is generated when the contract is compiled file Y

Responses

Field Name Description Type
code api request result code, 0: success number
message the result message String
data API response data json
data.resourceId the contract resource ID number

Request Sample

Response Sample

Query Contract Resource Information

Returns the information of the registered contract resources.

Request URL

Live URL https://bc-api.qpyou.cn/core/v1/contract/resource
Sandbox URL https://sandbox-bc-api.qpyou.cn/core/v1/contract/resource
HTTP Method GET
Content-Type application/json

Header Parameters

Field Name Description Type Required
Authorization The authentication token required to call APIs string Y
x-network the blockchain networks {ploygon, xpla} string Y

Query Parameters

Field Name Description Type Required
resourceId the contract resource ID string N

Responses

Field Name Description Type
code api request result code, 0: success number
message the result message String
data API response data json
data.resourceId the contract resource ID number
data.network the blockchain network string
data.tenantId the ID of the one who registered the contract resource string
data.contractName the contract name string
data.contractDesc the description for the contract string
data.codeId the contract code ID (only for XPLA blockchain) string
data.updatedAt the date the contract was registered string
data.createdAt the date the contract was modified string

Request Sample

Response Sample

Modify Contract Resources

Modifies the registered contract resources. Modifies the contract description (contractDesc), the bytecode, or the ABI/Scheme.

Request URL

Live URL https://bc-api.qpyou.cn/core/v1/contract/resource/{resourceId}
Sandbox URL https://sandbox-bc-api.qpyou.cn/core/v1/contract/resource/{resourceId}
HTTP Method PATCH
Content-Type application/json

Path Parameters

Field Name Description Type Required
resourceId the contract resource ID string Y

Header Parameters

Field Name Description Type Required
Authorization The authentication token required to call APIs string Y
x-network the blockchain networks {ploygon, xpla} string Y

Request Body

Field Name Description Type Required
from the address of the contract owner string Y
contractDesc the description for the contract string N
codeId This is the contract code ID (only for XPLA blockchain). It is obtained when you deploy a contract on the XPLA blockchain. string N
contractAbi the application binary interface that is generated when the contract is compiled. file N
contractBytecode the byte code that is generated when the contract is compiled file N

Responses

Field Name Description Type
code api request result code, 0: success number
message the result message String
data API response data json
data.resourceId the contract resource ID number

Request Sample

Response Sample

Deploy Contract

Creates a transaction that can deploy a new contract based on the previously registered contract resources (the bytecode and ABI/Scheme). This API can deploy all types (including NFT and FT, the Fungible Token) of contract.

Request URL

Live URL https://bc-api.qpyou.cn/core/v1/contract/resource/{resourceId}
Sandbox URL https://sandbox-bc-api.qpyou.cn/core/v1/contract/resource/{resourceId}
HTTP Method POST
Content-Type application/json

Header Parameters

Field Name Description Type Required
Authorization The authentication token required to call APIs string Y
x-network the blockchain networks {ploygon, xpla} string Y

Path Parameters

Field Name Description Type Required
resourceId the contract resource ID string Y

Request Body

Field Name Description Type Required
from the wallet address that deploys the contract string Y
message the initial configuration information that is required to deploy the contract json Y
encoded whether the returned transaction is encoded or not

  • true: Receive the encoded raw transaction string (data.rawTx).
  • false: Receive the decoded data.rawTx (JSON).
boolean N

Responses

Field Name Description Type
code api request result code, 0: success number
message the result message String
data API response data json
data.rawTx the transaction data string or json
data.instanceId the contract instance ID number

Request Sample

Response Sample

Get Deployed Contract Information

Returns the contract information deployed on a blockchain.

Request URL

Live URL https://bc-api.qpyou.cn/core/v1/contract/instance
Sandbox URL https://sandbox-bc-api.qpyou.cn/core/v1/contract/instance
HTTP Method GET
Content-Type application/json

Header Parameters

Field Name Description Type Required
Authorization The authentication token required to call APIs string Y
x-network the blockchain networks {ploygon, xpla} string Y

Query Parameters

Field Name Description Type Required
instanceId the contract instance ID string N

Responses

Field Name Description Type
code api request result code, 0: success number
message the result message String
data API response data array
data.resourceId the contract resource ID number
data.instanceId the contract instance ID number
data.contractAddress the contract address string
data.initMsg the initial configuration information when deploying the contract json
data.createdAt the date when the contract was recorded on a blockchain string
data.network the blockchain network information string
data.tenantId the ID of the contract deployer string

Request Sample

Response Sample

Modify Contract Instance Address

Update the deployed contract address with the contract instance ID (instanceId).

Request URL

Live URL https://bc-api.qpyou.cn/core/v1/contract/instance/{instanceId}
Sandbox URL https://sandbox-bc-api.qpyou.cn/core/v1/contract/instance/{instanceId}
HTTP Method PATCH
Content-Type application/json

Path Parameters

Field Name Description Type Required
instanceId the contract instance ID string Y

Header Parameters

Field Name Description Type Required
Authorization The authentication token required to call APIs string Y
x-network the blockchain networks {ploygon, xpla} string Y

Query Parameters

Field Name Description Type Required
contractAddress the contract address string Y

Responses

Field Name Description Type
code api request result code, 0: success number
message the result message string

Request Sample

Response Sample

Query Contract Method List

Returns the list of the contract methods by the contract resource ID (resourceId).

Request URL

Live URL https://bc-api.qpyou.cn/core/v1/contract/resource/{resourceId}/methods
Sandbox URL https://sandbox-bc-api.qpyou.cn/core/v1/contract/resource/{resourceId}/methods
HTTP Method GET
Content-Type application/json

Path Parameters

Field Name Description Type Required
resourceId the contract resource ID string Y

Header Parameters

Field Name Description Type Required
Authorization The authentication token required to call APIs string Y
x-network the blockchain networks {ploygon, xpla} string Y

Responses

Field Name Description Type
code api request result code, 0: success number
message the result message String
data API response data array
data.methodName the contract method name string
data.type the contract method type

  • execute: insert data into the contract or modify the existing data in the contract
  • query: Get Contract Information
string

Request Sample

Response Sample

Get Contract Method Information

Returns the function signature required to execute contract methods with the contract resource ID (resourceId) and the method name (method).

Request URL

Live URL https://bc-api.qpyou.cn/core/v1/contract/resource/{resourceId}/method/{method}
Sandbox URL https://sandbox-bc-api.qpyou.cn/core/v1/contract/resource/{resourceId}/method/{method}
HTTP Method GET
Content-Type application/json

Path Parameters

Field Name Description Type Required
resourceId the contract resource ID string Y
method the contract method name string Y

Header Parameters

Field Name Description Type Required
Authorization The authentication token required to call APIs string Y
x-network the blockchain networks {ploygon, xpla} string Y

Responses

Field Name Description Type
code api request result code, 0: success number
message the result message String
data This is the data required to execute contract methods (the method name and the input parameters of the method). json

Request Sample

Response Sample

Execute Contract Method

Executes the contract method with the method name and the input parameters (message) of the method.

Request URL

Live URL https://bc-api.qpyou.cn/core/v1/contract/instance/{instanceId}/query
Sandbox URL https://sandbox-bc-api.qpyou.cn/core/v1/contract/instance/{instanceId}/query
HTTP Method POST
Content-Type application/json

Path Parameters

Field Name Description Type Required
instanceId the contract instance ID string Y

Header Parameters

Field Name Description Type Required
Authorization The authentication token required to call APIs string Y
x-network the blockchain networks {ploygon, xpla} string Y

Request Body

Field Name Description Type Required
from the wallet address that requests executing the contract method string Y
message the contract method name and the input parameters of the method string Y
encoded whether the returned transaction is encoded or not

  • true: Receive the encoded raw transaction string (data.rawTx).
  • false: Receive the decoded data.rawTx (JSON).
boolean N

Responses

Field Name Description Type
code api request result code, 0: success number
message the result message String
data the returned value after executing the contract method json

Request Sample

 In general the contract methods are divided into 2 types: the query type and the execute type. The query type method just queries the data, and the execute type method writes new data in the contract or modifies the existing data in the contract. The execute type always returns the raw transaction, not like the query type.  

Response Sample: Query Type

Response Sample: Execute Type (encoded is true)

Response Sample: Execute Type (encoded is false)