The term "programmable money" is sometimes used to describe Bitcoin. It gives users a great deal of flexibility when it comes to establishing rules for how money can be spent because of the digital nature of the system.
When discussing Bitcoin, we use the terms wallets and coins. However, we might alternatively consider coins as checks, wallets as safes, and the blockchain as a long row of closed safes. Every safe has a little opening so that anyone can place checks inside or peek inside to see how much money is inside. But only the owner of the key will have access to the inside.
A key holder must unlock their box in order to give money to someone else. They draft a fresh check with a reference to the previous one, trash it, and then lock it in a box that the receiver may access. The new recipient goes through the same process to spend that.
This article will examine Script, the programming language used by nodes on the Bitcoin network, in more detail. The described locking/unlocking mechanism for the safes is controlled by script.
Continuing with our previous analogy, you could argue that every transaction consists of two components: a lock and a key (used to open your box). You insert a new key into a new box with a different lock after using your key to open the box containing the desired cheque. You require a new key in order to spend from the new box.
Easy enough. A little variety in the system's lock types is also available. Some safes might demand numerous keys, while others would want you to demonstrate that you know a certain secret. There are numerous restrictions that can be put in place.
We refer to our key as a scriptSig. Our scriptPubKey serves as the lock. A closer examination reveals that such components are actually made up of code blocks and data fragments. They come together to form a small program.
This combination is broadcast to the network when you do a transaction. Each node that receives it will run the program, which notifies it if the transaction is genuine or not, and then check it. If not, it will simply be trashed and the locked cash won't be available for use.
Unspent transaction outputs (UTXOs) are the cheques (coins) that you now possess. Anyone who can supply the key that fits the lock can use the money. The lock is the scriptPubKey, and the key is the scriptSig.
Only the individual who can demonstrate possession of this public key will be able to unlock these funds, if the UTXOs are in your wallet. Using the private key that corresponds to the public key stated in the scriptPubKey, you must give a scriptSig that is digitally signed in order to unlock it. Everything will soon become evident.