What is a smart contract? Ethereum Smart contract explained…
New to the blockchain world? A lot of things can sound confusing. I was once there too… You might be thinking of what a smart contract is. Is it like a real-life contract? Well… Let’s see what it is then!
A smart contract is just a digital representation of a real-world contract. (So, you were right. It is like a real-life contract in a digital form). They are the building blocks of decentralized applications, DApps that run on the blockchain. A smart contract is a self-executing contract in which the conditions of the buyer-seller agreement are put directly into lines of code. It allows us to write programs that sore, transfer and do stuff.
Now, let’s say Alice wants to send money from her ethereum account to Bob’s account. For this to work, they both need an account connected to the ethereum network. The accounts will have addresses. If Alice has 10 eths in her account and she sends 5 eths to bob, her balance will be down to 5. If bob had 0 eth before the transaction, his account will go up to 5 eths. Now, blockchain keeps a record of all these transactions in a ledger and it doesn't need any centralized intermediary (middle man) to complete the transaction. It is decentralized. this is a simple transaction.
Now, what if I want to sell you my estate? I would need a place to store the deal to my house and I would need a way for someone to buy it and to transfer it. This is where smart contracts come in. this is what it does. A program that would accept the deal would be written, and it will give room for you to purchase it, then will transfer the deal from the smart contract to you and will release all the funds once it is sold from your account to my account provided there is enough value in your account.
Smart contracts in ethereum are written in solidity which looks a lot like JavaScript is is very different from javascript. Solidity helps us to model ownership, transfer value, and handle advanced transactions that were written in the blockchain. It is a contract-oriented language. It allows us to encapsulate data and behavior in our decentralized applications. They support inheritance and can talk to one another. Now, you can say smart contracts allow us to create an internet of value.
What can smart contracts do and how do they work?
Let’s take a look at crowdfunding…
This is a platform where people try to fund the creation of their products by allowing supporters to pledge funds towards the product. It’s effectively preselling the products. In many cases, there are other rewards besides the product itself. People pledge money and if it’s funded, their funds are paid out to the creators. If the product isn’t funded, the money goes back to the pledgers.
Now, imagine you create a product and you need it to be funded and you decide to presell. You look for investors and people who want to buy your product, and they pledge money to your product by helping you fund it. If it is fully funded, they get the product and other rewards too and you get the funds. If it is not fully funded, they get their funds back. A smart contract can be used for this purpose. Using a smart contract, the fund is paid into the smart contract by the pledgers. The funds are stored there. If the product is funded before the agreed time limit, the money is released to the creator and the product to the pledgers; if not, the fund goes back to the pledgers.
Smart contracts can also be applied in real estate, insurance, the supply chain, digital identity, and other areas.
What do you think about smart contracts? You can add yours in the comment box. Did you learn something new today?
Thanks for reading. It’s nice to meet you :)
Don’t forget to follow me for all your blockchain news and solidity tips….