This tutorial demonstrates how to write, compile, and deploy a simple Solidity smart contract using Remix IDE, covering key concepts including contract constructors for initializing owner addresses, receive functions for accepting ether payments, and require statements for implementing access control to secure fund withdrawal functionality.
Deploy Solidity Smart Contracts with Remix IDE | Beginner Tutorial
Added:hey guys welcome in this video i would like to show you how you can write and deploy smart contracts in solidity using remix ide remix ide is a basically web application so all you have to do in order to write your very first smart contract in solidity all you need is your browser and then inside your browser just go to remix.ethereum.org and then you would see this beautiful ide so here you have a workspace here is a regular editor that where you can create new files new folders and just write your solidity code of course i'm not telling you the remix ide is the best option to write smart contracts for production because then usually you need to write some tests and you need some or historization of your smart contracts so you need a migrations and then you can use a tools like truffle open sapling or hard hat however here is i think a great environment just to try out a solidity especially that you can easily deploy your smart contracts to the test net to the mainnet and then you can um just try to test and verify your smart contracts within this environment so okay first of all i'm gonna create a new file in the very first smart contract and the smart contract i will call it fee collector because this would be the the smart contract that basically is able to take money and the owner of the smart contract can withdraw that money so we're gonna create a very simple uh smart contract just to show you how easily you can create the smart contracts so first of all if we are creating the contract uh we are using here the solid dt uh language solidity is a special language that you can use for preparing smart contracts and the ethereum virtual machine solidity is an object-oriented high-level language and i think it's quite similar to c plus plus and maybe javascript so if you are familiar with these languages i think you should not have any problems uh in the description to video uh to this video you can find some free resources from which you can learn the basics of the solidity because in my video today i would like to just quickly show you how you can start um writing contracts and how you can interacting with them from the remix id however if you need the basics of the solidity like how right functions what types are inside the solidity i think you can find everything here in this official docs so whenever we are creating a contract we have to name the contract so this contract would be named fee collector and of course we have to open the body of the contract however before we write any code we have to always specify what version of solidity we want to use so we need to basically specify this in our code in every file that's that has the smart contract code inside we have to specify this uh just to inform the the compiler what version of solidity actually we are using so we are having here pragma solidity and we are using the latest version of course if you are watching this video in the future probably uh you might change the version of the solidity here in the compiler section so this is the second item on the menu and here you see all the versions of the solidity compilers and i think it's especially if you are experimenting if you want to try something it's i think advice to check always the latest version of the solidity because you have the access to the latest feature in your in the solidity of course for some legacy applications you might need to choose other version because you might use some of the features of the of the language that were depreciated but of course we're gonna use the latest version and okay we have our our smart contract here and right now we're gonna create a constructor so whenever we are deploying the smart contract to the network uh then um for the first time the constructor can be called so so it's the special function which is called whenever the smart contract is created and of course like in any other languages we can pass parameters to the constructor or we can just leave the constructor without any parameters and we can write here some code that would be invoked whenever the smart contract is actually deployed to the blockchain network and here i will uh just write in the constructor i will save information inside the smart contract about the owner of this control smart contract so basically uh i want to have um the the variable which i will call at the owner so this is the special for label which will hold information about who is the owner of the smart contract and solidity is typed language so if i want to keep any information inside this variable i have to specify what is the type of this specific variable and um in the blockchain world in the solidity the ownership is represented by the public address so we are not dealing here with uh some api keys we are not dealing here with json web tokens uh in the blockchain world uh if you are calling the smart contract if you are deploying the smart contract if you're reading from it or if you are issuing some um some transactions or calling the functions from the smart contract you always operate with your address so we're gonna store the address of the owner of that smart contract so we have to specify the type of this variable to address and we're gonna mark the the variable as public so you see here that whenever you want to specify the variable you have to specify the type of this variable and you have to specify the visibility of that specific variable of course you can read all the details of that stuff in the in the official docks of the solidity but here we have the really simple uh variable which is the address public owner and here in the constructor we're gonna sign that the owner is the message dot sender and message.sender is a specif special variable in this solidity world so whenever uh somebody is calling the function then under message.sender we're gonna see the public address of the caller so let's say i'm gonna deploy the smart contract this fee collector with this account then the message sender would be actually my public address so so that that that would be under the message sender and i'm signing uh assigning um that this value under the um under the variable called owner so right now we have a really simple smart contract that all it does it actually creates the smart contracts and assigns the owner under this variable so let's uh let's try to actually compile this this specific file we have one warning about not specifying the license of our smart contract so just to shut out the the compiler i will copy here the information about the about the license so this is mit and now you can see that we can click on the compile the fee collector we can even click here how to compile so so so whenever we we change it and save it then it would be automatically recompiled for us so right now we have this smart contract and i think it's the perfect moment to actually deploy it and here if we go to the next section of their remix ide here we have the interesting options in which we can deploy and run our transactions and here you have the environment one environment is javascript virtual machine so this means that we are able to deploy our smart contract not into the real blockchain network but we can deploy our code into the javascript memory so basically in this memory of the browser we have the the simple version of the blockchain to which we can deploy the smart contract and of course you may ask the question why the hell we need that right why why we need uh to deploy something into the memory it doesn't make sense right but it turns out that if you want to try your code or just to be sure that your code is working before actually deploying the code to the real blockchain network you can deploy it to the memory because then it's much faster so you can just check that okay the logic works and once you are sure that everything is fine then you can deploy it to the testnet or even to the mainnet so here we have this environment which is a virtual machine we have here various accounts so right now i can choose the account which i'm interacting with the virtual machine so this actually actually is something like i would use my meta mask my wallet but here i'm just using some test wallets that are connected to the virtual machine and right now let's click the deploy and if we click deploy now you can see the list of deployed contracts and here basically we have just one thing that we can call on this smart contract because automatically if we have the public variable then we have a reader to that public variable so if i click the owner now you can see that i'm that's this is the address of the person which actually um deployed the smart contract so for instance if i change the account and if i click the deploy again now you see that we have two instances of this contract deployed and the second instance if i call the owner you actually see that the address here is completely different than in the previous case so we have two instances of our depth of our contract deployed so of course now our uh contract is actually not that interesting right we have just the constructor but i think it would be great if we can send the money um to this specific smart contract so in order to send the money um to the smart contract we have to prepare the special function which is called receive so whenever we want to write logic for our contract that is able to um receive some money then we have to create the function called receive and we need to um mark this function with the payable keyword and then we have to also turn the visibility of that function as external and for instance right now if we have the function receive we are it's possible to send actually the ether to that smart contract because whenever we are deploying the smart contract you can see that we have the address of the smart contract so this smart contract is deployed under this address of course this address is not real because it lives only in the javascript view to our machine however we will now deploy our smart contract um into the rinkeby test network so you would see that we can also use very easily the remix ide to deploy the smart contract into the testnet so the smart contract has the address and we are able to send the money so this smart contract will hold the money and here we have the function called receive and this function would be called whenever somebody sends money to the smart contract and right now i think it would be great if we can not only store the public value which is the owner but we can also store another vari value which would be the balance so right now i want to have the the public um the public variable the store information about the balance so whenever the fee collector smart contract receives money we're gonna increase the balance so we can track how much money is actually stored inside the contract so right now we have to add a type for this variable and we want to keep it as an integer so i will use the unsigned integer 20 256 and i will mark this variable also as the public one and right now when we have the variable called balance we can here um just type balance plus equal message value this is equivalent to something like balance plus message value right so it's you might know this from javascript or other programming languages that we are just increasing the balance so the function receive can be called twice or fifth times and whenever we receive the transfer into that contract we just want to increase the balance and we need to know so we can know how much money is inside the contract so message.value is another special variable in the solidity which basically lets us access how much money was sent to the smart contract within the transaction so if somebody is calling the function the message sender is always the person which calls so basically is the address and whenever we are sending some money the message.value holds information about how much ether was sent to the smart contract and it's represented in a way and we can call we can save that smart contract however this time we're gonna deploy it into the marin kb test network so if i uh select here the ring the injected web 3 then the remix ide is connecting to my metamask wallet so right now i'm using the account one on the ring kb test network and here you can see that remix ide is connected to my wallet if you are doing this for the first time and you select the injected web3 and you have the metamask then metamask will ask you about connecting into the remix ethereum orig so you might accept this whenever you want it so here we have the account the one from the meta mask and now if we want to deploy this smart contract if i click here the deploy now you can see that metamask asks me about issuing the transaction so if i will confirm it then we are deploying our our very first smart contract in solidity into the rinkeby test network and after some time you see that we actually deployed the smart contract so we have the smart contract we can call the balance the balance is zero and here you can see that the owner of the smart contract is actually the caller so i'm the owner because here is obviously my current uh address and here uh if we copy on the address of the smart contract and if we go then you can see that it's our smart contract so this smart contract is basically uh deployed to the blockchain you can see that our code was uh compiled uh into um into that code that is not really readable to humans and now our smart contract is here on the blockchain and now we can start calling it so now i will send money to this um to this address so this is the address of the smart contract and if i go into the to my ring p um i can just here uh type the recipient and here i can decide that i want to send for instance 0.02 if and if i select and i have the contract interaction if i click the confirm now i send just 0.02 if into that contract so let's see the the block explorer and here we see that we actually have the bonds so our transaction just arrived to the smart contract and if we call the balance here again now you can see that actually the money was received however our smart contract is not ideal because we have some money inside the smart contract but smart contract only knows how to receive money and there's no option to get this money back because this this specific smart contract only receives money and we deploy it and now we are not able to change the code of this smart contract so let's fix it and let's deploy it again so this time we're gonna create the function which gonna call we draw so i will use the keyword function and withdraw and this function will basically take the parameter so so we can take um how much we want to withdraw and then we also want to specify to which address we want to withdraw this money so we're going to have to type the type address payable because we need the type of the address to which we can send the money and we can type here test address so here you can see um that we have the function and the function is called um withdraw and it takes two parameters one is amount and second is um the address destination destination address so this function whenever it's called we want actually to transfer money to this address and every address every payable address in the solidity actually has the function which is called just transfer so we can just specify here the amount that we want to transfer from our smart contract so basically we will call this function with two parameters one is how much money we want to withdraw and the second is to which address we want to send it and of course whenever we do the transfer we of course have to deduce it from the balance so balance is always representing um the correct amount so from the balance we have to deduct the amount and compiler is uh shouting that we have to mark the function how it should be visible so whenever we want to have the function that can be called outside from so anyone can call it we need to um have the visibility set to public so right now this this function is public and everybody can uh call it and you might be surprised that why we have the function that's everybody can use because as you can see the smart contract collects money so it holds 0.02 and then we have the public function which anybody can call so this can result with the staff that anybody can come into my smart contract and just by knowing uh the smart contract address and the api code which i will cover in separate video then you can just start interacting with this smart contract and everybody can withdraw the funds so i guess we have to secure this function a bit so this function and this transfer can occur only if this function would be called with owner account so this would be the special function that of course is public but it can be called only by the owner so there is a nice um solution for that we can write require and this require um is checking basically the first um the first parameter is checking whether it's true or false so we can write here that the message sender has to be owner and if it would be false then we want to return the error which would be only owner can withdraw [Music] so right now we have the guard that a function would be called and here uh the solidity will check that the message sender so basically person or address that calls the function is equal to owner and if this would be not equal owner then it would be false and it would be this error rised and all the other execution of the smart contract is stopped so require is a really nice function which let us do some sanity checks inside the functions just that we are sure that the function can be called and another i think useful thing that we can check in this function would be that this amount is lesser or equal balance just to not have situation that the balance is 0.02 at there and somebody wants to withdraw two others because obviously it was result in some error so we're gonna check it and we're gonna present to the user nice error like insufficient fonts so right now i will save this smart contract and it's going to be compiled and now we're going to deploy it again to our rb test network and you can see that whenever i change the code i'm not able to use the old address see that old smart contract is already deployed and i'm not able to change the code of the smart contract so here i will deploy another one so if i click the deploy then metamask again is asking me about the transaction fee because of course i have to pay to the miners that they will mine my transaction and i have to pay the fee for actually putting my smart contract into the blockchain so this transaction fee depends on the size of your smart contract and how heavily are you using the memory so the bigger the smart contract is the more variables are you are using the more memory are you are using you will pay more transaction fee so right now i i will confirm that and in the minute we need to we would see the second instance of this fee collector smart contract so right now you see that we have the withdrawal function which takes some arguments so again i will copy it and i will send some money to this um to this um smart contract so let's send let's specify and let's send 0.03 if um to this smart contract and we're going to confirm that and let's wait a second for the transaction to be actually mined and now we see that the balance actually updated and now i will try to withdraw the funds i will specify that i want to withdraw not all this amount so i will just maybe try to withdraw one so 0.01 and i will i would like to send it to some other address so for instance we have here some address that holds zero if and i will just specify here the address so i'm providing this as an argument and i will call a withdrawal function you can see that we have the error because the only owner can withdraw and the reason why we have it is that in the meta mask right now i have this account seven and if i go to the previous account the one which is the owner right because we have the owner here and we are checking it so if i click the withdrawal again now you can see the transaction works so our require actually worked and checked that we are the senders and if i click here now the confirm now we have the transaction in in the blockchain to be mined we have to wait a second and the balance should be updated shortly so you can see that right now it holds 0.02 if so it's no longer 0.03 if we refresh that that this smart contract holds 0.02 and if we check my account that previously had 0 if now we can see that it holds 0.01 so that was uh just to show you how you can develop smart contracts of course this is just an experiment if you want to create the smart contract that does uh way more things it's also possible you can for instance emit events from the functions uh you can write some private functions that are just accessible from within the code of the smart contract so they cannot be called publicly by anyone so there are a lot of interesting topics that of course you can do with the smart contracts however here you can see how powerful it is because you can just deploy the smart contract once it goes to the blockchain and then you can write a logic that is responsible for taking um the money and proxing it to some other addresses of course you can hear also uh the list of the people that are whitelisted in order to withdraw the funds so you can use the one single smart contract and do a lot of interesting use cases i hope you liked the video i hope you learned something new of course if you have some more questions about solidity and smart contracts post them down below in the comments section uh i know that i didn't cover everything about the solidity but i just wanted to show you how the constructor works how the remix ide works how you can deploy the smart contracts how you can choose the environments and do the compilation and then of course in the upcoming videos i will show you how you can deploy the smart contracts and then start interacting with them from the react.js applications so that's all what i have for you thanks for your attention and see you on this channel
Up Next

Solidity Course: Ethereum Blockchain Development & Smart Contracts
@freecodecamp
1.5M views•2019-07-19

Torrent File Format & Bencoding: A Technical Deep Dive
@AsliEngineering
12.5K views•2022-08-08

Operational Security Essentials: A Guide for Hacktivists (OPSEC)
@hitbsecconf
157.4K views•2012-11-26

Understanding Ethereum: A Comprehensive Beginner's Overview
@99Bitcoins
3.1M views•2018-06-26
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Blockchain & Crypto
















![How to Become a Blockchain Developer? [Complete web3 Developer Roadmap]](https://i.ytimg.com/vi_webp/q54j35z3fPQ/maxresdefault.webp)

















