When blockchain was first invented smart contracts didn’t really exist.
Now, smart contracts are a huge compliment to the blockchain.
Smart contracts bring functionality to blockchain and cryptocurrency that might revolutionize many industries.
So, what is a smart contract, how does a smart contract work, what are the advantages and disadvantages, and what can smart contracts be used for?
What is a Smart Contract?
A smart contract is a digital program on the blockchain that automatically takes effect when certain conditions in its code have been met. Developers can use smart contracts to build apps that benefit from the security, privacy, reliability, and decentralization of the blockchain.
A smart contract establishes an agreement between two or more parties, but instead of everyone signing a piece of paper, everything is stored and run on the blockchain
and is signed with your crypto wallet’s secret key.
Like Bitcoin’s goal of being able to send and receive money without a third party, the goal of a smart contract is to allow users to come to an agreement together without a trusted third-party.
With a smart contract they don’t have to trust each other because the code on the blockchain takes care of the trust. Since a smart contract is on the blockchain, everyone can see the code and terms before they agree to anything. The blockchain also makes it so that the smart contract cannot be changed. Everyone knows it will do exactly what the terms say they will.
A smart contract platform
is a blockchain that allows the use of smart contracts.
Ethereum is the main blockchain leading the way in terms of a smart contract platform. It is the second largest cryptocurrency, just behind Bitcoin, and has over 2 million smart contracts on its blockchain. That is the most of any cryptocurrency by far.
The second largest blockchain for smart contracts is Cardano with around 3,000 on its platform. Some other popular smart contract platforms are Avalanche, Algorand, Polkadot, and Solana.
Bitcoin wasn’t built as a smart contract platform, though it can now use them, but it’s actually on another blockchain. Due to the way Bitcoin is coded, smart contracts are not possible on its blockchain. These smart contracts have a few limitations like bad scalability due to the low transaction speed of Bitcoin, simple contracts due to the limits of Bitcoin’s code, and costly fees due to Bitcoin’s high price.
You may have heard of decentralized apps, or dApps, before. These apps are powered by smart contracts and include anything from decentralized finance apps, to metaverse gaming, to decentralized exchanges. The code for these apps is stored on the blockchain.
Some popular dApps that make use smart contracts are UniSwap, a decentralized exchange, SushiSwap, another decentralized exchange, Oasis App, a decentralized finance platform, MetaMask Swap, a cryptocurrency swapping platform, ShibaSwap, or The Sandbox Marketplace, a metaverse gaming marketplace where users can exchange their creations from The Sandbox, a blockchain-based, virtual world.
How Does a Smart Contract Work?
A smart contract is a program inside a transaction in a block on the blockchain. This code is mostly a bunch of “if this, then that” statements that will only be activated when the “if” happens. When the “if” condition has been met and verified, then the rest of the code will activate and be run.
So, how does the code run in the first place?
A developer, who can be anyone, writes a bunch of code for the smart contract that is visible to the public. Users then enter the agreement, and send it to the blockchain just like any normal transaction. The transaction is just a bit different in that this contains the code to run the smart contract. Once the smart contract is validated on a block and added to the blockchain, the code will be executed by the nodes on the network and the contract will be activated.
Since the code of the contract is on the blockchain, it cannot be tampered with, meaning the code for the contract cannot be changed after the fact. No one, not even the developer, can change the terms of a smart contract on the blockchain at any point.
The most basic example is the first real use of a smart contract - the vending machine.
A vending machine is a really simple smart contract that basically releases a snack when two conditions are met. Those conditions are the correct amount of money and a selection. Once a user has deposited enough money and made a selection, the vending machine will automatically execute the code to release a particular snack without the need of any third party. It is a simple agreement between you and the vending machine.
Now for a blockchain related use of a smart contract, we can look at a simple cryptocurrency swap on the decentralized exchange, UniSwap.
Imagine you are looking to trade Ethereum for Cardano. One way of going about this is to use UniSwap. Here, you would deposit your Ethereum into a smart contract, which will automatically find the best exchange rate to Cardano and make the exchange for you. This would save you plenty of time and fees, since the other option would be to use a centralized exchange to sell your Ethereum for fiat and then use those funds to buy Cardano at the rate and with the fees of the exchange.
Smart Contract Advantages
There are many advantages to smart contracts.
Third parties are usually needed during traditional contracts for the added trust factor. With smart contracts, two users, who don’t know each other, can enter an agreement with each other without the trust. That is because they can easily trust the blockchain.
When a smart contract is ready to be executed, all the nodes on the network run the code and come to a consensus about what should happen. These nodes coming to an agreement about terms and execution of the contract is what replaces the need for a third party.
Smart contracts are visible to anyone because they are based on blockchain. That means before anyone agrees to the smart contract, they can easily look over the terms and conditions, and even the code. If they are satisfied with everything they can enter the contract, and know that it will work exactly the way it should.
Security is another big benefit of smart contracts. The blockchain is what makes smart contracts so secure.
Once a smart contract has been validated and added to the blockchain, there is no way to change the code inside because transactions on the blockchain cannot be changed without everyone else on the network knowing about it. Not even the developer of the smart contract can change it after it has reached the blockchain.
In order for anyone to change the smart contract they would have to alter the entire blockchain, a process that would take a monumental amount of energy in order to do.
Both parties can have peace of mind knowing that the terms of the contract will be executed without being tampered with.
Again, because there are no third parties to deal with, the time used to deal with smart contracts is significantly reduced compared to traditional contracts.
With traditional contracts, many different parties may need to be included in executing the terms of a contract. For example, a simple swap of a currency might take two different banks, a middleman between them, and days before you are able to access your new funds.
With a smart contract, these things are taken care of automatically as soon as the terms of the contract are met. Currency goes from someone else’s hands to yours in minutes, or even seconds. They are digital and automated and there is no need for any time-consuming paperwork to be completed.
Lastly, without a third party, there is a major reduction in fees. Now, smart contracts aren’t free either, but they do touch less hands, and therefore usually require less fees.
Anytime you make a transaction on the blockchain there will be a fee associated with it called gas. This happens regardless if you are making a simple transaction such as sending someone an amount of crypto, or making a complex transaction through a smart contract.
For example, on Ethereum the average gas fee per transaction using UniSwap is 0.005 ETH ($8.20), where having a lawyer take care of a contract could be hundreds or thousands of dollars.
Smart Contract Disadvantages
Smart contracts are great for many reasons, but there are a few drawbacks to them as well.
Anyone Can Deploy One
While it sounds awesome to allow anyone to be able to deploy a smart contract, it comes at a cost.
Malicious developers can use smart contracts to steal crypto from other users. What will happen is that a smart contract will be designed to send crypto to the hackers wallet instead of where they claim it will go.
For example, you may sign a smart contract to get a loan by putting up an NFT as collateral. As soon as you sign your NFT over, the smart contract just sends it to the hackers wallet and you get no loan. This is an extremely simple example, but you get the idea.
Just because everyone can see the code of the smart contract, doesn’t mean that everyone looks beforehand. This is equivalent to signing a traditional contract without first reading through it to find out the real terms.
Anyone being able to deploy a smart contract also means that there are many different developers of all types of experience creating them. Your contract could be developed by someone who just started, who may not put as much time and care into making sure that everything will execute properly. It’s possible that in the future there will be professional smart contract developers for hire and you may have to pay them a lot in order to write quality smart contracts, similar to a lawyer writing up contracts nowadays.
Everyone Gets to See the Smart Contract
Speaking of everyone getting to see the smart contract. While this is a major benefit of smart contracts, it is also a major downside.
The reason it is not always a good thing is that everyone
can see the contract. Everyone
, not just the parties involved, but anyone
that wants to look, can.
One problem with everyone getting to see the code on the smart contract is that they could potentially identify and take advantage of a bug in the code. This can lead to major hacks, or hijacking the smart contract and using it for malicious intent. This has already happened many times before and will probably be a common problem as smart contracts become more mainstream.
Since smart contracts can’t really be updated once they are on the blockchain, this can be potentially devastating.
What Can a Smart Contract Be Used For?
Smart contracts are one of the best real world uses for blockchain
. Here are a few more of the many things that smart contracts can help with.
Smart contracts have the chance to revolutionize the financial industry. Banks are outdated. They are slow and costly. Now, decentralized finance can help improve lending, borrowing, investing, trading, and many other financial services.
Right now, decentralized finance apps are one of the most common real-world uses of smart contracts. We already mentioned that smart contracts can be used by decentralized exchanges to quickly and easily swap cryptocurrencies, but there are many other uses as well.
They can be used to send, receive, loan, or borrow money from anywhere in the world regardless of borders. Usually, this requires a massive amount of time and paperwork, if even possible at all.
Smart contracts can be used to loan money to people while holding on to an asset as collateral. The first party will put up their money, and through a smart contract, loan it to another party, who will put up something, let’s say Bitcoin, as collateral. Now, if the second party pays back the loan, the Bitcoin used for collateral will automatically be sent back. However, if the second party fails to pay back the loan, the Bitcoin will automatically be sent to the first party.
In this same way, smart contracts can be used for escrows. An escrow stores a value until an action is taken. For example, someone could pay someone else for a service. One party pays the smart contract for the service, but the funds aren’t released to the second party until the service is completed.
These are just a few examples of the many ways that smart contracts are going to help the financial industry.
Smart contracts are widely used to help distribute NFTs, or non-fungible tokens, which are just a unique transaction on the blockchain used to verify ownership of an asset. These assets can be anything, but in this particular case we are going to look at assets for games.
Introducing blockchain, smart contracts, and NFTs into the gaming industry will change it for the better. Players will actually be in control of their in-game items.
Nowadays, you can purchase an outfit in a game, and while it is technically yours because you purchased it, there are thousands of others just like in the game. With an NFT, this outfit will now completely be owned by you. You can then go ahead and trade, or sell, this outfit with other players of the game. Marketplaces powered by smart contracts will help make these trades without even needing to go through the game.
Since NFTs are on the blockchain, everyone will be able to see if the NFT is real or not. They also benefit from blockchain’s security, meaning there is no way anyone could change the fact that your NFT is yours until you trade it.
In the future, there will be NFTs tied to rare in-game items that will sell for thousands of dollars.
Real estate is another industry that can be revolutionized by blockchain and smart contracts.
Smart contracts can easily handle the entire mortgage process, including the handing over of the deed in the form of a digital token, or an NFT. Simply, once the funds have been sent to the contract, the current owner of the house would provide the tokenized deed to the property, the smart contract will be executed, and the trade will be completed.
All of this can be done without the hidden costs, broker fees, title fees, closing costs, and legal fees. Smart contracts will save the endless hours of slow moving paperwork that you normally have to go through when buying a property.
Smart contracts can also allow for a property to be owned by many different people. A token can easily be broken up and purchased by different individuals who do not even need to know each other.
Partial real estate owners can then automatically split rental profits between them using the smart contract, can sell the share of the home at any time, and if their property is purchased outright they will receive their share of the funds without needing to worry about how to split it amongst the others.
A smart contract is code on the blockchain that automatically runs itself when certain conditions are met. These can be anything from simple currency swaps to complex financial deals. Blockchains like Ethereum and Cardano are major players when it comes to smart contracts.
A smart contract works by being sent to the blockchain. Once the transaction that holds the smart contract is validated by the network and added to the blockchain, the code is executed, the contract does its thing, and is completed.
Advantages of smart contracts include increased speed and less fees due to cutting out a middleman, more security since it's on the blockchain, and you don’t need to trust the other party in the contract.
Disadvantages of smart contracts are anyone getting to deploy a smart contract means that even malicious actors and hackers can take advantage of them. They can be used to hack unsuspecting crypto users. Another disadvantage is that everyone can see the code of the smart contract, not just the parties involved, which means that someone could take advantage of a potential bug in the code.
There are many real world use cases for smart contracts, and they will help revolutionize many industries. These include financial, gaming, real estate, and many more.
Now that you know what a smart contract in blockchain is, you can learn more about another topic, blockchain layers