Blockchain Basics

Smart contracts

This is Smart contracts

Beginner Level30 minutesBy Pratima Sharma
Smart contracts

What is a Smart Contract?

A Smart Contract is a self-executing piece of code stored on a blockchain. It automatically enforces rules, conditions, and agreements between parties without requiring a middleman.

Think of it as a digital agreement written in code instead of paper. Once deployed, no one can alter it, making it transparent, secure, and tamper-proof.

Key Features of Smart Contracts

  • Automation – Executes actions automatically when predefined conditions are met.
  • Transparency – All rules and code are visible on the blockchain.
  • Immutability – Once deployed, contracts cannot be changed.
  • Trustless Execution – No central authority or third party is required.
  • Security – Uses cryptographic principles to ensure authenticity.

How Smart Contracts Work

  1. A developer writes the contract code (usually in a blockchain-supported language like Solidity for Ethereum).
  2. The contract is deployed on the blockchain.
  3. Users interact with the contract by sending transactions.
  4. When conditions are satisfied, the contract executes automatically.

Example (Real-life analogy):

Imagine a vending machine:

  • You insert money (input).
  • The machine checks the amount (verification).
  • If correct, it releases a soda (output).
  • No shopkeeper is needed.

Smart contracts work the same way—code replaces intermediaries.

Example in Solidity (Ethereum Smart Contract)


// Simple Smart Contract to store and retrieve a number
pragma solidity ^0.8.0;

contract SimpleStorage {
    uint256 private storedNumber;

    // Store a number
    function setNumber(uint256 _num) public {
        storedNumber = _num;
    }

    // Retrieve the stored number
    function getNumber() public view returns (uint256) {
        return storedNumber;
    }
}

  

Explanation:

  • setNumber() allows users to store a value on the blockchain.
  • getNumber() retrieves the stored value.
  • The data is permanent and visible to anyone on the blockchain.

Popular Platforms Supporting Smart Contracts

  • Ethereum – The pioneer of smart contracts (Solidity language).
  • BNB Chain – EVM-compatible, faster and cheaper.
  • Polkadot – Focused on interoperability.
  • Solana – High throughput smart contracts in Rust.
  • Cardano – Uses Plutus (based on Haskell).

Use Cases of Smart Contracts

  • Decentralized Finance (DeFi): Lending, borrowing, and exchanges without banks.
  • Supply Chain: Tracking goods from origin to destination.
  • NFTs: Minting and transferring ownership of digital assets.
  • Voting Systems: Secure, transparent elections.
  • Insurance: Automatic claim settlements when conditions are met.

Advantages

  • Faster transactions
  • Reduced cost (no middlemen)
  • High security & transparency
  • Global accessibility

Challenges

  • Code bugs may cause financial loss
  • Difficult to update once deployed
  • Legal recognition varies across countries

Test Your Knowledge

Practice what you've learned with these quizzes related to What is Blockchain?.

Continue Learning

Explore more topics in What is Blockchain? or browse other tutorials.