How does each transaction verifying node come to know if the sender has enough amount in its wallet to transfer to the receiver or not? How are Blockchain transactions validated?
2 Answers
Each node stores the entire history of transactions (the blockchain). When a node hears about a new transaction, it performs a series of checks to make sure that transaction is valid.
So, when someone sends a tx, their software will use the private key of an unspent output (a 'bitcoin') to cryptographically sign the transaction. This signature proves ownership of the unspent output, and authorizes movement of the coins.
So when a node hears about a new transaction, it checks to make sure that the signature is valid. If the signature is not valid, it will ignore the transaction.
If you attempt to spend more coins than you own, then the signature will not be valid according to the blockchain record kept by the nodes. It is not possible to forge authenticity, you either own the coins and can create a valid transaction, or not.
Note that 'transaction validation' in this case just happens on each node, as the tx is relayed through the network. This is different than 'transaction confirmation', which happens when miners include a transaction in the next block. After 'validation', txs are stored in each nodes memory pool (mempool), until they are confirmed in a block.
-
1"If you attempt to spend more coins than you own, then the signature will not be valid according to the blockchain record kept by the nodes." - How does this part work exactly? This may sound naive, but does it just subtract the bitcoin transaction amount from the balance and see if its greater than or equal to 0? What is being signed here? Commented May 12, 2018 at 5:42
-
@Strawberry Bitcoin uses an 'unspent transaction output' (UTXO) system, not an account system. So there is no 'subtracting an amount from a balance' happening under the hood. Rather, a wallet will select a UTXO it controls, and use it as an input for a new transaction (and cryptographically sign the transaction to prove ownership of the UTXO). All other full nodes keep a record of all current UTXOs, so they will reject your tx if it breaks consensus rules. Trying to spend 2BTC from a 1BTC UTXO would be rejected, since such a transaction would be essentially minting new bitcoins out of thin air– chytrikCommented Sep 3, 2018 at 23:35
Here is a guide on how miners verify transaction on the blockchain. Simple and easy 5 min read, takes you through the proces in 7 steps.
-
1Please add some details, link-only answers are not well-received here, or delete the answer and add it below the question as a comment.– MCCCSCommented May 5, 2018 at 9:17
-
I don't think this link points to a page that shows you how a transaction is verified - it shows you how a block in confirmed i.e. block hashing. Transaction confirmation involves checking the digital signature of a UTXO (unspent transaction output) - which is a different action. Commented Dec 21, 2021 at 9:13