What Is a Smart Contract?

Have you ever heard of Kickstarter? it's where when you have an idea but you don't have the money. you make a page and show off your idea in hopes that other people donate to your project.
For Example,
A Smart Contract is exactly like this, It's a piece of code that does something. If something else happens. A lot of people call it if this then that . The most common smart contracts are written on the Ethereum network using something called Solidity.
PURPOSE OF SMART CONTRACTS
So let's go over some Examples of the purposes of Smart Contracts. You could write a piece of code that says if you give me 5 Ethereum in turn I will give you 20 basic attention tokens. If you have at least 100,000 Followers by the end of the year then 20 Ethereum will be added to your account and If the BNB is over $10000 for more than four days in a row this year then you will receive $5000.
Now it would be really easy to write a Smart Contract where people could donate Ethereum to a certain address and then if that contract address reached a certain point maybe say 500 Ethereum then we could give each donor a portion of an online work such as an artistic NFT or access to read an online book or even join a community.
The purposes of Smart Contracts are endless. But when it comes to Smart Contracts, there are two main things that you need to know what makes them beneficial to everyone.
1) They are immutable which means they cannot change. So you remember how I said some people call them if this then that? It's because most smart contracts do something when they get triggered. they are code on the blockchain that gets run and once it's on the blockchain it can never be changed.
Now the downside of this you might be thinking is that if there is a bug or the code is inefficient it will be a bug and inefficient forever.
However, if you want you could create a new smart contract and tell people not to use the old one. In fact, this happens very often.
2) Smart Contracts are distributed this means there are no discrepancies. You can't hire a lawyer and be like that wasn't our agreement. These Smart Contracts are agreements between a few parties online that can be automatically executed if certain conditions are met.
Smart Contracts are a piece of code designed to remove human error and issues. In fact you couldn't hire a lawyer even if you wanted to. The code is on a bunch of computers around the world, In fact, anyone if they wanted to could see your Smart Contract and how you participated in it.
So now we have financial agreements that nobody can argue because they are code, they don't change and everybody has access to them. Now you might not understand what the power of technology like this is but to help you get the hang of it.
Let's go over some examples,
1) Flash loan - what if I told you that you could borrow 10 million dollars with no money down? well on the Ethereum network, you absolutely can!! but only if you write a Smart Contract that pays it back in the exact same minute that it is borrowed. That's right you can borrow millions of dollars to do something for yourself on the Ethereum network if you know how to code it. So here's the catch all of the money must be paid back. So you may be wondering why would we want to do this. Well, imagine you could buy some Dogecoin for 50 cents on Coinbase and then sell it for 55 cents on Binance.
You could theoretically borrow 10 million dollars and buy a whole bunch of dogecoin on Coinbase and then sell it to Binance and then pay back the original loan of 10 million dollars with some interest. This is called a Flash Loan and some guy made 360 000 in a few minutes by creating one of these. That was pretty much the example that I just described.
Here's the kicker, the Smart Contract can check itself. It can simulate what you programmed and it can see if what you told it to do, would actually be able to pay back the lender after it does the code and if it can do that if it can immediately pay back the lender. It runs the code and you can borrow those funds to do whatever you want to do.
You could never do this with traditional finance but you can on the blockchain.
2) Insurance- Do you know you can create an entire insurance company with just a few Smart Contracts? We would just write something simple like this if the farmer John gives us two thousand dollars and if it is more than 95 degrees for four days in a row in Missouri, Pay farmer John ten thousand dollars so this is basically Insurance. Farmer John can be sure that if his crops die from a heat wave the Smart Contract will know that it happened due to temperature changes and pay him out his 100 000 Insurance.
Now you might be asking how the heck does a Smart Contract, A Piece of code know what the temperature in Missouri is?
Well with the help of something called Oracles. So Oracles are helpful tools to any Smart Contract, essentially they are a trusted source that gives real-world information to anything on the blockchain that requests it. Now Oracles can get confusing so we'll leave those for another article. you just need to know they send real-world data to a Smart Contract.
Now another question you might be wondering is- where does the initial one hundred thousand dollars come from? Well, you'd have to imagine that investors who wanted to start that Insurance Company, would have to pool their money together to be able to front it. In fact they would have to lock it up in that Smart Contract whenever Farmer John buys it they cannot do anything with those funds until the end of the summer because at that moment the Smart Contract owns that money then at the end of the summer. If the Insurance has not been paid out to Farmer John, the initial investment of one hundred thousand dollars plus Farmer John's two thousand dollar premium gets paid back to the investors. Now Insurance could be and probably is going to be very profitable.
3) Token Switching- When it comes to Smart Contracts one of the most useful things that you can do is create a pool of money with two different tokens. You write Smart Contracts to allow traders to switch out one token for another token and as one increases in volume, you increase the price of the other token. This way you keep steady value in the pool. This is roughly how a decentralized exchange works and if you're curious about what that is you can check out our recent article on something called Uniswap that article explains it beautifully you can write a Smart Contract that says if you give me 20 apples and I'll give you 30 coconuts. Except the apples and coconuts are Ethereum and Basic attention token so a Smart Contract can allow you to switch tokens.
Token switching opens up a whole new world for day traders or investors who want to get into a specific coin that isn't currently on a major exchange like Binance. Instead, they could buy an available coin and then use the decentralized exchange to swap those tokens.
4) Buy a House- Imagine you took the house or the apartment that you're living in and you took the deed and you put it on the blockchain. it's not owned by you anymore or the bank in fact it's owned by whoever has the deed on the blockchain.
There might be a day when we can use a Smart Contract to buy and sell a house instead of going through the usual process that takes weeks. You know advertising the house securing the funding using escrow to get insurance and the dreaded closing. You could just send an offer right on the blockchain and within minutes the other person can accept or deny. If they accept, you immediately own the new deed but the other person immediately has your payment now this would be very useful for anyone wanting to get into the real estate market but is stopped by the high fees or even banks who want to have a higher the profit margin on their mortgages
Imagine if you could buy and sell a house as quickly and easily as you can buy and sell a stock with blockchain that would be possible.

5) Elections- Electoral fraud is a real risk in some countries and has been used as a political weapon to destabilize others. Smart contracts make it possible to validate a voter's identity and reliably record their vote
6) Health- In addition to the recording of health data mentioned above, its application in this sector can range from the traceability of medicines to the management of the cold chain, the health passport, or clinical research.
7) Human ResourcesHuman Resources- The use of smart contracts that record a person's academic qualifications, certificates, and experience can prevent fraud in CVs and therefore facilitate the recruitment of individuals, also companies, providing a service.
8) Intellectual property- Many companies are dragged into years of court disputes over the use of patents in project development. Smart contracts can keep track of which part belongs to which company.
9) Supply chains- Internet of Things devices can be used throughout the supply chain to record every step of a product and improve its traceability. In this way, errors, theft, and loss can be eliminated.
HOW DOES A SMART CONTRACT WORK
The operation of a smart contract is similar to other blockchain transfers. These are the necessary steps:
1. A user initiates a transaction from their blockchain wallet.
2. The transaction arrives at the distributed database, where the identity is confirmed.
3. The transaction, which may be a transfer of funds, is approved.
4. The transaction includes the code that defines what type of transaction is to be executed.
5. The transactions are added as a block within the blockchain.
6. Any change in contract status follows the same process to be updated.