Consensus mechanisms ensure that different nodes in the network reach an agreement on the validity of transactions. For example, consensus mechanisms such as Proof of Work (PoW) and Proof of Stake (PoS) require nodes to complete certain tasks or meet specific conditions in order to confirm transactions. Only transactions that have been verified and confirmed by a majority of nodes can be added to the blockchain, ensuring the legality and consistency of transactions, preventing fraudulent transactions or double-spending issues, and enhancing the transparency and credibility of transactions.