Remix - A First Glance
Getting Started with Solidity
Last updated
Getting Started with Solidity
Last updated
For aspiring blockchain developers, the first question one might have on their mind is the following: where do I write my smart contracts? For this, we turn to Remix, an interactive development environment that allows us to both write smart contracts and deploy our code to EVM-compatible blockchains. For the purposes of this lesson, we will focus on the process of creating and deploying a smart contract.
When first loading Remix, you will see a home screen similar to the following:
For right now, what we are interested in is the Workspaces column. Remix allows us to create workspaces as a way to separate our projects - imagine putting the smart contracts of hundreds of projects into a single workspace! When first using Remix, we are given a default workspace called default_workspace.
Within default_workspace, we are particularly interested in the contracts folder. If you click on the contracts folder, the following content should drop down from the folder:
As the name might suggest, the contracts folder is where smart contracts live. This is made evident by the three starter smart contracts that Remix provides us with: 1_Storage.sol, 2_Owner.sol, 3_Ballot.sol. For the purposes of this lesson, however, we will be adding a smart contract to the contracts folder.
To create a new smart contract in the contracts folder, right-click on the contracts folder and the following drop-down menu will appear:
Click on "New File" and you will now be able to define the name of your smart contract file. Solidity files have the file extension .sol . For the purposes of this lesson, name your file HelloWorld.sol .
How do I know if Remix recognizes my file as being a Solidity file? Any file that is interpreted as a Solidity file has the Solidity logo to the left of it.
Listed below is the source code of HelloWorld.sol ; copy-and-paste this into your HelloWorld.sol file.
Solidity is a compiled programming language and thus, we must compile our smart contracts before deploying them. On the left-hand sidebar in Remix, you will find a button with the Solidity logo on it. Upon clicking the button, you will come across the Solidity compiler that Remix provides to compile our smart contracts.
To compile HelloWorld, simply just click the Compile HelloWorld.sol button; if your contract is defined correctly, this will result in a green checkmark appearing next to the Solidity logo. If your contract is not defined correctly, you will not be able to compile your contracts and an error message will appear below the compiler tool.
We've now come to the perhaps the most exciting part - deploying HelloWorld! Looking again to the lefthand sidebar, click the button represented by the Ethereum logo which will open up the Remix deployment tool.
Assuming HelloWorld compiled correctly, this is the tool that we will use to deploy HelloWorld. Make sure to select HelloWorld as the contract to deploy in the Deployer tool. To deploy HelloWorld, simply click the Deploy button. For this lesson, you will be deploying to a local blockchain that Remix provides us with (Remix VM).
Congratulations, you have deployed your first smart contract!
Now that HelloWorld lives on your local blockchain, you can use Remix to interact with HelloWorld! We will be calling the print() function via Remix. Focusing on the Deployer tool, you will see that under the Deployed Contracts section, our HelloWorld contract has its own tab. Clicking on the tab, you will see the following:
Rather than having to write complicated code to call print, Remix allows us to call the function simply by clicking a button. Click on the print button and you will see the following:
Congratulations, you have interacted with your first smart contract!
Remix Documenation: https://remix-ide.readthedocs.io/en/latest/index.html