Before discussing smart contracts, let’s first revise what a contract is, and then we will talk about smart contracts.
Contract
- When two persons or two parties want to carry out a deal or a transaction such as buying property, they need some proof for future reference.
- So, a contract between two or more individuals is a legal document that serves as proof for the transaction.
- All conditions of the transaction are mentioned in the contract and must be fulfilled by the involved parties.
![what is Smart Contracts, blockchain smart contract, Introduction to smart contracts, Writing Smart Contracts, Smart contracts tools, Deploying Smart Contracts](https://images.theengineeringprojects.com/image/main/2021/06/blockchain-smart-contract.png)
Smart Contract
![what is Smart Contracts, blockchain smart contract, Introduction to smart contracts, Writing Smart Contracts, Smart contracts tools, Deploying Smart Contracts](https://images.theengineeringprojects.com/image/main/2021/06/smart-contracts.png)
- In the Ethereum blockchain, a smart contract is actually a program that is deployed on Ethereum.
- The smart contract contains logic and it is written in some high-level language.
- An example of a high-level language is solidity that we will discuss in the upcoming tutorials.
- A smart contract is a set of rules that are coded in the form of a program. These rules govern the transactions between the Ethereum accounts. The transaction could be a transfer of assets, transfer of money, or a change of Ethereum state.
- In Ethereum, the type of account having a smart contract is called “Contract Account”.
- Smart contracts can have balance and can also store data. They contain several functions that can be called by other accounts.
Writing Smart Contracts
![what is Smart Contracts, blockchain smart contract, Introduction to smart contracts, Writing Smart Contracts, Smart contracts tools, Deploying Smart Contracts](https://images.theengineeringprojects.com/image/main/2021/06/how-to-write-smart-contract.png)
Remix
- The remix is an Integrated Development Environment for writing smart contracts.
- It is a browser-based IDE and helps in developing contracts easily.
- The language used is Solidity.
- It helps in the following functions:
- Writing and developing smart contracts
- Deploying contracts on Ethereum networks
- Troubleshooting contracts
- A remix is an open-source tool available freely for everyone. So, if you are not comfortable using the online version, you can simply download it and use its functionality.
- The downloaded version can be used offline on a local computer system.
- The general steps for writing a smart contract using the online tool are given below:
- Open your browser and type https://remix.ethereum.org/ in the address bar.
- The site will show some default contracts. You can use that, study that or you can simply delete that if not needed.
- On the left bar, there would be an option to create a new file. Use that to create your smart contract.
- Write the code for your smart contract in the newly made file.
- The next steps are to compile the contract using a solidity compiler and deploying it on the network.
- After deployment, the functions written in the contract code can be executed.
Solidity
- Solidity is a high-level programming language used for writing smart contracts.
- This language has similarities with C and JavaScript languages.
- Solidity is case-sensitive.
- The extension of a solidity file is .solc and this file contains code.
- You can write and read such a file in any text editor.
- The solidity compiler is used for the compilation of code and named “solc”. The compiler generates the bytecode of the smart contract.
- This bytecode is generated for the Ethereum virtual machine as it cannot understand code in the high-level language.
- You can install solc using npm by typing the following command in the command prompt.
npm install –g solc
Remix and Solidity are the two essential tools for writing smart contracts. In the next part, we will discuss the deployment of contracts.Deploying Smart Contracts
![what is Smart Contracts, blockchain smart contract, Introduction to smart contracts, Writing Smart Contracts, Smart contracts tools, Deploying Smart Contracts](https://images.theengineeringprojects.com/image/main/2021/06/Deploying-Smart-Contracts.png)
- ABI
- Bytecode
ABI
- ABI stands for Application Binary Interface.
- ABI of a smart contract contains a declaration of all public and external functions. It also contains their parameters and returns types.
- ABI is the definition of a contract. Any account that wants to execute a contract function uses its ABI.
- After deployment, the contract instance is created using its application binary interface.
Bytecode
- The bytecode is understandable by Ethereum and helps in deploying the contract on the Ethereum virtual machine.
- Ethereum virtual machine cannot understand solidity so bytecode is a must.
ABI definition and bytecode both are necessary for deployment. The transaction for deploying a contract on EVM takes place and an address is generated for the smart contract. This address is the identifier of the contract. Any function of the contract can be called and executed using the contract address.
So, guys, this was all about smart contracts. We discussed the main idea and some steps to create a smart contract. The two main tools for creating a contract are also discussed in this tutorial. I hope you have learned these concepts and enjoyed reading them. That’s all for today. Take care and have fun.