Validating and deploying a Smart Contract with REST API

Introduction

This article illustrates how to use REST API to work with the Smart Contracts on the Credits Blockchain Platform.

A Smart Contract is a program written in Java that compiles in byte code and is deployed on the blockchain. Each successful Smart Contract launch results in saving its new state in the blockchain. The next launch of the Smart Contract uses its previous state.

Description of cURL Parameters

-X POST - type of HTTP request, in this case we use POST. More info here: Wikipedia

-H “accept: application/json”

-H “Content-Type: application/json” - Specification for the transferred parameters and response to be in JSON format

-d {parameters} - With this key, we specify the data transferred with the request. Let’s look at them in more detail:

“authKey”: “” - Authorization key. Not used at present, should be passed “”

“networkAlias”: “Mainnet” - We specify the network, where the request should be executed. Either Testnet or Mainnet.

“sourceString": "source code" - Here we specify the source code of a smart contract.

Code

For compatibility check, REST API provides a “Validate” function. The easiest way to invoke it is to use CURL tool. Example of CURL tool uses is provided below.

Let's try it out with the following code !

cURL
Copy

Response

Upon successful compilation REST should return JSON response containing the status “success”: “true”. Example of the successful launch in cURL is provided below.

JSON
Copy

Great now we know that the smart contract is validated so let's move on the deployment of the Contract !

Deployment

To deploy a Smart Contract you should sign the resulting byte code with a digital signature. The following Python code allows us deploying the Smart contract in 2 steps:

  1. Compile a Smart Contract into byte code
  2. Sign the resulting byte code and sent the transaction for Smart Contract deployment
Python
Copy

Response

After the script execution, you should receive an output similar to the one below (except the addresses).

JSON
Copy

Great now you deployed a smart contract on the Credits Blockchain !

Execution status shows the deployment was successful (‘success’: True)

Transaction number in the Blockchain 'transactionId': '13707845.1'

Smart Contract address FAe2em5gQkUaFcWQ1nKVXy2nUwW51p2pgzsZuo1bNpzn.

Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard