What Is Smart Contract
A brief overview of smart contracts in simple words
- A smart contract is simply a special program that runs on top of the blockchain(s) like Ethereum.
- Technically, it is a program that is stored at a specific blockchain address, a.k.a. contract address.
- These programs are often referred to as programmable agreements, i. e. smart contracts.
- In smart contracts, all information is written directly in code and published into a blockchain.
- All contract data is safely encrypted before it is deployed (published) to the blockchain.
- Once it is deployed, no authority or person can secretly change contract data as all operations are recorded.
- These actions may include transferring (sending into) and releasing money from the contract, etc.
- As with all transactions, the actions are approved by nodes and have gas fees (see What is Network).
- Once a contract is published to the blockchain, all its transactions can be verified (see What is Explorer).
Smart contracts are specific types of programs that store information and funds (in the form of tokens) inside a blockchain.
A blockchain is a distributed database of records that keeps track of all its operations (transactions).
Ethereum explains smart contracts as accounts that live on the blockchain, and cannot be deleted by default.
Because of their ability to respond to certain actions exactly as programmed, they are often compared to vending machines.
A vending machine is programmed to discharge a snack after a user selects it and pays for it. Snack selection and payment are the conditions that must be satisfied to get the results. Thus, the machine will not discharge anything until both conditions are met.
Like vending machines, smart contracts can often replace intermediaries and cut unnecessary costs.
Specific conditions in smart contracts are predefined and written into code. Such conditions may include the kind of operation as well as the time when it is performed.
For example, the amount and the date when the payment is due.
Because of this, smart contracts are often referred to as programmable agreements. These agreements can be used in peer-to-peer deals between a buyer and seller, for example. You can learn more about how smart contracts are used here.
Since smart contracts are blockchain programs, they inherit blockchain qualities such as:
- transaction transparency,
- the anonymity of users,
- no central authority,
- secure encryption of data
Thus, compared to traditional paper-based contracts, smart contracts are faster, more secure, and fairer alternatives.
The contract terms are written into code and then deployed (published to the blockchain. Once published, each node of the network will have a copy of this code. This makes it impossible to change the rules defined by the contract without the nodes' approval.
A node is an independent computer that performs blockchain operations to get a reward. Besides storing data and smart contracts, nodes also process (approve) all blockchain transactions.
As such, all blockchain operations with contracts have timestamps and unique transaction IDs. The operations, also known as contract actions, are specific requests to nodes (contract calls) to execute a function defined in the contract code. As a blockchain operation, contract action has a gas fee.
A gas fee is a blockchain fee that is paid to nodes approving a user transaction (miners/validators). Gas fees vary depending on the type of network and the level of difficulty of a blockchain transaction.
Contract actions may include transferring (sending into) and releasing money from the contract. This way, smart contracts act as decentralized escrow. The funds (money) are only released when specific conditions are met.
Unlike a traditional escrow which involves a person or company, a contract stores the money inside a blockchain. Put simply, no single authority has access to the contract funds (unless defined by its rules).
As with regular blockchain accounts, a smart contract has its own address in the database, a.k.a a contract address. This address is given to a specific contract when it is deployed (published) to the blockchain. It is often used to get information on all the transactions within a particular contract, its status, and/or value and gas fees.
The tool that allows seeing the contract data is called a blockchain explorer. It is a specific search engine that finds and displays a specific piece of information from the blockchain records.
- More on smart contract use cases https://docs.zen.land/smart-contract-types/default-escrow-contract