Exploring Blockchain Development — Day 1
Creating your first smart contract in Solidity
In this series, I am going to share with you my journey in learning how to become a Blockchain Developer. I am not going to explain what blockchain is or how it works as there are plenty of resources out there.
We are going to use Solidity as the language to creating this smart contract by making use of a free online based integrated development environment (IDE) called Remix.
Go to https://remix.ethereum.org/
Lets create a solidity file. In the File Explore, left click the contracts folder. You should see three files already created. We do not need these files. Go ahead and right-click these individually and choose Delete.
Right-click the contracts folder and click on New File. Name this file MyContract.sol
As you may have guess, the extension “sol” represents a Solidity file
Every new Solidity file follows the same starting code that signalifies what licences this contract falls under and which version of Solidity this contract was written for. Type the following at the top of your contract.
The carrot says, we are developing for Solidity versions 0.8.0 or higher. Next we name our contract the same name we named our file and surround the block of code with curly brackets.
Let’s put a simple message our contract will output. Here we create a string variable that stores a message that is public seen outside of the contract that we will soon see how to interact with the contract.
Save your contract by press CTRL + S
As you saved the contract, you may have noticed this red warning on line 2.
If you hover your mouse over it, it gives you a message as to what the problem is. In our case, we have forgotten to put a semi-colon at the end of the statement to close it off. Put on in and Save the contract. As soon as your save the contract, Remix checks the code and will give you a green tick here.
The icon that signalifies a green tick is the Compiler. Click on it.
Here you can see the compiler’s version which meets the version you specified.
Click on the Compile MyContract.sol button to convert your written code to machine code.
Lets Deploy our contract, click on the Deploy and Run icon.
In the Deploy and Run Transitions window, we can select which environment we wish to deploy to. In this case, we will leave the default to deploy to our local browser.
Under Account, we have a number of test accounts we can use, lets leave the default.
Click on Deploy. This will deploy our contract locally. Expand our deployed contract and you will see the myMessage button which matches the variable that we declared (created) and if you click on the button, it will display a message.
Congratulation, you have created, deployed and interacted with your first contract.
In the next article, we will have a look at the different variables, information we can store within our smart contracts.
If you found this article helpful, please give me a Clap, as this brightens my day knowing I may have helped someone in their journey in making stuff! Also if you want to be notified for future releases in this series, “Follow” me. You may also send me a message if you need any further help.