What are Smart Contracts in Crypto? (4 Examples + Animated Video)

whiteboard crypto logo
Published by:
Whiteboard Crypto
on

Have you ever wondered how the blockchain works? Like, what code does it run on? Some blockchains only allow the basic code for them to work, like Bitcoin. It can’t be changed, and it only allows simple transactions to occur.

But some blockchains, like Ethereum, are meant to run code on top of the blockchain that allows you to do more than just send transactions. This code is called smart contracts.

A smart contract is a pre-arranged agreement written in code so that certain events, such as sending coins or paying interest, will happen when the code is triggered. Smart Contracts are the foundation for Decentralized Finance and allow the creation of many new opportunities on the blockchain.

What is a Smart Contract?

Smart Contract

A smart contract is exactly like this. It’s a piece of code that does something if something else happens. Some people like to call it a “If this, then that”:

  • If you give me 5 ETH, I’ll give you 20 Basic Attention Token (BAT)
  • If you have at least 100,000 subscribers by the end of the year, 20 ETH will be added to your account
  • If the temp is over 95 degrees for more than 4 days in a row this year, Farmer John’s account will receive $100,000 as crop insurance

It would be really easy to write a smart contract where people could donate ether to a certain address. If that address reached a certain point, say 500 ETH, 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 join a community. 

When it comes to smart contracts, there are 2 main things that make them beneficial to everyone: they are immutable and distributed.

Smart Contracts are Immutable

This means they cannot change. Remember how I said some people call them “If this, then thats”? It’s because most smart contracts do something when they are triggered. 

They are code that is on the blockchain, and once it’s on there it can never be changed. The downside of this is that if there is a bug, it will be a bug forever. 

However, you can just create a new smart contract and tell people not to use the old one. 

Smart Contracts are Distributed

This means there’s no discrepancies. You can’t hire a lawyer and be like “that wasn’t our agreement!”

These smart contracts are an agreement between a few parties online that can be automatically executed if certain conditions are met. A piece of code, designed to remove human error and issues.

In fact, you couldn’t hire a lawyer if you wanted to—the code is on a bunch of computers all around the world. In fact, ANYONE can see your smart contract. Now we have financial agreements that nobody can argue. 

4 Examples of Smart Contracts

Now that we know what a smart contract is, let’s go over some examples of smart contracts.

1) Flash Loans

What if I told you that you could borrow 10 million dollars with no money down?

Well, on the Ethereum network you absolutely can. Only if you write a smart contract that pays it back in the same minute that it is borrowed. This is called a “flash loan“.

That’s right, you can borrow millions of dollars to do something for you on the Ethereum network if you know how to code it. Here’s the catch—all of the money must be paid back.

Flash Loans

Why would we want to do this?

Imagine if you could buy some Dogecoin for 50 cents on Coinbase and sell it for 55 cents on Gemini.

You could theoretically borrow 10 million dollars and buy a bunch of dogecoin on Coinbase, then sell it to Gemini, 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 with one that did pretty much the example I just described. The smart contract can check itself, run a simulation of what you programmed and see if what you tell it to do will be able to actually pay back the lender. If it can, it does it. 

2) Insurance Using Oracles

Did you know you can create an entire insurance company with a few smart contracts? We just write something simple like this: “If Farmer John gives us $2000 AND if it is more than 95 degrees for 4 days in a row in Missouri, pay farmer John $100,000.”

This is basically insurance. Farmer John can be sure that if his crops die from a heat wave, the smart contract will know it happened due to the temperature change and pay him out his insurance.

You might be asking, “How the heck does a smart contract know what the temperature in Missouri is?” Well, with the help of something called oracles. 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.

You also might be asking, “Where does the 100,000 come from”?

Well, investors who start the insurance company must pool their money together to be able to front that money—in fact they have to lock it up in the smart contract where Farmer John buys it.

They can’t do anything with it until the end of the summer—the smart contract owns the money. Insurance could be a very profitable use of smart contracts.

3) Token Switching

When it comes to smart contracts, one of the most useful things you can do is create a pool of money with two tokens. You write the smart contract to allow traders to switch out one token for another token.

As one increases in volume, you increase the price of the other token—this way we keep steady value in the pool. This is roughly how a decentralized exchange works, and if you’re curious what that is, check out our recent video on Uniswap—it explains it beautifully.

You can write a smart contract that says if you give me 20 apples, I’ll give you 30 coconuts, except the apples and coconuts are ETH and BAT, an Ethereum based token.

Token switching opens up a whole new world for day traders or investors that want to get into a specific coin that isn’t on a major exchange like Coinbase. 

4) Buying a house using an NFT

The last example I want to share is buying a house. So, if you haven’t already, you should watch our video on NFTs, because you need to understand them and their purpose to get this example.

Imagine if you took the house or apartment you are living in and put the deed on the blockchain. It’s not owned by a bank anymore, or by you… 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 weeks of the usual process—advertising, securing the funding, using escrow, getting insurance, and closing—you could just send an offer right on the blockchain and within minutes the other person could accept or deny.

If they accept, immediately you own the new deed, but the other person now has your payment. This would be very useful for anyone wanting to get into the real estate market but are stopped by high fees or even banks who want a higher profit margin on their mortgages. 

Conclusion

As we end this article, we hope that you’ve learned something valuable from it and if you have, consider leaving a like to reward our hard work and subscribing to see more awesome cryptocurrency and decentralized finance explainer articles like this.

Thanks so much for reading, and we hope to see you in the next article!

whiteboard crypto logo

WhiteboardCrypto is the #1 online resource for crypto education that explains topics of the cryptocurrency world using analogies, stories, and examples so that anyone can easily understand them. Growing to over 870,000 Youtube subscribers, the content has been shared around the world, played in public conferences and universities, and even in Congress.