Blockchain 28 min read

From Bitcoin Basics to Ethereum Smart Contracts: A Hands‑On Guide

This article introduces blockchain fundamentals, explains Bitcoin and its protocol, compares public, private and consortium chains, then dives into Ethereum 2.0 concepts, consensus mechanisms, and provides a step‑by‑step tutorial for building a local test network, compiling geth and solc, and deploying a simple Solidity contract.

dbaplus Community
dbaplus Community
dbaplus Community
From Bitcoin Basics to Ethereum Smart Contracts: A Hands‑On Guide

1. Blockchain Basics

Blockchain is the distributed ledger technology underlying Bitcoin. It records transactions in an immutable, append‑only data structure that is replicated across many nodes.

Key components :

Users : control wallets via private keys.

Transactions : signed data packets broadcast to the network and included in blocks.

Miners/Validators : compete to create new blocks and achieve consensus.

Blockchain : the chain of blocks forming a public ledger.

Consensus mechanisms include Proof‑of‑Work (PoW), Proof‑of‑Stake (PoS) and Delegated Proof‑of‑Stake (DPoS). PoW requires solving a computational puzzle; PoS selects validators proportionally to their stake; DPoS elects a limited set of super‑nodes.

Chain classifications :

Public chain : open read/write/consensus for anyone.

Private chain : write permission restricted to a single organization; higher throughput (up to 100 k tx/s) and can roll back transactions.

Consortium chain : hybrid where a group of trusted entities share write rights.

Public chains provide decentralisation and censorship resistance but have low throughput (≈7 tx/s for Bitcoin). Private chains achieve higher performance at the cost of decentralisation.

2. Ethereum Overview (Blockchain 2.0)

Ethereum extends the blockchain model from simple value transfer to programmable smart contracts and decentralized applications (DApps). It introduces the Ethereum Virtual Machine (EVM), a Turing‑complete runtime that executes bytecode stored on‑chain.

Account types :

Externally Owned Account (EOA) : controlled by a private key, holds ether, can send transactions.

Contract Account : stores code and state; execution is triggered by transactions or internal messages.

Transaction is a signed packet that moves ether (denominated in wei, where 1 ether = 10¹⁸ wei) and may invoke contract functions. The execution cost is expressed as gasUsed × gasPrice.

Gas is a unit that measures computational effort. Each EVM opcode has a fixed gas cost; the sender specifies a gasPrice (in wei per gas) and a gas limit. If execution exceeds the limit, the state is reverted but the gas is still charged.

3. Ethereum Development Tutorial

3.1 Build a Local Test Network

Clone the Go‑Ethereum client:

git clone https://github.com/ethereum/go-ethereum

Install build dependencies (e.g., gvm on macOS or the Ubuntu packages listed in the official wiki).

Compile the client: make geth The binary appears at build/bin/geth.

Clone the Solidity compiler source: git clone https://github.com/ethereum/solidity Install its dependencies (CMake, Boost, etc.) and compile: make solc The solc binary is generated in the bin directory.

3.2 Create the Genesis Block

Write a genesis.json that defines the chain ID, initial accounts and difficulty, then initialise the data directory: geth --datadir test/chain init genesis.json This creates block 0, the starting point of the private network.

3.3 Launch geth

Start a node with the following flags (adjust paths as needed):

geth \
  --nodiscover \
  --rpc \
  --rpcapi "eth,net,web3" \
  --rpcport 8545 \
  --rpccorsdomain "*" \
  --datadir "test/chain" \
  --identity "myNode" \
  --networkid 12345 \
  --solc /path/to/solc

Key parameters: --nodiscover: disables automatic peer discovery, keeping the network isolated. --rpc and --rpcapi: expose the JSON‑RPC interface for web3.js or console access. --datadir: directory that stores the private chain data. --solc: path to the Solidity compiler used by the node.

3.4 Write and Compile a Simple Contract

Save the following Solidity source as test.sol:

pragma solidity ^0.4.0;

contract Test {
    function multiply(uint a) returns (uint d) {
        return a * 7;
    }
}

Compile with solc to obtain the bytecode and ABI: solc --abi --bin test.sol -o build/ The output files contain: Test.bin: EVM bytecode. Test.abi: JSON‑encoded contract ABI.

metadata such as compilerVersion and language.

3.5 Deploy the Contract

In the geth console, unlock an account that holds ether:

personal.unlockAccount(eth.accounts[0], "yourPassword")

Deploy the contract by sending a transaction that includes the compiled bytecode:

var abi = [ ... ]; // contents of Test.abi
var bytecode = "0x..."; // contents of Test.bin
var contract = eth.contract(abi);
var instance = contract.new({from: eth.accounts[0], data: bytecode, gas: 3000000});

The transaction consumes gas; once mined, instance.address holds the contract address.

3.6 Interact with the Contract

Two interaction modes are available:

sendTransaction : creates a real transaction, pays gas, and permanently changes state.

call : executes locally on the EVM without state changes or gas cost (useful for view functions).

Example using the JavaScript console:

var c = contract.at(instance.address);
// Call (no gas):
var result = c.multiply.call(5);
// Send transaction (pay gas):
var txHash = c.multiply.sendTransaction(5, {from: eth.accounts[0], gas: 200000});

Tools such as testrpc (now ganache-cli) and truffle can automate testing and deployment.

4. Q&A Highlights

Every full node executes each transaction; Ethereum prioritises security over computational efficiency.

Chinese companies using Ethereum include 金丘股份, 万向区块链实验室, 众安保险, 蚂蚁金服.

Bitcoin’s 1 MB block limit does not apply to Ethereum contracts.

Initial sync of the Ethereum chain typically takes around ten hours, depending on network bandwidth.

Chain splits are resolved by the longest‑chain rule; temporary forks disappear after enough confirmations.

Large contracts can be split into multiple contracts that call each other.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Blockchainsmart contractsSolidityEthereumEthereum Development
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.