Non-Fiction, Informative, Educational

Solidity Programming eBook

A Coursebook on Solidity Programming

by Wofford Odilia

  • English
  • 145 pages
  • 2026
  • SamEnrico

A Coursebook on Solidity Programming

Formats

Free sample

Chapter 1: The Invisible Ledger...--Imagine you and a friend are keeping track of who owes whom for coffee. You use a shared notebook. Every time someone buys, both of you write it down. If one of you tries to erase a debt, the other still has the record. Now imagine that notebook is not just between two friends but is duplicated across ten thousand computers worldwide, and no single person can erase or change anything without everyone else agreeing. That, in essence, is a blockchain. And on top of that global, tamper-proof notebook, you can run little programs that automatically move money, issue certificates, or even govern entire organizations. Those programs are called smart contracts, and the language you will use to write them is Solidity.This chapter is the conceptual foundation for everything that follows. You will write no production code here—instead, you will build a mental model of why blockchains exist, how Ethereum differs from Bitcoin, what gas really means, and why smart contracts are neither smart nor contracts in the legal sense. By the end of this chapter, you will understand the problem Solidity solves and be ready to set up your development environment in Chapter 2.Why Traditional Web Development Falls Short Traditional web applications operate on a client-server model. Your phone (the client) asks a centralized server (say, Twitter’s servers) for your feed. The server responds. You trust that server to not lie about your likes, to not delete your posts arbitrarily, and to keep your data secure. That trust is usually justified—but it is still trust. The server’s owner can change the rules, a hacker can breach the server, or the company can go bankrupt and vanish. In each case, your data and your digital relationships disappear.Now consider money. When you send $100 via a bank app, you are not moving digital cash. You are asking the bank to update its ledger: subtract $100 from your account and add $100 to another. The bank is the trusted intermediary. That system works billions of times per day, but it excludes billions of unbanked people, charges fees, takes days for cross-border transfers, and can freeze your account at any time.What if you could remove the intermediary? What if you could have a shared ledger that no single person controls, that no government can shut down easily, and that anyone with an internet connection can read and write to? That is the promise of blockchain.The Blockchain: A Chain of Tamper-Evident Blocks A blockchain is exactly what its name says: a chain of blocks. Each block contains a list of transactions (e.g., “Alice sends 2 ETH to Bob”), a timestamp, and a reference to the previous block. That reference is a cryptographic hash—a unique digital fingerprint of the previous block’s entire content.If you change even one comma in a previous block, its hash changes completely. That new hash no longer matches the reference stored in the next block. Every following block becomes invalid. This is how immutability works: not by physically preventing change, but by making change instantly detectable. Everyone running the blockchain software will reject the tampered version.Blocks are added roughly every 12 seconds on Ethereum. But who gets to add the next block? That is where consensus comes in.Decentralized Consensus: Agreeing Without a Boss In a traditional database, a central administrator decides the order of transactions. In a blockchain, thousands of independent computers (called nodes) must agree on the same history. This agreement process is called consensus.Ethereum originally used Proof of Work (like Bitcoin): nodes called miners solved expensive computational puzzles to earn the right to propose the next block. In 2022, Ethereum switched to Proof of Stake. Now, validators lock up (stake) 32 ETH as collateral. The protocol randomly selects one validator to propose a block, and others attest that the block is valid. If a validator cheats, their stake can be destroyed. This aligns incentives: it is more profitable to follow the rules than to attack the network.The key insight: no single validator controls the chain. To reverse a transaction, an attacker would need to control a supermajority of staked ETH and be willing to lose it all. That is economically irrational. Thus, the chain is secure without a central authority.The Ethereum World Computer Bitcoin popularized blockchain but does only one thing well: track who owns how much bitcoin. Ethereum generalized the concept. Instead of just sending coins, Ethereum lets you upload code that runs on the blockchain. The Ethereum Virtual Machine (EVM) is a global, singleton computer. Singleton means there is only one—every node executes the same code in the same order and arrives at the same result.Of course, a global computer that runs code for free would be flooded with infinite loops. That is why gas exists.Gas: The Fuel That Prevents Chaos Gas is the unit of computation on Ethereum. Every operation—adding two numbers, storing a variable, sending Ether—costs a specific amount of gas. When you send a transaction, you specify a gas limit (the maximum you are willing to consume) and a gas price (how much you pay per unit of gas in gwei, where 1 gwei = 0.000000001 ETH).If your transaction runs out of gas before finishing, the EVM stops immediately, reverts any changes, but still charges you for the gas used. This prevents infinite loops: you cannot run code forever because you would run out of ETH first.Gas is paid in ETH, but the price fluctuates based on network demand. When many people want to use Ethereum, gas prices rise. This market mechanism ensures that the network remains usable: if you really need your transaction to go through, you pay more.Accounts: The Two Kinds of Identities Ethereum has two types of accounts:Externally Owned Accounts (EOAs) are controlled by private keys. If you have a Meta Mask wallet, that is an EOA. An EOA can send transactions (which can transfer ETH or invoke smart contracts) and has a balance.Contract Accounts are controlled by code. They have no private key. Instead, they are activated when an EOA sends a transaction to them or when another contract calls them. Contract accounts also have balances and can store persistent data (state). The code that defines a contract account is written in Solidity and compiled to EVM bytecode.Think of an EOA as a person with a key. Think of a contract account as a vending machine: you insert coins (send ETH), press buttons (call functions), and it dispenses products (executes logic, updates its internal state). The vending machine cannot act on its own—someone must trigger it.Smart Contracts: Beyond "If This Then That"The term "smart contract" is famously misleading. They are neither smart (they do not use AI) nor contracts in the legal sense (though they can implement agreements). A better definition: a smart contract is a program that runs on the blockchain and controls digital assets.When you deploy a smart contract, you send its bytecode to the blockchain in a transaction. The blockchain assigns the contract an address. From then on, anyone (with the right permissions) can send transactions to that address, invoking the contract’s functions. The contract executes deterministically—every node runs the same code and gets the same result.Determinism is critical. The EVM cannot use…

This is the end of the free sample. Get the eBook to keep going. Buy now

About this book

A Coursebook on Solidity Programming

Details

Author
Wofford Odilia
Publisher
SamEnrico
Language
English
Genre
Non-Fiction, Informative, Educational
Released
2026-06-03
Pages (approx.)
145
Available as
eBook, Audiobook

Read better in the ZLOADR app

Your eBooks on your phone or tablet. Sign in with your SamEnrico account and start reading.

More by Wofford Odilia

See all