What is a smart contract on Cardano?
In previous article, we described how each transaction destroys some UTXOs and creates some new UTXOs. If you don’t understand this concept, reading our previous article might be a good idea before continuing.
Before a transaction can be added to the blockchain, it needs to be validated. This is to prevent anyone spending your UTXOs without your consent. Therefore, there is your name written in the UTXO besides the value that this UTXO holds. When a transaction wants to spend your UTXO, it first checks, whether you signed that transaction. If you signed a transaction, it means that you agree with it.
The transaction can only be added to the chain, if all input UTXOs agree with being spent in that transaction. Therefore, if there are inputs from 3 different people, this transaction has to be signed by all of these 3 people in order to pass validation. The name that is written inside a UTXO is like a guard of that UTXO. It defends that UTXO from being spent in transactions that are not signed by the owner of that UTXO.
Now, let’s get to the main topic. What is a smart contract in UTXO model? Imagine that you could make the guard stronger. Instead of just a name tag, it would be code. When a UTXO guarded by this code is being spent in a transaction, this code runs and decides whether it allows or denies spending the guarded UTXO in this transaction.
The only thing this code sees is the transaction itself. If the UTXO guarded by such code is being spent in a transaction, the guarding code gets the description of this transaction and decides whether the UTXO can or can’t be spent in it. For example, the code can say something like: “I allow spending my guarded UTXO in any transaction that has at least 6 inputs”. A code guarding a UTXO with NFT listed for sale for 20 ADA can say something like: “I allow spending my guarded UTXO in any transaction, that pays 20 ADA to the seller”. This is how NFT marketplaces work. Let’s not be worried about where the information about seller and 20 ADA are stored, we’ll look at that in the future.
This guarding code is called a smart contract. It’s just that. A code that allows or denies spending a UTXO that it is guarding. Nothing more. Simple as 1, 2, 3!
Wait, but what is a smart contract address? This term is used a lot. Well, we don’t want this article to be too long, so we will explain that in a future one together with even more details about UTXOs and addresses. Stay tuned!
If you have any questions, don’t hesitate to ask us! We’re on a mission to educate people on the tech through a CNFT collection. We appreciate all likes, follows and retweets as they can help us a lot in spreading information. Thank you!