What is a smart contract in blockchain?

A smart contract is a self-executing contract with the terms of the agreement directly written into code. They exist across a distributed, decentralized blockchain network, ensuring they cannot be altered and are executed exactly as agreed upon.