Published 15 October 2018

Creating a Smart Contract in the Credits Wallet Desktop

Creating a Smart Contract

Smart contracts  - are stand-alone, automatically executable software algorithms designed to automate the performance of contractual obligations of participants in any transaction based on blockchain technology.

Description of the smart contract for JAVA

Description of the smart contract for JAVA

Consider the elements of the simplest smart contract, implemented in JAVA, presented in the figure

  1. A smart contract on the CREDITS platform is the JAVA class inherited from the SmartContract class. In this case, our smart contract is called Contract.
  2. Methods and class variables can have a scope (private - visible inside the class, public - visible in other classes). In our case, one variable res is closed, two functions (methods) are open - the constructor of the Contract class and the store_sum function.
  3. The store_sum function performs the calculation that is included in the smart contract. In this case, the function takes two integer values ​​- a and b, adds them together, then outputs them to the console. When calculating the sum of a and b, the result is stored in the variable res.

To create and deploy smart contracts on the CREDITS platform, you need to install Wallet Desktop (user's wallet). After logging in and logging on to Wallet Desktop, the application should look like this:

To create and deploy a smart contract, we are interested in the "SMART CONTRACT" button, we click on it and the application should look like this:

Elements of the interface:

  • "search contract" editing element, entering and searching for a smart contract
  • "SEARCH" button, search for a smart contract
  • button "CREATE", create a smart contract
  • "BACK" button, return to the previous window

Click "CREATE", the application is an example of the form.

Elements of the interface:

  • Smart contract editor (supported by JAVA highlight)
  • item list, shows smart contracts
  • "BACK" button, return to the previous window
  • button "CHECK", check the correctness of the smart contract
  • "DEPLOY" button, deploys a smart contract to a blockchain

We will enter the text of the smart contract presented above. Then click "CHECK", then "DEPLOY". Congratulations, your smart contract is deployed on the CREDITS platform. To find a smart contract after creating it, you must save its hash.

Let's explain in the image below: the search and execution of a smart contract.

In order to execute a smart contract, it must first be found from a previously saved hash.

After the smart contract is found, we select the method we want to perform from the "Choose method" drop-down list, then fill in the input parameters of the method. We execute the smart contract method by pressing the "EXECUTE" key, the result is shown below.

0 Useful article

Contents