Ethereum is an open-source decentralized blockchain. However, it is not a typical blockchain but it is the first blockchain with a Turing complete language called Solidity. Solidity allows developers to build applications that can run on the Ethereum blockchain.

Developers build applications with the help of smart contracts. Now comes the question, what are smart contracts?

What are Smart Contracts?

Smart contracts are programs (a set of instructions, basically code) stored on the blockchain( a public database) and cannot be modified.

smart contracts

Every interaction(mostly write operations) with the smart contract happens in the form of a transaction much similar to the transaction of sending crypto from one user account to another but here the user will interact with the smart contract and can do a lot of things than just being able to send money like store any information, fetch information, compute something, send money to contract and withdraw money from the contract.

But here the catch is, the transactions(interactions) with the smart contract gets executed automatically when the required conditions are met if you want to store your name on the blockchain, you should only interact with the smart contract that stores your name

The smart contracts also enable you to create your NFTs. At the end of the day, a smart contract is just code written to do some specific task.

Satoshi introduced a way to do transactions safely without any third party with the decentralized blockchain technology.

Smart contracts are built on top of the blockchain. Smart contracts let us build more applications that would remove the third party involvement and reduce middlemen and fees making it fair and trustless.

How do Smart Contracts work?

  1. Decide what you want to achieve through a smart contract?
    • Assuming, all the information of who owns which property in the beautiful land of Wakanda is already stored on the blockchain. I want to make a smart contract where users can transfer ownership of the properties they own without the need of a middleman and thus save fees. So, we need to build a marketplace where users can list their properties with price, when they receive the amount, the ownership should be transferred.
  2. Convert these requirements into code and deploy on the blockchain.
    • A solidity developer will leverage the smart contract where the ownership details are stored and create a new smart contract where the user who owns a property can list a property with the price information.
    • This same contract will display the properties listed.
    • The contract also includes an option to transfer the required ETH to the smart contract, then it transfers the ownership of property selected to the new user who pays the required ETH.

Now the contract is deployed on the blockchain meaning it is stored on the blockchain. It will have an address and it will generate an ABI(Application Binary Interface) which contains the details about methods inside the smart contract. This will help in creating a dedicated frontend to interact with this smart contract.

Smart Contracts Examples

For example, Pranay has listed his property for 300 ETH. Now all the users can see this information.

Vinay, another user sees this property and invokes a method, and pays 300 ETH by interacting with the deployed smart contract in the form of a transaction. The contract checks if Vinay has 300 ETH to pay and the property Vinay is willing to buy is available or not. Then it transfers 300 ETH to Pranay and ownership to Vinay, if all requirements mentioned in the smart contract are met.

The same happens with NFTs and other applications.

Writes to smart contract always changes the state of the blockchain, so they happen in the form of transaction, and users interacting with the smart contract need to pay the gas fee for the miners to validate this transaction and add it to the blockchain, so the desired state will be achieved.

If the state concept is confusing, I will simply further. 

Let us assume, the Ethereum blockchain has only two users. One user, Pranay has an NFT and another user Vinay has 5 ETH. Let us say this as state S1

Now Pranay listed his NFT for sale on Opensea, an NFT marketplace for some price say 2 ETH, giving them permission to transfer this NFT from his account, if he receives 2 ETH in exchange. This is the state S2 where Opensea, which doesn’t have permission to sell Pranay’s NFT before, has permission now. 

Now, Vinay buys this NFT by paying 2 ETH to Pranay. Now, the state changed to S3, now Pranay has 2 ETH and Vinay has 3 ETH and an NFT.

Read calls are free. There is no need to pay to read information from the blockchain. Now, Vinay can view the NFT he got without paying any fee on Open Sea. The Open Sea will query the Token URI method of that NFT Smart contract to fetch the NFT metadata of the NFT he bought.

Post a Comment

Previous Post Next Post