compile and deploy your smart contract

In the previous tutorial of our Blockchain Roadmap series, we learnt how to write our first Solidity Smart Contract. Today, we will build upon that, compile and deploy our GetterSetter Smart Contract.

Remix IDE

Remix is a browser based IDE for compiling and deploying smart contracts. You can access Remix at remix.ethereum.org . It can be a little difficult to understand the user interface of Remix at first, so let’s start with that.

 

Remix IDE
Remix IDE tour

We will only talk about the sections of Remix that we are going to use for the tutorial.

The left top corner of Remix has different menus. These include the File Explorer, Compile menu and the Deploy Contract menu.

  • File Explorer: The File Explorer is where all your project files reside. You can have multiple files in a project. File Explorer allows you to create, edit and delete all the files in a project.
  • Compile Menu: Used to compile the smart contracts before deploying them. It shows the errors in contract after compiling, if any.
  • Deploy Menu: If the Smart Contract is successfully compiled, you can deploy it to check if it works as expected.

Before we start, remember to select Solidity in the environment selection tab. Next, go to the File Explorer menu.

Step 1: Create a file.

Create a smart contract
Create a Smart Contract file

Once you are in the File Explorer menu, click on the plus sign(+) in the top left of the file explorer tab. Name your file GetterSetter.sol ( .sol is the extension for Solidity files). You can see your file in the list of sample files that Remix provides.

Copy the code of the GetterSetter smart contract we wrote in the last tutorial. If you haven’t checked the last tutorial, check it out before we go any further.

Step 2: Compile the contract

Compile the Code
Compile the Smart Contract code

Switch to the compile menu to find the Solidity Compiler. Select the correct Solidity compiler version (0.6.0). Once you have selected the correct compiler version, click on Compile GetterSetter.sol button to compile the contract. Any errors in the contract, if present, will be shown at this point.

Turns out we don’t have any, so let’s proceed to deploy the contract.

Step 3: Deploy Contract

Compile and deploy the Smart Contract
Deploy the Smart Contract

Go to the Deploy Contract menu and select JavaScript VM in the Environment drop down menu. JavaScript VM simply means the transactions will be executed in a sandbox blockchain in the browser. If you refresh the browser, a new sandbox blockchain will be created. This is perfect for testing our smart contract.

Step 4: Test the Smart Contract

Our smart contract has two main functions:

  • getString(): returns the value of the firstString variable
  • setString(): set a new value to the firstString variable
getString getter function
getString function output

We will start with checking the initial value of firstString. In the code, we initially set the value of firstString to “Hello World”. So the output when you click on the getString button in the left pane is “Hello World”.

Let us try to update the value of the variable firstString to “The Blockchain Blog”.

setString setter output
setString function usage

To do that, write ”The Blockchain Blog” in the box next to setString button in the left pane of the browser. Remember the value of the string should be enclosed in double quotes (“ ”). You can see the transaction being executed in the window below the code. The window also shows many other transaction properties like the transaction status, hash, amount of gas used, output, etc.

If you click on the getString button again, you will see the value of the variable firstString has been successfully updated.

So this is it. Congratulations, you have successfully compiled and deployed your first Solidity Smart Contract.

If you liked this article, join our community on Instagram, Telegram and Twitter.
For free Udemy Course coupon codes, check our Free Courses page.
32 thoughts on “Solidity: Compile and Deploy your Smart Contract”

Leave a Reply

Your email address will not be published. Required fields are marked *