Blockchain Basics & Development Setup

What Exactly is Blockchain?

A blockchain is essentially a decentralized database. Unlike traditional databases (like PostgreSQL) that are managed by a central server, blockchain data is maintained collectively by thousands of computers worldwide, called nodes.

Traditional Database vs Blockchain

| Feature | Traditional DB | Blockchain | |---------|---------------|------------| | Controller | Single organization | Everyone (decentralized) | | Data modification | Can delete or modify | Immutable once written | | Downtime risk | Single point of failure | Only if all nodes fail simultaneously | | Transparency | Determined by the operator | Fully transparent and public | | Speed | Very fast | Slower (requires consensus) |

Three Core Properties of Blockchain

  1. Decentralization: No single person or organization can control the entire network. Power is distributed among all participants.
  2. Immutability: Once data is recorded on the blockchain, it can never be changed or deleted. This creates a permanent, tamper-proof record.
  3. Transparency: Every transaction ever made can be viewed by anyone using a block explorer. Nothing is hidden.

What is a Smart Contract?

A smart contract is a self-executing program deployed on the blockchain. Think of it like a vending machine:

  • You insert Coin A (this triggers the contract)
  • The vending machine executes its predefined logic (the smart contract code)
  • You receive Coin B as the result (the execution output)

No one can interfere with this process once it's started. Code is law.

Smart contracts eliminate the need for intermediaries like banks, lawyers, or notaries. They run exactly as programmed without downtime, censorship, or third-party interference.

Ethereum & the EVM

Ethereum was the first blockchain platform to support smart contracts, and it remains the most popular one. Its core is the EVM (Ethereum Virtual Machine) — a "world computer" running simultaneously on thousands of computers around the globe.

Key Concepts

Gas (Transaction Fee)

Every operation on Ethereum requires computational resources. Users pay for these resources in gas:

$$\text{Gas Fee} = \text{Gas Used} \times \text{Gas Price}$$

| Operation | Gas Required | |-----------|-------------| | Simple ETH transfer | 21,000 gas | | Deploying a contract | Hundreds of thousands to millions | | Complex contract interaction | Tens to hundreds of thousands |

Wallet

A wallet is your identity on the blockchain. It consists of a cryptographic key pair:

  • Public Key → Your address, like a bank account number (safe to share)
  • Private Key → Your password, like your ATM PIN (never share this with anyone!)

If you lose your private key, you lose access to your funds forever. There is no "forgot password" button on the blockchain.

Setting Up Your Development Environment

We'll build a complete Web3 development environment step by step.

1. Install Node.js

Node.js is required to run Hardhat, our development framework.

# Verify Node.js is installed (version 18 or higher)
node --version
npm --version

If Node.js is not installed, download it from nodejs.org.

2. Create a Hardhat Project

Hardhat is a development framework for Ethereum smart contracts.

mkdir vibe-dapp
cd vibe-dapp
npm init -y
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox

# Initialize the Hardhat project
npx hardhat init

When prompted, select "Create an empty hardhat.config.js".

3. Install OpenZeppelin Contracts

OpenZeppelin provides audited, production-ready smart contract templates.

npm install @openzeppelin/contracts

4. Install Ethers.js & Other Tools

npm install ethers dotenv

5. Configure Hardhat

Edit hardhat.config.js:

require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();

module.exports = {
  solidity: "0.8.20",
  networks: {
    // Local development network
    hardhat: {
      chainId: 31337,
    },
    // Sepolia test network
    sepolia: {
      url: process.env.SEPOLIA_RPC_URL || "",
      accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
    },
  },
};

6. Install MetaMask Wallet

MetaMask is the most popular browser wallet for interacting with dApps.

Go to https://metamask.io and install the browser extension.

  1. Create a new wallet — follow the setup wizard
  2. Back up your seed phrase — this is a 12-word phrase that can restore your wallet. Write it down and store it securely offline.
  3. Switch to the Sepolia test network — we'll use a test network to avoid spending real money
  4. Get free test ETH from a Sepolia faucet:

Your First Smart Contract

Let's write a simple "Hello World" contract to verify everything works.

Create contracts/HelloWorld.sol:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract HelloWorld {
    string public message;

    constructor() {
        message = "Hello, Web3 World!";
    }

    function setMessage(string memory _newMessage) public {
        message = _newMessage;
    }

    function getMessage() public view returns (string memory) {
        return message;
    }
}

Compile the Contract

npx hardhat compile

Deploy to Local Test Network

Create scripts/deploy.js:

const hre = require("hardhat");

async function main() {
  const HelloWorld = await hre.ethers.getContractFactory("HelloWorld");
  const contract = await HelloWorld.deploy();
  await contract.waitForDeployment();

  console.log("Contract deployed to:", await contract.getAddress());

  // Test reading the initial message
  let message = await contract.getMessage();
  console.log("Initial message:", message);

  // Update the message
  const tx = await contract.setMessage("Vibe Tutor Web3!");
  await tx.wait();

  // Read the updated message
  message = await contract.getMessage();
  console.log("Updated message:", message);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
npx hardhat run scripts/deploy.js

Expected output:

Contract deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
Initial message: Hello, Web3 World!
Updated message: Vibe Tutor Web3!

Congratulations!

You've set up your Web3 development environment and deployed your first smart contract. You now have:

  • ✅ A complete Hardhat development environment
  • ✅ An Ethereum wallet with test ETH
  • ✅ A deployed smart contract on a local test network
  • ✅ The ability to read and write to the blockchain

In the next chapter, we'll dive deeper into the Solidity programming language and build more complex contracts.

Practice Exercise

💡 Vibe Coding Practice: Ask AI to help you modify the HelloWorld contract to:

  1. Add a counter that increments every time the message is updated
  2. Store a history of all previous messages
  3. Restrict who can update the message (only the contract owner)
  4. Deploy the upgraded contract and test all the new features

Member Exclusive Free Tutorial

This chapter is free exclusive content for registered members! Please login or register to unlock immediately.

Login / Register Now