Web3 - What is a Gas price, Smart Contracts?
We will look into the flow of Etherum Smart Contract and also understand some developer terms
👋 Hi, this is Venkat and here with a free, full issue of the The ZenMode Engineer Newsletter. In every issue, I cover topics in a simpler terms in areas related to system design, Artificial Intelligence, Small projects.
If you are new here feel free to read the older article here.
What is a Gas Price on blockchain in a simpler terms?
Okay, imagine you want to send a letter to your friend, but you need to pay a small fee for the mailman to deliver it. The gas price is like that fee you need to pay for the mailman to deliver your letter.Similarly, when people want to make a transaction on a blockchain, they need to pay a small fee to the network to get their transaction processed. This fee is called the gas price. It's like a little payment you have to make to the blockchain so that it will process your transaction and put it in the blockchain.
Just like how you need to pay the mailman to deliver your letter, you need to pay the gas price to the blockchain to process your transaction. The higher the gas price, the faster your transaction will be processed.
What is a Smart Contract on a blockchain?
Okay, imagine you have a toy vending machine. You put in a coin, and the machine gives you a toy. A smart contract is like a vending machine, but instead of giving you a toy, it does something else.
A smart contract is a computer program that runs on a blockchain. It's like a set of instructions that tell the blockchain what to do when certain things happen. For example, let's say you and your friend want to bet on the outcome of a race. You could create a smart contract that says if your friend wins the race, the smart contract will automatically give them a prize, but if you win the race, the smart contract will automatically give you the prize.
The smart contract is like a little computer that sits on the blockchain and waits for the race to finish. When the race is over, it checks who won and then automatically gives the prize to the winner, without needing any people to get involved or to trust each other. This is because the smart contract is programmed to do exactly what it's supposed to do, without any possibility for anyone to cheat.
So a smart contract is like a vending machine that does something automatically, but instead of giving you a toy, it does something else, like giving a prize to the winner of a race.
Lets understand the flow of a Smart Contract in Ethereum BlockChain
Agreement: Two parties agree to a set of terms, such as exchanging funds for goods or services. They decide to use a smart contract to ensure the terms are executed automatically and transparently.
Solidity Code: A developer writes the smart contract in a programming language called Solidity. The code specifies the terms of the agreement and the conditions under which the contract will execute. For example, if a certain amount of cryptocurrency is sent to the contract address, the contract will automatically release the goods or services.
Bytecode: The Solidity code is compiled into bytecode, a machine-readable format that the Ethereum Virtual Machine (EVM) can understand.
EVM: The bytecode is sent to the EVM, a decentralized computer that runs on the Ethereum network. The EVM executes the contract code and enforces the rules specified in the smart contract.
Miners to Block: The EVM sends the contract execution to the Ethereum network, where it is broadcast to all nodes. Miners then group transactions together into blocks and compete to solve a cryptographic puzzle to add the block to the blockchain.
Contract Execution and Payment: Once the block is added to the blockchain, the smart contract is executed and the terms of the agreement are automatically carried out. For example, if a certain amount of cryptocurrency was sent to the contract, it will be transferred to the appropriate party. The transaction fees paid by the parties are used to incentivize miners to process the transaction and add it to the blockchain.
Overall, a smart contract on Ethereum is a self-executing agreement between parties that is enforced by the blockchain. The terms of the agreement are encoded in code, which is then executed on the Ethereum Virtual Machine, with the help of miners who process the transaction and add it to the blockchain.