If you’ve heard much about blockchain, chances are that you’ve heard about smart contracts. But what makes smart contracts, well, smart? In this article, we dive into what smart contracts are, why they’re critical to any Web3 project, and give real-world examples of their applications.
Simply put, a smart contract is a piece of code that runs on a blockchain. Much like any other contract, it establishes and enforces the terms of an agreement. Smart contracts allow developers to codify an agreement in a secure, transparent, and accessible way to anyone. From loans to logistics to insurance, smart contracts are how agreements are enforced on Web3 platforms.
Why are smart contracts important?
To understand why smart contracts are important, let’s take an example of how a traditional contract works. Let’s say that you take out a loan to buy a car. Before you can purchase your new car, the bank or other lender will give you a lengthy legal contract that spells out all the terms and conditions of the loan, including the interest percentage the bank will charge, the amount of time you have to pay back the loan, and what happens if you fail to repay the loan.
Now, let’s say a year later that you realize that the bank has been overcharging your interest on the loan. Sometimes, the bank will rectify the situation and pay you back the amount they overcharged. But what about the case where the bank doesn’t do anything? You’d have to hire a lawyer and bring this claim to court. In court, your lawyer would explain how the bank did not follow the terms of the contract to prove that they charged you more interest than you agreed to.
Does that all sound complicated (and expensive)? Well, that’s because it is.
In Web3 applications, developers write smart contracts to the blockchain so that they are enforceable. These agreements are public and objectively enforced by the network, not a third party like a court or other mediator. By enforcing the agreement in a decentralized manner, both smart contract creators and users of the smart contract can rely on the terms of the agreement without needing to trust each other. Why is this? For the most part, smart contracts cannot be updated after they are written (with some exceptions).
Smart contracts allow developers to build a variety of applications that efficiently replace current systems that require expensive and time-consuming contract enforcement (think finance, legal, and other complex applications).
How do smart contracts work?
The concept of smart contracts dates back to the 1990s when Nick Szabo compared them to the functionality of a vending machine. Let’s say you wanted to purchase a can of soda for one dollar, but you only have a five-dollar bill. When you insert your five-dollar bill, you expect the machine to either give you the soda and four dollars in change or return your five dollars if the soda is sold out.
This may seem like a trivial use case, but this logic is programmed into the vending machine. And whenever we use a vending machine, we trust that this is the behavior that the vending machine will follow.
Now, let’s tie this into how smart contracts work. When using a vending machine, you must trust that it will do what you expect. When using a smart contract, you are guaranteed that the contract you are using will perform exactly as you expect. Smart contracts are publicly verifiable and trustless, meaning the logic of the smart contract can be viewed by anyone, and the blockchain itself is responsible for executing the contract, not the contract creator.
To understand how this works in practice, let’s continue with our vending machine example:
- First, the smart contract developer creates the smart contract and writes it to the blockchain. This contract can be written in a variety of languages. After the contract is deployed, developers cannot (in most cases) update the contract. If they want to make any changes, they’ll need to write a new smart contract to the blockchain. In our example, the vending machine smart contract developer would codify all the vending machine logic and write it to the blockchain.
- Second, each computer (or “node) on the network stores a copy of this smart contract, alongside all other smart contracts and transactions. In our example, this means that the vending machine code is spread across thousands of independent computers, making it impossible for any bad actors to make any updates to the logic.
- Third, a user sends funds to the smart contract and waits for network consensus. Different blockchains have different consensus methods, but all blockchain networks require several independent nodes to verify the transaction before proceeding. This step is an additional level of security and prevents any bad actors from faking a transaction that didn’t happen. In our example, this is when the user inputs their funds to pay for the can of soda into the vending machine.
- Fourth, after the network confirms that the funds were successfully sent, the smart contract is executed by all nodes on the network to determine the outcome and next steps as determined by the contract. By having all nodes run the smart contract, the blockchain is enforcing the terms of the smart contract without requiring a central authority. In our example, every node on the network would confirm that the user paid the correct amount for the soda and, after doing so, would dispense the can of soda to the user. To pay for this contract execution, the user will typically have to pay “gas” — a fee that allows the network to continue operating.
How does Enshrine use smart contracts?
Every token created on the Enshrine platform uses the Enshrine smart contract. This contract is written to the Polygon blockchain and controls what token owners can do with their tokens.
Among other functionality, the Enshrine contract enables:
- Token owners (in all cases) and others (in some cases) can view token details like creator, associated media, title, description, etc
- Token owners can sell or transfer their token to another owner
- If the creator specifies royalties, these royalties are collected whenever the token is sold to a new owner
Do smart contracts benefit creators?
The short answer is: yes. But let’s explore why smart contracts benefit creators (as well as token owners).
Imagine you’re an artist that enjoys painting the dogs that you see when you’re out on a walk. Now let’s say that you want to sell your paintings and ensure that you receive 5% of the sale price every time someone sells your artwork. Without something like a smart contract, you’d have to rely on the honor system and trust that whoever is selling your art sends you a royalty payment. This sounds pretty unlikely, right?
As we discussed earlier in the article, smart contracts are permanent once written and are enforced by network consensus. This means that you can guarantee that any time someone resells your painting, you’ll receive 5% of the proceeds from that sale.
By using smart contracts, creators don’t need to rely on any platform or individual. Regardless of where their tokens are sold or who is reselling them, they can depend on the smart contract logic behaving precisely as they expect it to. As we see it, this gives more power to creators because they can be less reliant on platforms and a new avenue to monetize their content on their terms.