Creating and Deploying a smart contract on the Stratis TestNet

This article explains in detail the process to deploy a sample smart contract.

For more information about Stratis smart contracts, see Official Stratis Smart Contracts documentation

Get Github Desktop

Start by downloading Github Desktop from: https://desktop.github.com/ and installing it

Clone the latest Stratis Full Node

Start Github Desktop and go to File -> Clone Repository and click on URL. After that a window will open. Paste https://github.com/stratisproject/StratisBitcoinFullNode.git inside the first textbox and select a location to place the project. In this case it is located at C:\Projects\SDFFullNode. Click on “Clone” and let it finish. The project will now be located at the provided location.

Switch branches to the alpha Smart Contract branch

Click on “Current branch” on top of the screen and select “origin/sc-alpha” from the list as shown in the screenshot

Set up the Smart Contract sample template

Open Visual Studio and select File->New->Project. In the New Project window, select “Online” and search for “Stratis”. The “Stratis Smart Contracts Template” option will appear.

After double-clicking it and selecting “Modify” in the following window, it will start installing. You have to close Visual Studio (not the install-window) to proceed with the installation.

After the installation has completed, open Visual Studio again and select File->New->Project. On the bottom of the list in the following window, “Stratis SmartContract Project” will be there. Select it and press “Ok”. You have now successfully created a default SmartContract project.

Start the Node

Open a command-prompt and set the location to the SmartContracts Daemon location with the “cd <location>” command. In my case it is located at “C:\Projects\SDFFullNode\src\Stratis.StratisSmartContractsD”. This will be the location you have selected in Github Desktop.

Start the smart contract enabled daemon by entering the following commands:

dotnet restore
dotnet run -addnode=13.64.119.220 -addnode=20.190.57.145 -addnode=40.68.165.12

After this, the full node is running on your computer. Leave this open.

Create a test wallet for funding your smart contract deployment and usage

Open a browser window and navigate to http://localhost:38220/swagger. Here you will communicate directly with the currently running API.

Scroll down to the /api/Wallet/create endpoint, click on it and click on “Try it out”. In the textbox, paste the following code:

{ "name": "Satoshi", "password": "password" }

You can also change Satoshi/password to your desired credentials, as long as you remember them. After this click on “Execute”. Your wallet has now been created.

Get the addresses from your wallet

Scroll down to the /api/Wallet/addresses endpoint, click on it and click on “Try it out”. Enter your WalletName (this will be the name you have provided in the previous step) and enter “account 0” in the AccountName textbox and click on “Execute”. A list of addresses will be returned as shown in the screenshot

Get “Test Strat” (TSTRAT) for testing

Copy one of the addresses from the previous step and navigate in your browser to https://smartcontractsfaucet.stratisplatform.com/. Paste the copied address and click on “Get $TSTRAT”. An amount of 100 $TSTRAT is now sent to your address. If you look at the FullNode window, after a while it should display a confirmed balance of 100.

Deploy the Smart Contract

Open a new command-prompt and navigate to the SmartContract Tools location. It will be located at: “C:\Projects\SDFFullNode\src\Stratis.SmartContracts.Tools.Sct”, depending on where you stored your project you cloned from Github.

Deploy the default SmartContract by entering the following command in the command-prompt:

dotnet run – deploy PATH_TO_SMART_CONTRACT http://localhost:38220 -wallet [YOUR_WALLET_NAME] -password [YOUR_PASSWORD] -fee 0.002 -sender [YOUR_WALLET_ADDRESS] –params 10#20

  • PATH_TO_SMART_CONTRACT: Go to Visual Studio, select the Auction.cs file and copy the location next to the Full Path property in the Properties window

  • [YOUR_WALLET_NAME]: The name for the wallet you have provided earlier

  • [YOUR_PASSWORD]: The password for the wallet you have provided earlier

  • [YOUR_WALLET_ADDRESS]: The address you have used to receive the funds on earlier

If everything went successfully, the command-prompt will return a Contract Address as shown in the screenshot

Execute a bid on the Auction Smart Contract

Navigate to http://localhost:38220/swagger and scroll down to /api/SmartContracts/build-and-send-call, click on it and click on “Try it out”. Inside the text box copy the following code:

{

  "walletName": "Satoshi",

  "contractAddress": "mhy7g8mMt5WnGLGC5NpjGqn2jnKjmeJnwX",

  "methodName": "Bid",

  "amount": "10",

  "feeAmount": "0.001",

  "password": "password",

  "sender": "mqDBJHcu1hqG1a7GcAtGgzNzCeSTLfuf5p",

}
  • walletName: The WalletName you have provided earlier
  • contractAddress: The ContractAddress which has been returned in the previous step
  • password: The password for the wallet you have provided earlier
  • sender: The address you have used to receive the funds on earlier

Click on “Execute”. If everything went successfully, you will see the following result

Congratulations! You have now created, deployed and called a Stratis SmartContract!

Article written by @Aevan (can be contacted on our Discord) Tip @Aevan with Stratis here