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.

You will need to obtain the Stratis Smart Contract Tool, this can be done using the below command

git clone https://github.com/stratisproject/Stratis.SmartContracts.Tools.Sct

Follow below steps to validate and compile Smart Contract:

cd Stratis.SmartContracts.Tools.Sct\Stratis.SmartContracts.Tools.Sct\
dotnet run -- validate [PATH_TO_SMART_CONTRACT] -sb
../../../_images/image114.png

To see more information on the options available for the sct validate command, use the following command:

dotnet run -- validate --help

Note

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 1,000,000 TCRS-TEST tokens within your cirrusdev 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

../../../_images/image215.png

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.

../../../_images/image36.png

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:

../../../_images/image46.png

To interact with the deployed contract, you can simply select the Browse API hyperlink to be directed to Swagger.

../../../_images/image56.png

This will then launch your defined Internet Browser

../../../_images/image65.png

Select the SayHello post method to display the available parameters

../../../_images/image74.png

Calling the SayHello() method

We are going to call the SayHello() method, to do this click the Try it out button.

../../../_images/image84.png

A lot of the text fields are pre-populated, all that is required is to enter the password and replace the SayHello() string  with ().

../../../_images/image92.png

Click the Execute button to call the method. The response can be seen below instantaneously.

../../../_images/image102.png

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.

../../../_images/image122.png

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!

../../../_images/image132.png

Alternatively, you can call the contract from wallet as well. To call it, just copy the contract address as depicted below and click call contract button.

../../../_images/image142.png

Provide the method name, contract address, password, parameters, and click call contract as illustrated below.

../../../_images/image152.png

Now we have deployed a basic HellowWorld contract, we can now look at extending the functionality in Tutorial 3.

../../../_images/image115.png