Deploying the HelloWorld Smart Contract Example¶
Now let’s look into deploying the HelloWorld Smart Contract in C# on your local network, firstly, let’s take a look at the contract itself.
Compiling the HelloWorld smart contract¶
A smart contract in C# must be compiled into CIL before it can be deployed. For this, we are going to use the Stratis Smart Contract Tool. The Stratis Smart Contract Tool is compiled and packaged with the Cirrus Core Developer Edition wallet and can be found in the below directory:
If you are progressing through the tutorial headless, the Stratis Smart Contract Tool for compiling contracts compatible with the Developer Edition (DLT) can be found here.
Command Promptand Navigate to the
Execute the following command:
Stratis.SmartContracts.Tools.Sct.exe validate [PATH_TO_SMART_CONTRACT] -sb. A relative path to
`HelloWorld.csin your Stratis Full Node repository should work fine.
Copy the CIL to your clipboard.
To see more information on the options available for the sct
validate command, use the following command:
Stratis.SmartContracts.Tools.Sct.exe validate --help
To see the general help on the sct, use the following command:
If you are building the Stratis Smart Contract Tool from source and have previously cloned the repository, please ensure that before you compile any smart contracts, you sync the repository to the latest version of the source code and rebuild the tool.
Deploying the HelloWorld smart contract¶
Begin by making sure that you have the Local Smart Contract network running. You should now be in possession of 100,000,000 CRS-TEST tokens within your
Hackathon_1 wallet! You can deploy the token from the Cirrus Core UI or via Swagger which can be launched from the Wallet drop-down in the top right. This tutorial will demonstrate the deployment from the Cirrus Core GUI.
Navigate to the
Smart Contracts tab within the Cirrus Core wallet and select the
Create Contract button
You will now be presented with the
Create Contract dialog. To deploy the contract you will need to complete the relevant fields. Each member of the object is fully documented in the API. Use the CIL code you generated in the previous section for the
Byte Code field.
Once completed, select
the Create Contract button to deploy the contract. Once deployed, the contract will be visible on the
Smart Contracts Dashboard as per below:
To interact with the deployed contract, you can simply select the
Browse API hyperlink to be directed to Swagger.
This will then launch your defined Internet Browser
SayHello method to display the available parameters
Calling the SayHello() method¶
We are going to call the
SayHello() method, to do this click the
Try it out button.
A lot of the text fields are pre-populated, all that is required is to enter the password.
Execute button to call the method. The response can be seen below instantaneously.
As detailed in the response, we need to check the receipt to view what was returned from the Smart Contract. Navigate back to the
Smart Contracts Dashboard within Cirrus Core where you will find your balance has reduced slightly and in addition there is a new type of Smart Contract execution listed.
Click the hyperlinked
hash text to view the receipt.
Upon clicking the hyperlinked text, you will be presented with a new dialog that displays the receipt of the Smart Contract call. Here we can see the
returnValue proving that the Smart Contract call was successful!
Now we have deployed a basic HellowWorld contract, we can now look at extending the functionality in Tutorial 3.