1. Home
  2. Training Library
  3. Programming
  4. Programming Courses
  5. Smart Contract Development with Solidity

Remix Introduction: IDE Overview

Remix Introduction: IDE Overview
Overview
Difficulty
Intermediate
Duration
3h
Students
49
Ratings
5/5
starstarstarstarstar
Description

This course provides a deep dive into the Solidity programming language which is used to implement smart contracts on blockchain platforms. This course will give you a practical understanding of Solidity and how to develop your own smart contracts.

Transcript

All right. In this lecture, we're talking about the remix IDE which is open here in the window and I'm going to show you what you can achieve if you follow this lecture thoroughly. So, I have a smart contract here and I run this smart contract, and when I hit this "Hello World" button, then Hello World will stand here based on this variable. And when you click it, then you see here in the lock window that there are transactions. Now, let me completely remove this and tell you how I did this. When you first open up remix, let me just reload the window, then it will look exactly like this, so very, very similar. So, remix might have some design updates over time. But if you the first time go to remix, the theorem.org, this is basically where you find remix, then you get a website, and this website is like any other integrated development environment. If you've ever worked with VS codes or any editor basically atom or maybe IntelliJ, then you know the very basics of any IDE. You have an editor window, you have something like a foul browser where the files for your projects are, and you have a compiler eventually integrated and some debugging functionality. And that's not very different here in remix but it's specialized for solidity development. And the first lecture here is we need to give you an overview of remix, how it works, and for that purpose, I want to write a very, very simple smart contract and every single smart contract, every programmer starts with the "Hello World" smart contracts, so this one will be exactly the same. So, when you start remix, you have like a smart contract here in this editor window already opened, and that is an example of solidity, how you can vote on the Blockchain. So, when you write smart contracts, you write them in solidity and they're getting compiled and over here on the right side under the compile tab, you see the current version of the compiler. So, currently, there is the version number 051 loaded. It's not the newest version, the newest one over here is 054. So, you're good. As long as you go with 05 something, be aware that they are sometimes having breaking functionality. They are sometimes not backwards compatible. Now that we are talking about this compile tab, there's one thing that I really want to highlight here is this auto compile functionality. So, whenever you change something, then you see that it starts to compile here on the right side. And when I take this out, then nothing happens. So, you have to click start to compile and usually as long as the smart contracts are not too complicated, I leave this auto compile on and I want to urge you when you go to remix ethereum.org, which you should be because if you're following this lecture, then just open your browser, go to remix ethereum.org, and have a look around with me together. And the first thing is see that this auto compile is on, so that you don't have to every time you change something hit 'Start to compile'. All right. The first thing is usually I close this ballot, it's already filed because I don't need it, and I create a new one. And you find here on the left side on top of your browser, you find a little plus button, you find other buttons to where you can open files, you can publish them to GitHub, Gist, and so on. But for now, we just want to create a new file and we are calling it "HelloWorld". And solidity, there's solidity, have the file ending SOL. So, I call it hello world.sol, and I just simply hit "Return", or you can click the 'OK' button and you're presented with an empty editor window. And now I will tell you what I'm going to write now but I will not tell you too much explanation because I really want to focus on the solidity remix IDE here. So, every solidity fell starts with the so called pragma line and that tells the compiler for which compiler version this solidity file was written for, and that follows so called cember versioning. If you don't know what it is, just follow along we're discussing it in detail later. So, I say pragma solidity and then I have this ^050, and that helps this cember caret tells the solidity compiler that this solidity file was written for version 05 X, so 050, 051, 052 and so on. So, greater or equal 050 but not expanding 06, so it's not including 06. And after that, there comes the smart contract, and every smart contract starts with the keyword contract, and then in CapWord style meaning the first letter is capitalized and every other letter of every word is capitalized, so hello, the H is capitalized, world is capitalized, and then our curly brackets. And inside these curly brackets, there is the contract body meaning this is like you would have it in a Java class or any other class really. You write your actual contract code that would mean variables, where you have usually class variables, they are called storage variables here. And you have functions, and you also have something like modifiers which we're going to discuss later. And now I want to write a simple string that is a so called reference type here that shouldn't bother you any longer, just refer to it as a string for now, and I called it Hello world. And I initialize it already here with double quotes, Hello world exclamation mark. All right. I see here on the right side under my compile tab that because I auto compiled on, it keeps compiling the smart contract and I see this is green, there are no warnings whatsoever. If I have any errors then solidity, the remix IDE will tell me where the error is, what is expected. It's not always accurate but it's getting better from solidity version. And I usually really prefer this auto compile on, so I immediately see when there are errors. If you are on a very slow machine or if you have very complex smart contracts, which you probably have not, but if you have them, try to turn off auto compile in order to have more speed during writing the actual solidity files. It can eventually slow down your computer if you leave auto compile on. Okay. Now we have this smart contract, it is compiled and it doesn't do anything yet. I will add a public here and when I add the public to a storage variable and we are also going to discuss this later. I just want to give you a heads up. When you add the public to a storage variable, then solidity will automatically create a function which has the same name as this variable here. So, the function will be Hello world and it will be a get to function, so you can read out the contents of this variable once it's deployed. Now, a smart contract needs to be compiled and deployed on the Blockchain. And this remix IDE comes with free ways how you can deploy a smart contract, and when you go over here to the run tab, there are several tabs here on the top and the second one is the run tab. Then you find a dropdown here as a first element and the first element is the environment's dropdown. And here you have three options. The first one is JavaScript VM, the second one is Injected Web3 and the third one is Web3 provider. And for sake of development and simplicity, we are going to work with the JavaScript VM. The JavaScript VM is a blockchain that is running entirely in the browser whenever, it's just in memory, whenever you reload the page. The contents of the Blockchain will be gone and will be resetted. And it really helps with prototyping rapid development of smart contracts, just trying out something. It's really, really helpful just to have this. Now the downside is you cannot connect from the outside, so it's really just a private Blockchain, a private Ethereum network that is running as a single node and simulating mining in your browser. Very simple thing, can't do much, but it's very helpful if you just do prototyping. The second thing is Injected Web3 and we are going to discuss this a little bit later when we are talking about things like metamask over here and misth. Those are connecting to an external Blockchain, but injecting a so called Web3 object into the browser window, so that you can go via this metamask to the Blockchain and it behaves like any other plugin you would interact with. So, you have your wallet outside of the browser and furthermore connect to a Blockchain note. And the third one, Web3 provider would be if you connect directly to a Blockchain node. Now, does this have to bother you at all at the moment? No. We're going to discuss this later and I will guide you step by step through these steps how to use these environments properly. For now, I want you to select the JavaScript virtual machine, and as soon as you select the JavaScript virtual machine in the accounts dropdown, you will have five different accounts to each 100 ether, and because it's just a simulated network in your browser and you have full control because you are the owner of your browser hopefully, so you have full control over what is happening in your browser. You can also influence the data that is on this Blockchain that is running in your browser. So, it's like having development database that is running under your control. So, it doesn't come with all the great features of a normal Blockchain with decentralization, but the way you access the data is the same. So, in this case, you can also compile smart contracts and then deploy those smart contracts. And the accounts here, these five different accounts, just help you to simulate different people that are interacting with your smart contracts assuming over here, you have control over these people but let's assume that this one is you, this one maybe somebody else, you don't have access to this account and so on. So, we are going to get to this a little bit later, for now, just select the first account. The gas limit, you can leave it at three million for now. The gas limit is here to avoid having endless loops or endless running processes running on the Blockchain. If you run code on the Blockchain, then you have a certain amount of computational operations that you can do when each one of these computational operations cost gas. And the gas limit limits the amount of computational operations you can do. The value is here to send with the transaction some value along to your smart contract. We are leaving this at zero for now and it's going to be way for now, so just leave this at zero. Next important part. You have a dropdown here, and you can select a smart contract you want to deploy or interact with. And this one comes directly from the solidity file, which is open here. In each solidity file, you can have one or more smart contracts, so it doesn't necessarily have to be the smart contract with the same name as the file but it became a very good practice to just have one smart contract in one solidity file to make them easier to maintain and then import them with so called import statements which we're also going to discuss later. Okay. It's a long story short. Once you're done, JavaScript VM first account gas limit very large for now, zero value, at the right smart contracts selected here, and hit "Deploy". On a side note, if there is a wrong smart contract or the smart contract is not here yet, go back to the compiled up and see if auto compile is on or if you really compiled.  It happens quite frequently that it's not compiled. The next thing that you see is over here on the bottom. You have this lock window here and this lock window has two functions. The first one is you can run simple commands against the internal Blockchain node here that is running in the browser. The second one is logging of transactions. So, if you are doing anything on the Ethereum Blockchain, if you interact with the smart contract, if you deploy a smart contract, if you read from a smart contract, if you write to a smart contract, then a transaction is sent against the Blockchain node. It is almost like an Ajax request against an API, just slightly different with different data and the data is always standardized. So, this particular transaction that happened here came from this address. It went to an empty address, so it created a new smart contract. It cost some gas and it had some data that was sent along which is basically the compiled smart contract in hex format. And once that is done, you will see your smart contract here on the Deployed Contracts on the right side and there's a little dropdown here and with this dropdown, you can interact with your smart contract. One thing that I want to highlight is that the smart contract is running under its own address here, but we're also going to discuss this in a little bit. All right. That's it for this lecture. And in the next one, we are going to enhance our smart contract a little bit with some more functions to write and read, and I'm going to talk a little bit more about transactions.

About the Author
Students
58
Courses
7

Tom is a CTO, senior back-end developer, and systems architect with over twenty years of hands-on development experience in a variety of languages and systems. He has a CS master's degree and has been working with Ethereum and blockchain technologies since 2016.

Covered Topics