Creating your first smart contract

We’ll start by creating a simple “Hello World!” smart contract to get comfortable with the IDE and its debugging tools. Here’s what we’ll cover:

1. The contract will store a string and a number.

2. It will print “Hello World!” in the debug output.

3. Methods will allow retrieval and modification of the string and number, recording who made the changes.

To begin, go to Resources/Templates and select CRC Empty Project. This will create a new contract structure that you can modify to meet these requirements.

var CRC_Contract = {

/** 
 * TODO: Contract Class Initialization; Initialize here yout contract properties
 *
 */
           _Name : "MyContract",      // Token Name. It must match the project name in the settings 
         _Symbol : "MCT",             // Asset Tiker.It must match the one in the settings 
          _owner : "Enter here the owner's wallet address", // Asset Owner Address
  
/** 
 * Contract Constructor. It will be executed only once, when the contract is deployed.
 *
 */
    _constructor: function() {
      
      // TODO: enter here your constructor code
      
    }

};

To improve the class, we’ll add:

  • Properties to store the string and number.

  • Fields to track who modifies these values.

  • A method to print the “Hello World!” message.

  • Methods for setting and retrieving the string and number.

With these updates, the class will resemble the following structure:

With these updates, the contract can handle string and number properties, track changes, display the “Hello World” message, and provide methods for setting and retrieving values. This added functionality prepares you for further experimentation in the IDE. The msg variable, prepopulated by the node, contains key details about the current call.

The fields within the “msg” structure are defined in the “Definitions.hc” library. This integration makes crucial call information easily accessible, enabling smooth interaction with the blockchain from within the smart contract.

Last updated