DEV Community

Cover image for What are smart contracts? Learn and deploy your first contract.
Siddharth Singh Baghel
Siddharth Singh Baghel

Posted on

What are smart contracts? Learn and deploy your first contract.

Congratulate and appreciate yourself because you choose to enter the web3 world, a technical underworld that has immense potential and opportunities for devs like us. Checkout more articles related to blockchain and web3 here on this article series and make a presence in web3 underworld 😎.

Lets enter the web3 underworld:

A gif to show we are entering inside web3 underworld

Table Of Content

What are Smart Contracts with Example?

Smart contracts are simple programs or codes (written in the solidity programming language) stored in a blockchain that will be triggered upon certain conditions. As simple as that. Let me give a real-life example to better explain this.

Remember the Espresso Machine in offices,

Espresso Machine to explain the smart contracts with real life example

You press Espresso and put the cup below the nozzle then it will serve you the freshly made hot coffee. Your friend Peter Parker wants Cappuccino, he presses that button and got one, woohoo.

Yeah, smart contracts are that simple. They are a simple set of rules which are written in a coding language (Solidity) with the help of variables and functions similar to any other coding language.

Espresso smart contract written in solidity in remix IDE

Who uses smart contracts?

Anyone working on web3 projects needs to do some work with smart contracts. Now, some of us might not be so much familiar with web3 and blockchains, I advise reading this article to get a more clear understanding.

Coming to smart contracts, if you have decided to build a dApp (Decentralized Application) upon any chain which supports EVM (Ethereum Virtual Machine), you will need to write a smart contract.

  • Smart contracts are basically the bridge between the decentralized application and the blockchain. Let's take the previous Espresso Machine example, here suppose Espresso Machine is a Blockchain and you as a user wants a freshly made cappuccino.

  • What you will do is interact with the menu present on the espresso machine and press the Cappuccino button there. This menu is our smart contract, the bridge between the user and Blockchains (Espresso Machine here).

  • Upon pressing the cappuccino button the smart contract will interact with the Ethereum Blockchain (or any other depending on the user) and transfer 30 wei( = 30* 10e-18 ETH) to the owner of the smart contract and serve you the coffee.

  • The owner of the smart contract is the address who deploys it. Also, because smart contracts are deployed only once on the main-net, the owner can't be changed, any set of rules are also unchangeable after the deployment of the smart contract.

Pre-requisites

So, since you have decided to enter the web3 world and are eager to write your first smart contract, let us discuss some of the homework which you have to do,

  1. Basic Understanding of Blockchain Technology - Follow this article series from the beginning.

  2. Learning Solidity - If you are good at any one programming language (c, cpp, python, etc. ) it will hardly take two-three weeks to learn solidity basics, and trust me basics are enough to start.

    Resources: Solidity Tutorial is a very helpful website for learning solidity. Other than that DEV also has some very good articles and Youtube is always our saviour.

  3. Follow me on DEV 😁

IDE (Integrated Development Environment)

After completing the necessary prerequisites, you are ready to start coding your first Smart Contract.

  • Now when decide to start coding something, the first thing that crosses our mind is which IDE should prefer. Here, in case of solidity, since this language is still so young, we don't have many options for IDEs available. The one which is globally preferable at this time is Remix. Remix has a variety of test networks and each account in every network gives the user 100 free test ETHs which are more than sufficient for the developers.

  • Remix also gives us the option to connect our MetaMask wallets.

  • Once you have mastered smart contracts and want to start building dApps, you need both the front end of the web or mobile app along with the backend, then you will use the IDEs preferred for respective dApps. For example, if you want to create a web dApp, you might prefer VS Code Editor.

Miscellaneous FAQs about Smart Contracts


Q1. How do I create a smart contract in blockchain?

Learn about Blockchain Technology then learn the Solidity programming language, start building your first dApp, then deploy it on the mainnet (Ethereum) or any test networks (Georli, Roopsten, etc.). After deploying you have created your first smart contract in blockchain, woohoo, congrats. One thing is here that since your smart contract is stored inside the blockchain, therefore, if you deployed your smart contract to the mainnet then it is impossible to render that contract because blockchains are immutable and irreversible. But, you can do trial and error as many times as you want with the test network chains like Georli, Ropsten, etc. or with the advanced development environments like Truffle and Ganache, Hardfat, or Foundry.


Q2. What is a smart contract vs blockchain?

Smart contracts are simple codes or rules written in solidity programming language and Blockchains (Ethereum, Binance chain, polygon, etc.) are the decentralized databases where these contracts are stored so that no one can ever render these contracts.


Q3. What is an NFT smart contract?

Smart contracts which deal with minting, listing, buying, selling, collecting, and viewing NFTs are called NFT smart contracts. NFTs are non-fungible tokens, which means these are some digital art, music, photographs, etc. which are up for sale digitally and are unique in the world. The biggest digital art (NFTs) market is Opensea. I will also be posting an article where I will create an NFT marketplace dApp from scratch soon.


Q4. Is Bitcoin a smart contract?

No, Bitcoin is a blockchain and BTC is its cryptocurrency. Also, Bitcoin does not support storing smart contracts on it because the founder (Satoshi Nakamoto) is a ghost. No one in the world can contact him. To run smart contracts on any chain, the chain must support EVM (Ethereum Virtual Machine). Chains like Polygon, Binance chain, and Ethereum support EVM and hence we can store smart contracts on them.


Q5.

  • What is the smart contract platform?
  • What is smart contract language?
  • How do I make a smart contract?

Read the article from the begginning to get all the answers thoroughly.

_____________________--End--_____________________

Writer's Support

  • If you find the article useful show some ❀️ by staring some of my repositories and following me on dev.to and github.

Top comments (3)

Collapse
 
siddharthsing profile image
Siddharth Singh Baghel

Covered all important topics to get started with the smart contracts. Hope readers will enjoy. Happy to read feedback comments.

Collapse
 
icolomina profile image
Nacho Colomina Torregrosa

Great article ! I would like to suggest soroban as a smart contracts platform

Collapse
 
siddharthsing profile image
Siddharth Singh Baghel

Thanks for reading. I will definitely try soroban, thanks for the great suggestion. 😁