What are smart contracts?

Smart contracts are computer programs that live on the blockchain. Like the lines of code that power your favorite apps and websites, smart contracts are the computer code behind many transactions you make on blockchains.

So, when we say that a blockchain or a dapp “does something”––minting an NFT, facilitating a transaction between buyers and sellers, exchanging one token for another, etc.––most often it’s the few lines of code known as a smart contract that actually does the work. 

How smart contracts work

Let’s start with dapps (decentralized applications) as an example. Dapps are just like the apps on your phone or other devices, except they run on a blockchain. The majority of transactions you make, whether you're swapping crypto or buying an NFT, you’ll do via dapps.

Behind the scenes of every dapp is a smart contract that handles the actual work. Once activated and its requirements met, a smart contract will automatically complete its task. Let’s say we have a dapp whose smart contract facilitates transactions between two people: one person selling a digital asset like an NFT, and the other buying that NFT using crypto.

Here's how it goes:

  1. The smart contract operates on an if, then framework. 

  2. If the agreed-upon amount of crypto is given to the smart contract on one side, and if the NFT is given to the smart contract on the other, then the smart contract will move the NFT from the seller's wallet to the buyer's, and the crypto from the buyer's wallet to the seller's.

  3. If one of the requirements doesn't show up, the smart contract will not trigger the exchange.

  4. In that case, both sides are protected, and neither loses their crypto or their assets.

Smart contracts are powerful because they're "trustless." It sounds bad ("No trust?!"), but "trustless" doesn't mean there's no trust; it means they’ve eliminated the need for trust between two parties looking to exchange. Like everything added to the blockchain, a smart contract's code can never be changed or deleted. Smart contracts cannot be interfered with or tampered with by anyone, so you can trust they're going to do what you need them to. 

The smart contract cannot be deceived, nor can it swindle someone. After all, it's just a string of impartial code. If its preconditions are met, it does its thing. If not, it doesn't.

Your future is trustless

The smart contract approach seems simple (and smart), but it's not how traditional finance (TradFi) typically handles transactions. Usually, we give someone funds and then trust they'll hand over the thing we're buying. Most of the time, this works fine. But sometimes it doesn’t, and we have to hire outside help to handle our transactions.

In traditional finance, intermediaries (like real estate agents, mortgage brokers, bankers, and lawyers) can establish a point of assurance between a buyer and seller. We trust these intermediaries (or at least pay them) to be impartial and ensure that everything plays out fairly and honestly, especially for large purchases and negotiations.

This current system works well enough, but since it relies on humans, it’s vulnerable to all the foibles of humanity, including mistakes both honest and malicious. Hiring these intermediaries is costly, not to mention the time and effort it takes for the various parties to communicate and reach an agreement.

To build more “trust” into our systems requires more intermediaries, which means spending more time, effort, and money––unless we use smart contracts.  

Smart contracts replace these intermediaries in the form of code. The difference is they don’t have bad days or ulterior motives. Once deployed to the blockchain, in the case of most smart contracts, no single person or entity controls the smart contract, not even the developer who wrote the code.

This is not to say that all smart contracts are created equal. Because smart contracts are permanent, developers must be meticulous when writing them. They need to check thoroughly for any bugs or loopholes and test exhaustively because fix any issues that arise before it's added to the blockchain. 

The benefits of smart contracts

  1. Always available: Smart contracts are open for business 24/7, 365. There are no 9-5 hours, holidays, or "Back in 5" signs.

  2. Anonymous: Smart contracts don’t need your legal name or any other personal info to do their thing; they just plug onto your public blockchain account address.

  3. Uncensorable: A deployed smart contract cannot be blocked by a government, corporation, or bad actor. For people living under unstable circumstances, they offer a reliable way to move and store assets safely.

  4. Permanent: Every bit of data recorded by a smart contract is added permanently and inalterably to the blockchain. Nobody can go back to forge transactions or fudge records.

  5. Secure: Since a smart contract's data is stored throughout the blockchain, there's no vulnerable central target for hackers to attack. While blockchain hacks have occurred, they’re much more challenging to pull off than cracking a company that keeps its data in just a few servers. 

  6. Iterative: Since most smart contracts’ code is open-sourced, anyone can see what’s happening under the hood and build on top of it to improve or extend its capabilities. Builders can tack on additional smart contracts to existing ones, adding new functionalities or improve existing ones.

  7. Community-minded: Blockchain communities encourage conversation and collaboration to foster an environment where anyone can build new smart contracts and dapps. The companies that run traditional apps want to keep their innovations locked away, out of sight of consumers, competitors, and any oversight. With blockchain, everyone can work openly towards the same bright future. 

Smart contracts may just be short snippets of code, but they’re responsible for many of the most exciting and useful things blockchains can do. They reinvent how we exchange assets between one another, streamlining and simplifying how we build trust into our fundamental systems.

Next Lesson: What are dapps?
Back to 
Learn

AboutLearnBlogSupportCareersPrivacyTermsDapp Developers
DiscordFacebookInstagramTwitterYoutube
© 2023 Valora
Scan to download
Google Play App Store