Download as pdf or txt
Download as pdf or txt
You are on page 1of 55

A Brief Introduction to Web3:

Decentralized Web Fundamentals for


App Development 1st Edition Shashank
Mohan Jain
Visit to download the full and correct content document:
https://ebookmass.com/product/a-brief-introduction-to-web3-decentralized-web-funda
mentals-for-app-development-1st-edition-shashank-mohan-jain/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Linux Containers and Virtualization: Utilizing Rust for


Linux Containers 2nd Edition Shashank Mohan Jain

https://ebookmass.com/product/linux-containers-and-
virtualization-utilizing-rust-for-linux-containers-2nd-edition-
shashank-mohan-jain/

Web API Development for the Absolute Beginner: A Step-


by-step Approach to Learning the Fundamentals of Web
API Development with .NET 7 1st Edition Irina Dominte

https://ebookmass.com/product/web-api-development-for-the-
absolute-beginner-a-step-by-step-approach-to-learning-the-
fundamentals-of-web-api-development-with-net-7-1st-edition-irina-
dominte/

Semantic Web for Effective Healthcare Systems Vishal


Jain

https://ebookmass.com/product/semantic-web-for-effective-
healthcare-systems-vishal-jain/

Fundamentals of Web Development 3rd Edition Randy


Connolly

https://ebookmass.com/product/fundamentals-of-web-
development-3rd-edition-randy-connolly/
How JavaScript Works: Master the Basics of JavaScript
and Modern Web App Development 1st Edition Jonathon
Simpson

https://ebookmass.com/product/how-javascript-works-master-the-
basics-of-javascript-and-modern-web-app-development-1st-edition-
jonathon-simpson-2/

How JavaScript Works: Master the Basics of JavaScript


and Modern Web App Development 1st Edition Jonathon
Simpson

https://ebookmass.com/product/how-javascript-works-master-the-
basics-of-javascript-and-modern-web-app-development-1st-edition-
jonathon-simpson/

American Government: A Brief Introduction (Brief


Fifteenth Edition ) Brief

https://ebookmass.com/product/american-government-a-brief-
introduction-brief-fifteenth-edition-brief/

(eBook PDF) Introduction to Criminology: A Brief


Edition

https://ebookmass.com/product/ebook-pdf-introduction-to-
criminology-a-brief-edition/

Kotlin for Web Development and Kotlin Collections: A


Beginner's Odyssey in Web Development 2 Books in 1 Jp
Parker

https://ebookmass.com/product/kotlin-for-web-development-and-
kotlin-collections-a-beginners-odyssey-in-web-
development-2-books-in-1-jp-parker/
A Brief
Introduction
to Web3
Decentralized Web Fundamentals
for App Development

Shashank Mohan Jain
A Brief Introduction
to Web3
Decentralized Web
Fundamentals for App
Development

Shashank Mohan Jain


A Brief Introduction to Web3: Decentralized Web Fundamentals for App
Development

Shashank Mohan Jain


Bangalore, India

ISBN-13 (pbk): 978-1-4842-8974-7 ISBN-13 (electronic): 978-1-4842-8975-4


https://doi.org/10.1007/978-1-4842-8975-4

Copyright © 2023 by Shashank Mohan Jain


This work is subject to copyright. All rights are reserved by the publisher, whether the whole or
part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: James Robinson-Prior
Development Editor: James Markham
Coordinating Editor: Gryffin Winkler
Copy Editor: April Rondeau
Cover designed by eStudioCalamar
Cover image by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY
10004, U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, email orders-ny@springer-sbm.com,
or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member
(owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance
Inc is a Delaware corporation.
For information on translations, please e-mail booktranslations@springernature.com; for
reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is
available to readers on GitHub (https://github.com/Apress). For more detailed information,
please visit http://www.apress.com/source-code.
Printed on acid-free paper
I humbly dedicate all my work to my parents, without
whom this would never, ever be possible. I also dedicate this
to my wife, Manisha, and my daughter, Isha, for allowing
me to take time out of their time to write this book.
Table of Contents
About the Author���������������������������������������������������������������������������������ix

About the Technical Reviewer�������������������������������������������������������������xi

Introduction���������������������������������������������������������������������������������������xiii

Chapter 1: Decentralization and Web3�������������������������������������������������1


1.1 Web 1.0�����������������������������������������������������������������������������������������������������������1
1.2 Web 2.0�����������������������������������������������������������������������������������������������������������1
1.3 Web 3.0�����������������������������������������������������������������������������������������������������������2
1.3.1 Introduction to Decentralization�������������������������������������������������������������3
1.3.2 Different Topologies for Networks����������������������������������������������������������4
1.3.3 Decentralized Systems���������������������������������������������������������������������������5
1.3.4 Web3 Case Study������������������������������������������������������������������������������������8
1.4 Summary��������������������������������������������������������������������������������������������������������9

Chapter 2: Blockchain������������������������������������������������������������������������11
2.1 Types of Blockchains�������������������������������������������������������������������������������������11
2.1.1 Public Blockchain���������������������������������������������������������������������������������12
2.1.2 Private Blockchain��������������������������������������������������������������������������������12
2.1.3 Permissioned Blockchain���������������������������������������������������������������������12
2.2 What Is a Blockchain?�����������������������������������������������������������������������������������13
2.3 Blockchain Building Blocks���������������������������������������������������������������������������14
2.3.1 Block�����������������������������������������������������������������������������������������������������14
2.3.2 Chain����������������������������������������������������������������������������������������������������15

v
Table of Contents

2.3.3 Network������������������������������������������������������������������������������������������������15
2.4 Where Is Blockchain Used?���������������������������������������������������������������������������16
2.5 Evolution�������������������������������������������������������������������������������������������������������17
2.6 Consensus�����������������������������������������������������������������������������������������������������17
2.6.1 Proof of Work����������������������������������������������������������������������������������������18
2.6.2 Proof of Stake���������������������������������������������������������������������������������������20
2.7 Blockchain Architecture��������������������������������������������������������������������������������21
2.8 Cryptographic Keys���������������������������������������������������������������������������������������23
2.9 Blockchain Compared to a Singly Linked List�����������������������������������������������24
2.10 Ethereum�����������������������������������������������������������������������������������������������������25
2.11 Summary����������������������������������������������������������������������������������������������������26

Chapter 3: Solidity������������������������������������������������������������������������������27
3.1 What Is Solidity?�������������������������������������������������������������������������������������������28
3.2 Ethereum�������������������������������������������������������������������������������������������������������29
3.2.1 Ethereum Virtual Machine��������������������������������������������������������������������29
3.3 Smart Contracts��������������������������������������������������������������������������������������������30
3.4 Making Sense of Solidity Syntax�������������������������������������������������������������������30
3.4.1 Pragma�������������������������������������������������������������������������������������������������30
3.4.2 Variables�����������������������������������������������������������������������������������������������30
3.4.3 Value Types�������������������������������������������������������������������������������������������34
3.4.4 Address�������������������������������������������������������������������������������������������������35
3.4.5 Operators in Solidity�����������������������������������������������������������������������������35
3.4.6 Loops����������������������������������������������������������������������������������������������������37
3.4.7 Decision Flows�������������������������������������������������������������������������������������39
3.4.8 Functions in Solidity�����������������������������������������������������������������������������41
3.4.9 Abstract Contracts��������������������������������������������������������������������������������52
3.4.10 Interface���������������������������������������������������������������������������������������������53

vi
Table of Contents

3.4.11 Libraries���������������������������������������������������������������������������������������������55
3.4.12 Events�������������������������������������������������������������������������������������������������55
3.4.13 Error Handling in Solidity��������������������������������������������������������������������56
3.4.14 Solidity and Addresses�����������������������������������������������������������������������56
3.5 Summary������������������������������������������������������������������������������������������������������62

Chapter 4: Wallets and Gateways�������������������������������������������������������63


4.1 Types of Wallets��������������������������������������������������������������������������������������������64
4.2 So, What Is a Testnet ?����������������������������������������������������������������������������������66
4.3 MetaMask�����������������������������������������������������������������������������������������������������67
4.3.1 Installation��������������������������������������������������������������������������������������������68
4.4 Web3.js���������������������������������������������������������������������������������������������������������76
4.4.1 web3-eth����������������������������������������������������������������������������������������������77
4.4.2 web3-shh���������������������������������������������������������������������������������������������77
4.4.3 web3-bzz����������������������������������������������������������������������������������������������77
4.4.4 web3-net����������������������������������������������������������������������������������������������78
4.4.5 web3-utils��������������������������������������������������������������������������������������������78
4.5 Infura Setup��������������������������������������������������������������������������������������������������79
4.5.1 Interfacing with Ropsten Network via Infura Gateway�������������������������82
4.6 Summary������������������������������������������������������������������������������������������������������87

Chapter 5: Introduction to Remix IDE�������������������������������������������������89


5.1 Remix IDE������������������������������������������������������������������������������������������������������89
5.2 Creating Own Token������������������������������������������������������������������������������������109
5.3 Summary����������������������������������������������������������������������������������������������������126

Chapter 6: Truffle������������������������������������������������������������������������������127
6.1 Truffle Installation���������������������������������������������������������������������������������������127
6.1.1 Installing Node������������������������������������������������������������������������������������127
6.1.2 Install Truffle���������������������������������������������������������������������������������������128

vii
Table of Contents

6.2 Smart Contract Deployment via Truffle�������������������������������������������������������129


6.2.1 Contract Code�������������������������������������������������������������������������������������130
6.2.2 Compile and Deploy the Contract�������������������������������������������������������137
6.3 Summary����������������������������������������������������������������������������������������������������144

Chapter 7: IPFS and NFTs�����������������������������������������������������������������147


7.1 IPFS�������������������������������������������������������������������������������������������������������������147
7.1.1 IPFS: 30,000-Foot View����������������������������������������������������������������������149
7.1.2 Installation������������������������������������������������������������������������������������������150
7.2 ERC-721������������������������������������������������������������������������������������������������������152
7.3 Creating an ERC-721 Token and Deploying It to IPFS���������������������������������153
7.4 Summary����������������������������������������������������������������������������������������������������165

Chapter 8: Hardhat���������������������������������������������������������������������������167
8.1 Installation of Hardhat Framework�������������������������������������������������������������167
8.2 Workflow for Hardhat����������������������������������������������������������������������������������167
8.3 Deployment of the Smart Contract��������������������������������������������������������������172
8.4 Summary����������������������������������������������������������������������������������������������������179

Index�������������������������������������������������������������������������������������������������181

viii
About the Author
Shashank Mohan Jain has been working in
the IT industry for around 22 years, mainly
in the areas of cloud computing, machine
learning, and distributed systems. He has keen
interest in virtualization techniques, security,
and complex systems. Shashank has multiple
software patents to his name in the area of
cloud computing, Internet of Things, and
machine learning. He is a speaker at multiple
reputed cloud conferences. Shashank holds
Sun, Microsoft, and Linux kernel certifications.

ix
About the Technical Reviewer
Prasanth Sahoo is a thought leader, an adjunct professor, a technical
speaker, and a full-time practitioner in blockchain, DevOps, cloud, and
Agile, all while working for PDI Software. He was awarded the Blockchain
and Cloud Expert of the Year Award 2019 from TCS Global Community
for his knowledge share within academic services to the community. He is
passionate about driving digital technology initiatives by handling various
community initiatives through coaching, mentoring, and grooming
techniques. Prasanth has a patent under his name, and to date he has
interacted with over 50,000 professionals, mostly within the technical
domain. He is a working group member in the Blockchain Council,
CryptoCurrency Certification Consortium, Scrum Alliance, Scrum
Organization, and International Institute of Business Analysis.

xi
Introduction
We live in exciting times. We are witnessing a revolution in the space of
technology every other day. Web3 happens to be one such revolution.
With the advent of web3 and blockchain technologies, the way we write
applications is changing. The whole idea of this book is to provide the
reader with a basic introduction to web3. The book will enable the reader
to understand the nuances of web3 and to create simple applications, like
creating one’s own tokens or NFTs.

xiii
CHAPTER 1

Decentralization
and Web3
In this chapter, we are going to examine the evolution of Web 3.0 starting
from Web 1.0 and 2.0.

1.1 Web 1.0
In Web 1.0, websites delivered static content (rather than dynamic
content) written in hypertext markup language (HTML). The data and
content were sent by means of a static file system as opposed to a database,
and the web pages had only a minimal amount of interactive information.
The following is a list of the principal technologies that were included
in Web 1.0:

• HTML (HyperText Markup Language)

• URL encoded in the HyperText Transfer Protocol, or


HTTP (Uniform Resource Locator)

1.2 Web 2.0
Since in Web 1.0 most content was static, it gave rise to Web 2.0.

© Shashank Mohan Jain 2023 1


S. M. Jain, A Brief Introduction to Web3, https://doi.org/10.1007/978-1-4842-8975-4_1
Chapter 1 Decentralization and Web3

The vast majority of us have only experienced the World Wide Web in
its most recent iteration, sometimes referred to as Web 2.0, the interactive
read–write web, and the social web. Participating in the creative process of
Web 2.0 does not require you to have any prior experience as a developer.
A great number of apps are designed in such a way that anyone can make
their own version of the program.
You are capable of coming up with ideas and communicating those
ideas to people around the globe. You are able to post a video to Web 2.0,
where it will be available for millions of users to watch, interact with, and
comment on. Web 2.0 applications consist of social media sites, such as
YouTube, Facebook, Flickr, Instagram, and Twitter, among others. Think
about how popular these sites were back when they first launched, and
then compare that to how popular they are now.
Web 2.0 allowed applications to scale, but also gave rise to centralized
platforms that took control of all user data. This gave them a chance and
opportunity to do data mining, which can be put to both positive and
negative uses.
Since users were increasingly losing control to these centralized
platforms, it led to the emergence of Web 3.0

1.3 Web 3.0
Web 2.0 design inherently depended on centralized systems. Those systems
might have been distributed but were not decentralized. This meant that
control of those systems remained with individuals or a group of individuals.
This led to huge issues as privacy and data usage concerns started to emerge.
This led to the evolution of Web 3.0, which keeps decentralization as its
first requirement. This means applications for Web3 will be deployed in a
decentralized way and data storage for its apps will also be decentralized.
Therefore, it’s important to have an idea of what decentralization is before
understanding the Web3 landscape.

2
Chapter 1 Decentralization and Web3

1.3.1 Introduction to Decentralization
“Unthinking respect for the authority is the greatest enemy of truth.” This
famous quote by Albert Einstein goes a long way in making us think about
whether there should be systems that are controlled by an authority,
thereby asking us to have complete faith and trust in the authority, or
there should be systems that are decentralized, with consensus as the
root of decision making. Central systems, as their name suggests, can be
controlled by the whims of a central authority, whereas a decentralized
system will favor more inclusive decision making, thereby reducing the
chance of corruption within that system.
In a decentralized setup, there is no owner or master. There are only
peers participating in the network. These nodes exchange messages
between them to form consensus as and when needed. The protocols
governing these networks make sure that the overall system of nodes is
in a consistent state. Every node in the network has an up-to-date copy of
all the data that was recorded. Decentralized networks can also distribute
data to validate particular private information without having to hand
over that information to a third party. This validation is made possible by
the fact that data does not have to be transferred. The validation of data is
accomplished by the utilization of a consensus-based technique, wherein
the nodes on the network agree to a certain state of the overall system at a
certain point in time.
Each participant node in a decentralized network functions
independently of the other nodes in the network. Decentralized nodes
interact with one another through the use of common standards, but
they keep their independence and are in charge of their own privacy
management, rather than adhering to the directives of a centralized
authority. This not only helps to maintain the network’s safety but also
ensures that it is governed in a democratic manner.
Figure 1-1 shows how nodes connect and communicate in centralized,
decentralized, and distributed networks.

3
Chapter 1 Decentralization and Web3

Figure 1-1. Difference between centralized, decentralized, and


distributed networks

The terms “centralization” and “decentralization” both refer to levels


of control. Control is exercised by just one organization or person in a
centralized system (a person or an enterprise, for example). There is not a
single entity that controls the operation of a decentralized system. Instead,
the control is divided among a number of different autonomous entities.
Differences in location are meant to be understood as distribution.
In a system that is not distributed, also known as being co-located, all
of the components of the system are situated in the same physical location.
A distributed system is one in which different components can be found in
different physical locations.

1.3.2 Different Topologies for Networks


Networks can be configured in different topological settings. A few of them
are explained in the following sections.

4
Chapter 1 Decentralization and Web3

1.3.2.1 Centralized and Non-distributed


In the event that you are putting together a stand-alone application that
will run on your Windows computer, this configuration is not distributed
and also functions as a centralized system. Your application is under the
control of one party (the application vendor), and an additional party,
such as Microsoft, is in charge of your operating system (centralized).
The application and the operating system are both stored locally on your
personal computer, making them both non-distributable components.

1.3.2.2 Centralized but Distributed


Imagine that you are working on a cloud application that is hosted on
Amazon Web Services and runs on virtual machines hosted by Amazon
Web Services. This configuration is both centralized and distributed at
the same time. Your application and operating system are both under the
control of AWS (centralized). Cloud storage serves as the host for both the
application and the operating system, which may be partitioned across
multiple locations.

1.3.3 Decentralized Systems
By its very nature, a decentralized system will be distributed. Peer-to-peer
software can be thought of as an example of a decentralized system, which
is defined as “a system that requires multiple parties to make their own
independent decisions.”
It is impossible to have a single, centralized authority in a decentralized
system that is responsible for making decisions on behalf of all the
different parties. Instead, each party, also known as a peer, is responsible
for making locally autonomous decisions in the direction of achieving its
own individual goals, which may or may not be in conflict with the goals
pursued by other peers. Peers engage in one-on-one communication with

5
Chapter 1 Decentralization and Web3

one another, during which they may exchange information or perform a


service for other peers. When it comes to decentralized systems, an open
system is one in which the participation of peers is not restricted in any
way. At any point, a peer may join or leave the system at their discretion.
Before information is added to a blockchain (which is an example
of a decentralized system), the nodes participating in the network must
use something called a consensus mechanism to reach a decision on
whether or not it is accurate. Once the block has been updated with the
data, it is sent to all of the nodes in the network. This makes it extremely
difficult to alter information that has already been added to the ledger.
Mutation of state on a decentralized network requires a majority of nodes
to reflect the updated state, which is a very difficult thing to achieve, and
therefore the decentralized network of nodes is immutable. This is in
contrast to changing the data in a single database that is centralized. If
rule of immutability is broken, the validating nodes will disregard such
information.
The process of dispersing functions and power away from a central
location or authority is known as decentralization. It is difficult, if not
impossible, to identify a specific center in a decentralized architecture. The
World Wide Web was created as a decentralized platform. Decentralized
architectures and systems are demonstrated by blockchain technologies
such as Bitcoin and Ethereum.
As the technological landscape changes, decentralized structures
emerge. Decentralization has the power to change a lot of things, from
governance and industry to justice systems.
Now, with this basic knowledge of decentralization, we can start to
understand the Web 3.0 landscape.
Web 3.0 apps are built on blockchains, which are decentralized
networks of numerous peer-to-peer nodes. Blockchains are used to
record transactions that take place between users. In the context of the
Web 3.0 ecosystem, these applications are referred to as decentralized
apps (DApps), which is a term that is frequently used. The participants

6
Chapter 1 Decentralization and Web3

in the network, known as developers, are paid for their efforts to provide
services of the highest possible quality in order to maintain a decentralized
network that is both robust and safe.
At a high level, the Web 3.0 architecture comprises four major parts, as
follows:

1. Blockchain – A peer-to-peer network of nodes is


responsible for the maintenance of these global
state machines. Access to the state machine, as
well as writing to it, is open to anybody on the
globe. In essence, rather than being owned by a
single company, it is held collectively by all of the
participants in the network. Users are able to upload
new data to the blockchain, but they are unable to
edit the data that has already been added. There are
many types of blockchain available, like Ethereum,
Solana, Polkadot, etc.

2. Smart Contracts – The Ethereum blockchain can


host something called a smart contract, which is
a computer program that runs on the blockchain.
These are written by app developers using high-
level programming languages such as Solidity or
Vyper to specify the logic that lies beneath the state
transitions. We will discuss Solidity in Chapter 3.

3. Ethereum Virtual Machine (EVM) – It’s a virtual


machine that is tasked with putting into action
the logic that is outlined in smart contracts. It
is in charge of managing the state machine’s
transitions between states. It generally operates
on the bytecode, which is generated by taking the
Solidity source code and compiling it via the Solidity
compiler.

7
Chapter 1 Decentralization and Web3

4. Front End/UI – The user interface (UI) logic is


defined by the front end, just like it is in any other
application. However, it does communicate with
smart contracts, which are programs that describe
how an application works.

Before we can develop a simple Web3 app, we need to be conversant


with certain technologies and environments. We will start with the Remix
integrated development environment (IDE), which we will use as an
environment in this chapter for the development and deployment of our
Web3 app based on smart contracts.

1.3.4 Web3 Case Study


Every one of us as professionals has heard about LinkedIn, which is a
social network for professionals. It is controlled by LinkedIn, and its bosses
can decide the rules of the platform. They can also choose whom to censor
if they want to. But we don’t need to worry. There is a Web3 alternative to
LinkedIn that goes by the name of Entre. It can be accessed at https://
joinentre.com/.
It’s a decentralized professional network built using Web3
technologies. It currently has around 50,000 members and is growing. It
provides posting for jobs, calendar for events, and many other features.
Since this is a decentralized platform, the rules are hard to change by a
central authority.
Apart from this, there are other Web3 platforms, like Deso as an
alternate to Twitter and Odysee as an alternate to YouTube. I can say
that we are in very exciting times as far as the shape of the technology is
concerned.

8
Chapter 1 Decentralization and Web3

1.4 Summary
In this chapter, we briefly touched upon the notion of Web 3.0 and
decentralization and its forms. In next chapter, we will introduce the
reader to the blockchain ecosystem and its various types. We will also
study the functioning of some of the existing blockchain networks, like
Bitcoin and Ethereum.

9
CHAPTER 2

Blockchain
Blockchain technology presents an innovative take on the traditional
distributed database. The utilization of existing technology in
unconventional settings is the source of the innovation. When we think
of a traditional database like Postgres, there is a master node that accepts
the write requests and is responsible for synchronizing the state changes
to other Postgres nodes. In a decentralized setup like blockchain, there is
no master node, but still it serves the same purpose of updating the ledger
and making sure that other nodes in the network reflect the updated state
correctly.
There are a great number of distinct varieties of blockchains and
applications for blockchain technology. The blockchain is an all-­
encompassing technology that is currently being integrated across a
variety of different platforms and pieces of hardware around the world.
A blockchain is a data structure that enables the creation of a digital
ledger of data and the sharing of that data across a network of parties that
are not affiliated with one another. There are a great number of distinct
varieties of blockchains.

2.1 Types of Blockchains
Blockchains can be classified under three broader categories.

© Shashank Mohan Jain 2023 11


S. M. Jain, A Brief Introduction to Web3, https://doi.org/10.1007/978-1-4842-8975-4_2
Chapter 2 Blockchain

2.1.1 Public Blockchain
Blockchains that are open to the public, like Bitcoin, are large distributed
networks that are each managed by their own native token. They have
open-source code that is maintained by their community and welcome
participation from anyone, regardless of level of involvement.

2.1.2 Private Blockchain
Private blockchains are typically smaller than public ones, and they do
not make use of tokens. Their membership is strictly monitored and
regulated. Consortiums that comprise reliable members and engage in the
confidential exchange of information favor the use of blockchains of this
kind. An example of this would be a corporation using a blockchain in its
own data center. IBM has an implementation called Hyperledger that is
implemented by several corporations.

2.1.3 Permissioned Blockchain
A permissioned blockchain is one in which a user needs permission to
access it. This is very different from public and private blockchains. A
corporate setup might look for a permissioned blockchain where it uses
the blockchain more like a decentralized database within the confines
of the corporate boundaries. Examples of permissioned blockchains are
Ripple and IBM Food Trust.
The reasons blockchains rose to prominence are as follows:

1. Their decentralized nature – The blockchain setup


advocates decentralization in its architecture.
This means that in a strong blockchain network
like Bitcoin or Ethereum, there are no centralized
authorities. Anyone can participate in these

12
Chapter 2 Blockchain

networks by spinning their own node and becoming


part of the blockchain network. This is really an
empowering feature.

2. Immutable data structure for storage – All data that


is stored on the blockchain is permanently recorded
across a fleet of nodes/computers across the
globe. One can think of this as a permanent ledger
of records. Removal of a record from this ledger
needs a majority of the network to agree, which is
a practical impossibility if the network is big like
Bitcoin or Ethereum.

Though the rules vary from blockchain to blockchain, generally any


mutation or state chain on the blockchain is done by one entity, which
then publishes the changes on the network for other nodes to verify. Only
when a majority agrees to that state is the transaction considered valid.
The mechanism for who gets the right to change the state can vary from
blockchain to blockchain based on the underlying algorithm of the chain.
As an example, for a Bitcoin-based blockchain there is the proof-of-work
algorithm, which lets the nodes participate in solving a mathematical
puzzle, and the node that solves it first gets the right to write on the ledger.
The writer then broadcasts the changes to the network for the validator to
validate the changes.

2.2 What Is a Blockchain?
A blockchain is a peer-to-peer network that does not rely on a centralized
authority to manage the state of the system or ledger. The computers that
form the network can be distributed physically. “Full nodes” is another
common name for these kinds of computers.

13
Chapter 2 Blockchain

After data has been entered into a blockchain database, it is extremely


difficult, if not impossible, to delete or alter that data. This means that
once the data is recorded and replicated across tons of nodes across the
world, the consumer of the data can have a higher level of trust in the data
as compared to data recorded on a centralized ledger. This means that
records like property rights, marriage certificates, invoices, and so on can
be recorded on the chain for permanence without the worry of tampering.
Processes that rely on having a central system in business and banking,
such as fund settlements and money wires, can now be completed
without having a central authority in place. The implications of having
secure digital records are extremely significant for the economy of the
entire world.

2.3 Blockchain Building Blocks


There are three main components of a blockchain ecosystem.

2.3.1 Block
A block is a listing of the transactions that have been entered into a ledger
over the course of a specific time period. Each blockchain has its own
unique dimensions, time intervals, and events that cause blocks to be
created.
There are some blockchains whose primary focus is not on
maintaining and securing a record of the transactions involving their
respective cryptocurrencies. However, every blockchain will record any
transactions involving its associated cryptocurrency or token. Consider
the transaction to be nothing more than the simple recording of data. The
interpretation of what that data means is accomplished by first giving it a
value, as is done in the course of a financial transaction.

14
Chapter 2 Blockchain

2.3.2 Chain
A chain can be thought of as a linked list of blocks. The block that comes
after the first block (also known as genesis block) will maintain a reference
to the previous block and so on and so forth. This reference is maintained
by generating a hash of the contents of the previous block. This has some
great implications for the immutability of the chain. Anyone who has to
alter a previous block will then need to modify all blocks ahead of that
particular block. Generally this is a practical impossibility as it might
require either huge computing resources in the case of algorithms like
proof of work, or a huge stake to be put in the network for proof of stake–
based algorithms like Ethereum.

2.3.3 Network
“Full nodes” are the building blocks of the network. Imagine them as a
computer that is actively implementing an algorithm to ensure the safety
of the network. All nodes in the network have the same copy of records
(called the ledger). The ledger comprises all transactions that have ever
been recorded on the blockchain.
The network nodes are decentralized and can be run by anyone in
any part of the world. Since running these nodes will incur costs, people
need some incentive to do so. They are motivated to run a node because
they want to earn cryptocurrency, which serves as their incentive. The
underlying algorithm of the blockchain provides them with compensation
for their service. Typically, a token or cryptocurrency, such as Bitcoin or
ether, is awarded as the reward.

15
Chapter 2 Blockchain

2.4 Where Is Blockchain Used?


Applications based on the blockchain are designed around the principle
that the network should act as the arbitrator. This kind of system creates
an unforgiving and oblivious atmosphere for its users. The computer code
effectively becomes the law, and the rules are carried out in the manner
in which they were written and are interpreted by the network. The social
behaviors and prejudices that are characteristic of humans are absent in
computers.
The network is incapable of interpreting the user’s intent (at least
not yet). As a potential use case for this concept, insurance contracts
that are arbitrated on a blockchain have received a lot of attention and
research. The ability to keep immutable records is yet another fascinating
application of blockchain technology.
You can use them to make a comprehensible timeline of who did
what and when. Countless hours are spent by numerous industries
and regulatory bodies trying to get a handle on the magnitude of this
issue. An immutable ledger will allow us to keep a consistent timeline of
transactions that have happened right from the inception of the chain.
Although people frequently use the terms “Bitcoin” and “blockchain”
interchangeably, these two concepts are not the same. A blockchain is
used by Bitcoin. The underlying protocol that allows for the safe transfer
of Bitcoin is known as the blockchain. Bitcoin is the name of the digital
currency that serves as the driving force behind the Bitcoin network.
So Bitcoin is one of the applications built on top of the blockchain
infrastructure.

16
Chapter 2 Blockchain

2.5 Evolution
Blockchain technology was initially developed in conjunction with the
cryptocurrency Bitcoin. The whole idea of Bitcoin was to develop a system
for decentralized money and banking. The initial purpose of the Bitcoin
network’s construction was to ensure the cryptocurrency’s safety. It has
somewhere in the neighborhood of 5,000 full nodes and is spread out
across the world. Its primary purpose is to buy and sell Bitcoin and other
cryptocurrencies, but the community quickly realized that it could be
used for a great deal more than that. Because of its size and the fact that
its security has been proven over time, it is also being used to secure other
blockchains and blockchain applications that are smaller in scale.
The blockchain technology has undergone a second iteration with the
creation of the Ethereum network. It modifies the conventional structure of
a blockchain by incorporating a programming language that is embedded
within the structure itself. Similar to Bitcoin, it has more than 5,000 full
nodes and is distributed across the world. Ether trading, the development
of smart contracts, and the formation of decentralized autonomous
organizations (DAOs) are the primary uses of Ethereum. Additionally, it is
utilized in the process of securing blockchain applications as well as more
compact blockchains.
The Ethereum ecosystem is what turned the blockchain ecosystem into
a programmable blockchain.

2.6 Consensus
Consensus is one of the most difficult problems to solve in a distributed
systems setup.
Blockchains are useful tools because they are capable of self-correcting
and do not require the intervention of a third party in order to do so.
Through the use of their consensus algorithm, they are able to successfully
enforce the rules.

17
Chapter 2 Blockchain

In the world of blockchain technology, “reaching consensus” refers


to the procedure of reaching an agreement among a group of nodes that
typically do not trust one another. These are the nodes on the network that
have full functionality. Transactions that are entered into the network in
order for them to be recorded on the ledger are being checked for validity
by the full nodes. Each blockchain has its own set of algorithms that it
uses to get its network to reach a consensus on the new entries that are
being added. Because different kinds of entries are being generated by
each blockchain, there is a diverse range of models available for achieving
consensus.
Some of the mechanisms used by different blockchains for consensus
are as follows:

• Proof of Work – Used by Bitcoin blockchain

• Proof of Stake – Used by Ethereum

• Proof of History – Used by Solana

2.6.1 Proof of Work
The first decentralized cryptocurrency to use a consensus mechanism
was Bitcoin, and that mechanism was proof of work. Mining and proof
of work are concepts that are closely related to one another. The term
“proof of work” comes from the fact that the network needs an extremely
high level of processing power to function properly. Proof-of-work
blockchains are those in which virtual miners from all over the world
compete with one another to see who can solve a mathematical puzzle
first. These blockchains are then secured and verified. The victor receives a
predetermined amount of cryptocurrency from the network as well as the
opportunity to update the blockchain with the most recent transactions
that have been verified.

18
Chapter 2 Blockchain

Proof of work offers a number of significant benefits, particularly for


the case of Bitcoin, which is a relatively straightforward but extremely
valuable cryptocurrency. It is a tried-and-trusted method that can
reliably keep a decentralized blockchain in a secure state. As the price
of a cryptocurrency continues to rise, more miners will be encouraged
to participate in the network, which will result in an increase in both the
network’s power and its level of security. The Bitcoin network also in its
algorithm has a difficulty adjustment mechanism, which is like a feedback
loop to alter the difficulty of mining based on demand. If there are huge
number of miners and they are able to mine quickly because they have
good resources at hand, the algorithm increases the difficulty level of the
mining to keep the mining time of one block to 10 minutes.
The mathematical puzzle used by a proof-of-work algorithm is
not truly a puzzle in the sense of a physical puzzle. It uses the one-­
way function of cryptographic hashes as the underlying mechanism.
Cryptographic hashes are designed to be deterministic one-way functions.
What this means is that any content, be it text of few lines or document
or images or videos can be reduced to a specific size. For instance, in a
SHA 256–based hash function, the size of the output is 256 bits, no matter
how big or small the input is. The other property of hash functions is that
the same content will generate the same hash no matter how many times
you run the same hash function over it. This is where the determinism
comes from.
As I said, it’s a one-way function, so going from input to output is
easy. Going back from output to input is impossible, or one could say
computationally infeasible. Bitcoin uses this property for its proof-of-work
algorithm.
So basically the Bitcoin network provides a hash value as the input and
asks the miners to generate a hash by taking the following two inputs:

• The block header

• A random number called nonce

19
Chapter 2 Blockchain

The miner needs to add these two together and generate a hash that is
less than the value provided by the Bitcoin network for a specific block. As
we discussed, since hashing is a one-way function, the miner now starts to
add different values of nonce to the header and has to effectively generate
the hashes to make it less than the target hash provided by the system.
There is no other way to do this except by crunching these hashes.

2.6.2 Proof of Stake
Ethereum blockchain started with proof of work as the algorithm but now
is moving to a proof-of-stake algorithm. In proof of stake, to mine the ether
(that’s the currency on the Ethereum blockchain) the network participant
has to stake the currency. Say, for example, I want to be a validator on
the network. I then have to put some money at stake to validate the
transactions. This puts my skin in the game, and I am disincentivized to
cheat. So, instead of putting in energy, as in the case of Bitcoin, Ethereum
advocates putting money itself at stake for being a participant on the
network.
From the pool of stakers, the one who puts the maximum stake will be
chosen as the validator of transactions and will be rewarded for the task.
Other validators will be able to do a proof of validity of the block
of transactions once the winner has validated the most recent block of
transactions. The blockchain is updated whenever the network reaches a
certain predetermined number of confirmations or attestations.
One of the most significant distinctions between the two consensus
mechanisms is the amount of energy required. Proof-of-stake blockchains
enable networks to function with significantly lower resource consumption
than blockchains based on proof of work. The debate still rages as to which
is a better mechanism as far as representation of money is concerned.
Both of these consensus mechanisms have economic repercussions
that punish malicious actors for disrupting the network and discourage
others from doing so. The sunk cost of computing power, energy, and

20
Another random document with
no related content on Scribd:
His efforts were all for the good of Prussia, and his subjects
recognized what he had done for the fatherland. Zimmermann, the
Hanoverian physician, thus describes him in his old age:—
“He is not of tall stature, and seems bent under his load of
laurels and his many years of struggle. His blue coat, much worn like
his body, long boots to above the knees, and a white snuff-
besprinkled vest, gave him a peculiar aspect. But the fire of his eyes
showed that Frederick’s soul had not grown old. Though his bearing
was that of an invalid, yet one must conclude from the quickness of
his movements and the bold decisiveness of his look, that he could
yet fight like a youth. Set up his unimportant figure among a million
of men, and every one would recognize in him the king, so much
sublimity and constancy resided in this unusual man!”
And the same writer says of his palace:—
“At Sans Souci there reigned such quiet that one might notice
every breath. My first visit to this lonely spot was of an evening in the
late fall. I was indeed surprised when I saw before me a small
mansion, and learned that in it lived the hero who had already
shaken the world with his name. I went around the entire house,
approached the windows, saw light in them, but found no sentry
before the doors, nor met a man to ask me who I was or what I
craved. Then first I understood the greatness of Frederick. He needs
for his protection not armed minions or firearms. He knows that the
love and respect of the people keep watch at the doors of his modest
abode.”
Frederick’s military genius was coupled with absolute control of
his country’s resources. Though Gustavus Adolphus was both
general and king, he was not an autocrat. The constitution of
Sweden prescribed his bounds. In ancient days, only Alexander
stood in the position of Frederick, and Cæsar, during the latter
portion of his campaigns. Hannibal was always limited in his
authority. Alexander, working in a far larger sphere, had personal
ambitions and a scope which Frederick lacked, yet each worked for
the good of his country. Frederick was not a conqueror. He fought to
defend his possessions. His military education was narrow; his
favorite studies and occupations essentially peaceful. But from
history he had sucked the ambition to make more powerful the
country which owed him allegiance, and he had digested the deeds
of the great commanders as only a great soldier can. Unconscious of
his own ability, necessity soon forced him to show what he was
worth. Like the Romans, he laid down one rule: Never wait for your
opponent’s attack. If you are on the defensive, let this be still of an
offensive character in both campaigns and battles. This rule he
followed through life.
Frederick most resembled Hannibal. He possessed Hannibal’s
virtue,—the secret of keeping a secret. He never divulged his plans.
From the start he was a captain, and so he remained to the end.
How did he learn his trade? Alexander and Hannibal learned theirs
under Philip and Hamilcar in Greece and Spain. Cæsar taught
himself in Gaul; Gustavus Adolphus, in Denmark, Russia, and
Poland. But Frederick had had no opportunities, except to learn the
pipe-clay half of the art of war. His five years’ retirement after his
court-martial must have done for him more than any one ever knew.
The fertility of his intelligence, and his power of applying what he
learned, were the foundation of his skill. His first campaign advanced
him more than a life of war does the greatest among others. The
First Silesian War was a school out of which Frederick emerged the
soldier he always remained.
That Frederick was not a warrior for the sake of conquest was
well shown in his moderation after the First Silesian War. He
demanded only his rights, as he understood them. And after the
Second Silesian, and the Seven Years’ War, he asked no more than
he got at the peace of Dresden, when he might have made far
greater claims. Indeed, Frederick’s whole life showed his preference
for the arts of peace. After the glamour of the first step had vanished,
war was but his duty to Prussia.
Frederick had assimilated the theory of war from the history of
great men; but its study was never a favorite pursuit. He was a born
soldier. As Cæsar taught himself from ambition, so Frederick taught
himself from necessity. What he did had not a theoretical but an
essentially practical flavor. He rose to the highest intellectual and
characteristic plane of the art, not by imitation of others, but by native
vigor. Frederick had by heart the lesson of Leuctra and Mantinæa,
but it required genius to apply the oblique order as he did it at
Leuthen. No man has ever so perfectly done this. No one in modern
times has had such troops.
Frederick placed war among the liberal arts. Perhaps the least
straight-laced of any captain, he held that only broad principles can
govern it; that the use of the maxims of war depends on the
personality of the soldier and the demands of the moment. His
“Instructions” to his generals set out Frederick’s whole art. It is full of
simple, common sense; apt rules, practical to the last degree. But it
was the man who made them so fruitful. Just because they do
represent the man they are interesting in this connection.
Frederick is the first writer on the military art who goes to the root
of the matter. He always wrote profusely,—most plentifully in bad
French verse,—but his “Instructions” are admirable throughout. At
the head of the paper stands this motto: “Always move into the field
sooner than the enemy;” and this was his course in campaign and
battle alike. He asked of the enemy a categorical yes or no to his
ultimatum, and upon no struck an instant blow. So novel was
Frederick’s quick decisiveness that he was at first looked upon in
Europe as a rank disturber of the peace. But his was only the old
Roman method revamped.
Underlying this rule was the good of Prussia. This motive he
ground into his men’s souls. He demanded as a daily habit
extraordinary exertions. His men must perform the unusual at all
times. And “from highest officer to last private, no one is to argue,
but to obey,” says he. A habit of obedience supplanted fear of
punishment. The king’s zeal flowed down through every channel to
the ranks. He was himself notoriously the hardest-worked man in
Prussia, and his men appreciated the fact.
Next in importance to discipline comes the care of the troops. In
his day subsistence tied armies down to predetermined manœuvres.
Frederick carried his rations with him, and in his rapid movements
made requisitions on the country, as Napoleon, a generation later,
did more fully.
Then follows the study of topography. Positions were to
Frederick only links in a chain, or resting places, but he ably utilized
the lay of the land in his battles. He taught his generals, wherever
they might be, to look at the surrounding country and ask
themselves, “What should I do if I was suddenly attacked in this
position?” He enunciated many maxims scarcely known at his day.
“If you divide your forces you will be beaten in detail. If you wish to
deliver a battle bring together as many troops as possible.” Frederick
did not try to keep everything, but put all his energy into the one
important matter. His was no hard and fast system. He did what was
most apt. His battle plans were conceived instantly on the ground.
What was intricate to others was simple to him and to the Prussian
army. Frederick held Hannibal up as a pattern. “Always,” said the
king, “lead the enemy to believe you will do the very reverse of what
you intend to do.”
Minor operations are clearly treated of. In general the motif of
these “Instructions” is attack and initiative. “Prussians,” said he, “are
invariably to attack the enemy.” Close with him even if weaker. Make
up for weakness by boldness and energy. He opposed passive
defence. Every one of his battles was offensive. He complained,
indeed, that he had to risk much all his life.
Frederick’s irrepressible courage under misfortune is equalled in
history only by Hannibal’s. Fortune was not his servant as she was
Alexander’s and Cæsar’s. He thanked himself for his good luck, or
rather his successes were due to the fact that he made use of good
luck when he had it, and threw no chances away. The magnificence
of his warlike deeds is traceable almost solely to his own mental
power and remarkable persistency. No danger or difficulty ever, in
the remotest degree, changed his purpose or affected his reasoning
power. It was this kept the ascendant on his side.
Despite sternest discipline, Frederick was familiar with his men,
who knew him as Vater Fritz, and bandied rough jokes with him.
“The Austrians are three to one of us, and stoutly entrenched,” said
the king, riding the outposts before Leuthen. “And were the devil in
front and all around them, we’ll hustle them out, only thou lead us
on!” answered a brawny grenadier. “Good-night, Fritz.” He gained
such personal love from his men that it seems to have been
transmitted as a heritage of the Hohenzollerns. He spurred his men
to the most heroic efforts, the most extraordinary feats of daring and
endurance. As the complement to this quality, he infused in his
enemies a dread of his presence. He utilized the mistakes they
made and led them into still others, less from any system than by
doing the right thing at the right moment. Strict rules aid only the
minds whose conceptions are not clear, and whose execution lacks
promptness. Rules were as nothing to Frederick. He observed them,
not because they were rules, but because they were grounded on
truths which his own mind grasped without them. He broke them
when there was distinct gain in so doing. His operations against six
armies surrounding him was based on his own maxim, that “Whoso
attempts to defend everything runs danger of losing everything,” and
he turned from one to the other, risking much to gain much. This idea
of Frederick’s was a novel one in his century, whose warfare
consisted in an attempt to protect and hold everything by fortresses
and partial detachments. In working out this idea he is
unapproached.
Frederick never allowed his enemies to carry out their own
plans. His movements imposed limitations upon them. He impressed
his own personality on every campaign. To carry his victuals with him
enabled him to outmanœuvre them, for his enemies relied
exclusively on magazines established beforehand. He could select
his routes according to the exigencies of the moment, while they
must keep within reach of their depots.
Tactically, Frederick stands highest of all soldiers. Strategically
he was less great. In strategic movements, his brother, Prince Henry,
did occasional work worthy to be placed beside the king’s. Tactically,
no one could approach him. His method of handling the three arms
was perfect.
Gustavus Adolphus had given new impulse to systematic,
intelligent war. But what he did was not understood. His imitators
jumbled the old and new systems. They placed too much reliance on
fortresses and magazines, and on natural and artificial obstacles;
they made strained efforts to threaten the enemy’s communications;
they manœuvred for the mere sake of doing something and apart
from any general plan; they avoided decisive movements and
battles.
Frederick, by making his armies less dependent on magazines,
acquired a freer, bolder, and more rapid style. The allies aimed to
parcel out Prussia. Frederick met them with decision. Surrounded on
all sides by overwhelming numbers, he was compelled to defend
himself by hard knocks. And his individual equipment as well as the
discipline of his army enabled him to do this with unequalled
brilliancy. In all history there is no such series of tactical feats as
Frederick’s.
Each captain must be weighed by the conditions under which he
worked. We cannot try Alexander by the standard of Napoleon.
While Napoleon’s battle tactics have something stupendous in their
magnificence, Frederick’s battles, in view of numbers and difficulties,
are distinctly finer. Frederick’s decisiveness aroused fresh interest in
battle. Manœuvres now sought battle as an object, while sieges
became fewer and of small moment.
All Europe was agog at Frederick’s successes, but no one
understood them. Lloyd alone saw below the surface. As Gustavus
had been misinterpreted, so now Frederick. Some imitated his
minutiæ down to the pig-tails of his grenadiers. Some saw the cure-
all of war in operations against the enemy’s flanks and rear. Some
saw in detachments, some in concentration, the trick of the king.
Only Lloyd recognized that it all lay in the magnificent personality of
the king himself, that there was no secret, no set rule, no
legerdemain, but that here again was one of the world’s great
captains. The imitators of Frederick caught but the letter. The spirit
they could not catch. Until two generations more had passed, and
Lloyd and Jomini had put in printed form what Frederick and
Napoleon did, the world could not guess the riddle.
His own fortresses were of importance to Frederick because his
enemy respected them. But he paid small heed to the enemy’s. He
could strike him so much harder by battle, that he never frittered
away his time on sieges, except as a means to an end. The allies
clung to their fortified positions. Frederick despised them, and
showed the world that his gallant Prussians could take them by
assault.
This period, then, is distinguished for the revival of battles, and
of operations looking towards battle. Of these Frederick was the
author. Battles in the Seven Years’ War were not haphazard. Each
had its purpose. Pursuit had, however, not yet been made effective
so to glean the utmost from victory. No single battle in this period
had remarkable results. Frederick’s battles were generally fought to
prevent some particular enemy from penetrating too far into the
dominions of Prussia. In this they were uniformly successful. But in
the sense of Napoleon’s battles they were not decisive. The superior
decisiveness of Napoleon’s lay in the strategic conditions and in his
superiority of forces. No battles—as battles—could be more
thoroughly fought out than Frederick’s; no victories more brilliant.
Frederick not only showed Europe what speed and decision can
do in war, but he made many minor improvements in drill, discipline,
and battle-tactics. He introduced horse-artillery. His giving scope to
such men as Seydlitz and Ziethen made the Prussian cavalry a
model for all time. He demonstrated that armies can march and
operate continuously, with little rest, and without regard to seasons.
Light troops grew in efficiency. War put on an aspect of energetic
purpose, but without the ruthless barbarity of the Thirty Years’ War.
No doubt Napoleon, at his best, was the greater soldier. But
Napoleon had Frederick’s example before him, as well as the
lessons of all other great captains by heart. Napoleon’s motive was
aggressive; Frederick’s, pure defence. Hence partly the larger
method. But Frederick in trial or disaster was unspeakably greater
than Napoleon, both as soldier and man.
In the forty-six years of his reign Frederick added sixty per cent.
to the Prussian dominion, doubled its population, put seventy million
thalers in its treasury, and created two hundred thousand of the best
troops in existence. Prussia had been a small state, which the
powers of Europe united to parcel out. He left it a great state, which
all Europe respected, and planted in it the seed which has raised its
kings to be emperors of Germany. This result is in marked contrast
to what Napoleon’s wars did for France.
Whoever, under the sumptuous dome of the Invalides, has
gazed down upon the splendid sarcophagus of Napoleon, and has
stepped within the dim and narrow vault of the plain old garrison
church at Potsdam, where stand the simple metal coffins of
Frederick the Great and of his father, must have felt that in the latter
shrine, rather than the other, he has stood in the presence of the
ashes of a king.
Whatever may be said of Frederick’s personal method of
government, or of the true Hohenzollern theory that Prussia
belonged to him as an heritage to make or to mar as he saw fit, it
cannot be denied that he was true to the spirit of his own verses,
penned in the days of his direst distress:—

“Pour moi, menacé du naufrage,


Je dois, en affrontant l’orage,
Penser, vivre et mourir en Roi.”
LECTURE VI.
NAPOLEON.

THE career of Napoleon Bonaparte is so near to our own times and


so commonly familiar, that it is not essential to describe any of those
operations which were, within the memory of some men yet living,
the wonder and dread of Europe. In certain respects Napoleon was
the greatest of all soldiers. He had, to be sure, the history of other
great captains to profit by; he had not to invent; he had only to
improve. But he did for the military art what constitutes the greatest
advance in any art, he reduced it to its most simple, most perfect
form; and his and Frederick’s campaigns furnished the final material
from which Jomini and his followers could elucidate the science; for it
has taken more than two thousand years of the written history of war
to produce a written science of war.
I shall not touch upon Napoleon’s life as statesman or lawgiver,
nor on his services in carrying forward the results of the Revolution
toward its legitimate consequence,—the equality of all men before
the law. In these rôles no more useful man appears in the history of
modern times. I shall look at him simply as a soldier.
Napoleon’s career is a notable example of the necessity of
coexistent intellect, character, and opportunity to produce the
greatest success in war. His strength distinctly rose through half his
career, and as distinctly fell during the other half. His intellectual
power never changed. The plan of the Waterloo campaign was as
brilliant as any which he ever conceived. His opportunity here was
equal to that of 1796. But his execution was marred by weakening
physique, upon which followed a decline of that decisiveness which
is so indispensable to the great captain. It will, perhaps, be
interesting to trace certain resemblances between the opening of his
first independent campaign in 1796, and his last one in 1815, to
show how force of character won him the first and the lack of it lost
him the last; and to connect the two campaigns by a thread of the
intervening years of growth till 1808, and of decline from that time
on.
When Napoleon was appointed to the command of the Army of
Italy he had for the moment a serious problem. In this army were
able and more experienced officers of mature powers and full of
manly strength, who looked on this all but unknown, twenty-seven
years old, small, pale, untried commander-in-chief, decidedly
askance. But Napoleon was not long in impressing his absolute
superiority upon them all. They soon recognized the master-hand.
The army lay strung out along the coast from Loano to Savona,
in a worse than bad position. The English fleet held the sea in its
rear, and could make descents on any part of this long and ill-held
line. Its communications lay in prolongation of the left flank, over a
single bad road, subject not only to interruption by the English, but
the enemy, by forcing the Col di Tenda, could absolutely cut it off
from France. The troops were in woful condition. They had neither
clothing nor rations. They were literally “heroes in rags.” On the
further side of the Maritime Alps lay the Austrian general, Beaulieu,
commanding a superior army equally strung out from Mount Blanc to
Genoa. His right wing consisted of the Piedmontese army under Colli
at Ceva; his centre was at Sassello; with his left he was reaching out
to join hands with the English at Genoa. Kellerman faced, in the
passes of the Alps, a force of twenty-five thousand Sardinians, but
for the moment was out of the business.
1796.
Napoleon spent but few days in providing for his troops, and
then began to concentrate on his right flank at Savona. He knew that
his own position was weak, but he also divined from the reports
brought in from the outposts that the enemy’s was worse. From the
very start he enunciated in his strategic plan the maxim he obeyed
through life: Move upon your enemy in one mass on one line so that
when brought to battle you shall outnumber him, and from such a
direction that you shall compromise him. This is, so to speak, the
motto of Napoleon’s success. All perfect art is simple, and after
much complication or absence of theoretical canons from ancient
times to his, Napoleon reduced strategy down to this beautifully
simple, rational rule.
Nothing in war seems at first blush so full of risk as to move into
the very midst of your enemy’s several detachments. No act in truth
is so safe, if his total outnumbers yours and if you outnumber each of
his detachments. For, as always seemed to be more clear to
Napoleon and Frederick than to any of the other great captains, you
can first throw yourself upon any one of them, beat him and then turn
upon the next. But to do this requires audacity, skill, and, above all,
tireless legs. And success is predicated in all cases on the
assumption that God is on the side of the heaviest battalions.
So Napoleon, who was very familiar with the topography of Italy,
at once determined to strike Beaulieu’s centre, and by breaking
through it, to separate the twenty-five thousand Piedmontese in the
right wing from the thirty-five thousand Austrians in the left wing, so
that he might beat each separately with his own thirty-seven
thousand men.
Beaulieu’s reaching out toward Genoa facilitated Napoleon’s
manœuvre, for the Austrian would have a range of mountains
between him and his centre under Argenteau, whom he had at the
same time ordered forward on Savona via Montenotte. Napoleon’s
manœuvre was strategically a rupture of Beaulieu’s centre. Tactically
it first led to an attack on the right of Argenteau’s column. The details
of the manœuvre it would consume hours to follow. Suffice it to say
that by a restless activity which, barring Frederick, had not been
seen in war since the days of Cæsar, Napoleon struck blow after
blow, first upon Argenteau, throwing him back easterly, then on Colli,
throwing him back westerly, absolutely cut the allies in two, fought
half a dozen battles in scarce a greater number of days, and in a
short fortnight had beaten the enemy at all points, had captured
fifteen thousand prisoners, fifty guns, and twenty-one flags.
Still the problem was serious. Beaulieu, if active, could shortly
concentrate one hundred thousand men. Napoleon must allow him
not a moment of breathing spell. He issued a proclamation to his
troops which sounds like the blare of a trumpet. It set ablaze the
hearts of his men; it carried dread to his enemies, and Napoleon
followed it up by a march straight on Turin. Alarmed and
disconcerted, the King of Sardinia sued for peace. Napoleon
concluded an armistice with him, and thus saw himself dis-
embarrassed of the enemy’s right wing and free to turn on the left
under Beaulieu. His columns were at once launched on Alexandria,
and by his skilful manœuvres and unparalleled alertness he soon got
the better of the Austrians. He had at a stroke made himself the most
noted general of Europe. The rest of the campaign was equally
brilliant and successful.
Napoleon had shown his army that he commanded not by the
mere commission of the Directory, but by the divine right of genius.
He had not only taken advantage of every error of his opponents, but
had so acted as to make them commit errors, and those very errors
of which he had need. His army had been far from good. But “I
believe,” says Jomini, “that if Napoleon had commanded the most
excellent troops he would not have accomplished more, even as
Frederick in the reversed case would not have accomplished less.”
We recognize in this first independent campaign of Napoleon the
heroic zeal of Alexander, the intellectual subtlety of Hannibal, the
reckless self-confidence of Cæsar, the broad method of Gustavus,
the heart of oak of Frederick. But one fault is discoverable, and this,
at the time, was rather a virtue,—Napoleon underrated his
adversary. By and by this error grew in the wrong direction, and
became a strong factor in his failures.
Through the rest of this campaign, which numbered the victories
of Lodi, Castiglione, Bassano, Arcole, the most noteworthy thing
except his own personal diligence is the speed with which Napoleon
manœuvred his troops. To state an instance: from September 5 to
September 11, six days, Napoleon’s men fought one pitched battle
and two important combats and marched, Masséna eighty-eight
miles, Augereau ninety-six miles, and the other corps less distances.
He was far from being uniformly lucky. He had many days of serious
backsets. But whenever luck ran in his favor, he seized it and made
it useful; when against him, he gamely strove to stem its tide. If
Fortune frowned, he wooed her unceasingly till she smiled again.
The campaign which began in April, 1796, really lasted till April,
1797. Napoleon pushed the Austrians out of Italy and well back
towards Vienna. His triumphs culminated in the brilliant victory of
Rivoli, and his success at the truce of Leoben. At Rivoli, with thirty
thousand men, Napoleon defeated the enemy and captured twenty
thousand prisoners. The men who had left Verona and fought at San
Michele on the 13th of January, marched all night to Rivoli, there
conquered on the 14th, and again marching to Mantua, some thirty
miles, compelled Provera to lay down his arms on the 15th.
Napoleon could rightfully boast to have equalled Cæsar in speed of
foot.
The men of the Revolution had cut loose from eighteenth century
methods of warfare by rising en masse and putting the personal
element into the scale. But it was reserved for Napoleon to substitute
a new method for the old. From Nice to Leoben he showed the world
what modern war can do. He made himself independent of
magazines, as Frederick had done but rarely. With a smaller army he
always had more men at the point of contact. This was Napoleon’s
strongest point. He divined what his enemy would do, not from his
tent but from the saddle, seeing with his own eyes and weighing all
he saw and heard. He was every day and all day long in motion; he
rode unheard-of distances. He relied on no one but himself, as, with
his comparatively small army, he could well do; and correctly seeing
and therefore correctly gauging circumstances, he had the courage
to act upon his facts. He sought battle as the result of every
manœuvre. The weight of his intellect and his character were equally
thrown into all he did. And his abnormal ambition drove him to
abnormal energy. In this his first campaign and in one year, with
moderate forces, he had advanced from Nice to within eighty miles
of Vienna, and had wrung a peace from astonished Austria.
Napoleon next undertook the Egyptian campaign. His ambition
had grown with success. But matters in France were not in a
condition of which he could personally avail, and he believed he
could increase his reputation and power by conquests in the East.
His imagination was boundless. Perhaps no great soldier can be free
from imagination, or its complement, enthusiasm. Napoleon had it to
excess, and in many respects it helped him in his hazardous
undertakings. At this time he dreamed himself another Alexander
conquering the Eastern world, thence to return, as Alexander did not,
with hordes of soldiers disciplined by himself and fanatically attached
to his person, to subjugate all Europe to his will. The narration of this
campaign of sixteen months may be made to sound brilliant; its
result was miscarriage. It is full of splendid achievements and
marred but by one mishap,—the siege of Acre. But the total result of
the campaign was failure to France, though gain to Napoleon, who
won renown, and, abandoning his army when the campaign closed,
returned to Paris at a season more suited to his advancement.
Napoleon’s military conduct in this campaign shows the same
marvellous energy, the same power of adapting means to end, of
keeping all his extraordinary measures secret, the better to impose
on the enemy by their sudden development, the same power over
men. But the discipline of the army was disgraceful. The plundering
which always accompanied Napoleon’s movements—for, unlike
Gustavus and Frederick, he believed in allowing the soldier freedom
beyond bounds if only he would march and fight—was excessive.
The health of the army was bad; its deprivations so great that suicide
was common to avoid suffering which was worse. And yet Napoleon,
by his unequalled management, kept this army available as a tool,
and an excellent one.
Napoleon now became First Consul. The campaign of 1800 was
initiated by the celebrated crossing of the Alps. This feat, of itself,
can no more be compared, as it has been, to Hannibal’s great
achievement, nor indeed to Alexander’s crossing the Paropamisus,
than a Pullman excursion to Salt Lake City can be likened to Albert
Sidney Johnston’s terrible march across the Plains in 1857.
Napoleon’s crossing was merely an incident deftly woven into a
splendid plan of campaign. From Switzerland, a geographical salient
held by them, the French could debouch at will into Italy or Germany.
Mélas, the Austrian general in Italy, had his eyes fixed upon
Masséna in Genoa. A large reserve army was collected by Napoleon
in France, while Moreau pushed toward the Danube. Mélas naturally
expected that the French would issue from Provence, and kept his
outlook towards that point. When Napoleon actually descended from
the Great St. Bernard upon his rear, he was as badly startled as
compromised. This splendid piece of strategy was followed up with
Napoleon’s usual restless push, and culminated in the battle of
Marengo. This was at first a distinct Austrian victory, but good
countenance, Mélas’ neglect to pursue his gain, and Napoleon’s
ability to rally and hold his troops until absent Dessaix could rejoin
him, turned it into an overwhelming Austrian defeat. And Napoleon,
by the direction given to his mass, had so placed Mélas that defeat
meant ruin. He was glad to accept an armistice on Napoleon’s own
terms.

MARENGO CAMPAIGN
This superb campaign had lasted but a month, and had been
characterized by the utmost dash and clearness of perception. Again
Napoleon’s one mass projected on one properly chosen line had
accomplished wonders.
Napoleon once said to Jomini, “The secret of war lies in the
secret of communications. Keep your own and attack your enemy’s
in such a way that a lost battle may not harm you, a battle won may
ruin your adversary. Seize your enemy’s communications and then
march to battle.” Napoleon’s success came from study of the
situation. His art was founded on an intimate knowledge of all the
facts, coupled with such reasoning power as enabled him to gauge
correctly what his enemy was apt to do. Without the art the study
would be useless. But the art could not exist apart from study.
After Marengo there were five years of peace. These and the
four years between Wagram and the Russian campaign were the
only two periods of rest from war in Napoleon’s career. Succeeding
this came the memorable Austerlitz campaign. Napoleon had had for
some months three of his best officers in Germany studying up
topography, roads, bridges, towns, in the Black Forest region and
toward the Tyrol and Bohemia. To thus make himself familiar with the
status was his uniform habit.

Ulm-Austerlitz Campaign
Napoleon, now Emperor, was at Boulogne, threatening and
perhaps at times half purposing an invasion of England. He
commanded the best army he ever had. The Austrians, not
supposing him ready, inundated Bavaria with troops, without waiting
for their allies, the Russians, and marched up the Danube to the Iller,
under Field-Marshal Mack. Napoleon put an embargo on the mails,
broke up from Boulogne at twenty-four hours’ notice, and reached
the vicinity of the enemy with an overwhelming force before Mack
was aware of his having left the sea. His line of march was about
Mack’s right flank, because this was the nearest to Boulogne and
gave him a safe base on the confederate German provinces. So well
planned was the manœuvre, so elastic in its design for change of
circumstances, that it fully succeeded, step for step, until Mack was
surrounded at Ulm and surrendered with his thirty thousand men.
Here again we find the Napoleonic rule fairly overwhelming Mack
with superior numbers. Except in 1796 and 1814, Napoleon always
had more men than the enemy on the field at the proper time. “They
ascribe more talent to me than to others,” he observed, “and yet to
give battle to an enemy I am in the habit of beating, I never think I
have enough men; I call to my aid all that I can unite.”
The chart herewith given of the grand manœuvre of Ulm is so
simple as to suggest no difficulties of execution. But there is
probably nothing in human experience which taxes strength,
intellect, judgment, and character to so great a degree as the
strategy and logistics of such a movement, unless it be the tactics of
the ensuing battle. The difficulties are, in reality, gigantic.
Napoleon headed direct for Vienna, and on the way absolutely
lived on the country. “In the movements and wars of invasion
conducted by the Emperor, there are no magazines; it is a matter for
the commanding generals of the corps to collect the means of
victualling in the countries through which they march,” writes Berthier
to Marmont. Napoleon took Vienna and marched out towards Brünn,
where the Austrians and Russians had concentrated. Here he was
far from secure, if equal talent had been opposed to him; but he took
up a position near Austerlitz, from which he could retreat through
Bohemia, if necessary, and, calmly watching the enemy and allowing
several chances of winning an ordinary victory to pass, he waited,
with an audacity which almost ran into braggadocio, for the enemy to
commit some error from which he could wrest a decisive one. And
this the allies did, as Napoleon divined they would do. They tried to
turn his right flank and cut him off from Vienna. Napoleon massed his
forces on their centre and right, broke these in pieces, and won the
victory of which he was always most proud. Napoleon’s conduct here
showed distinctly a glint of what he himself so aptly calls the divine
part of the art.
There is always a corresponding danger in every plan which is of
the kind to compass decisive results. In this case Napoleon risked
his right wing. But to judge how much it is wise to risk and to guess
just how much the enemy is capable of undertaking is a
manifestation of genius.
The era of the great battles of modern war dates from Austerlitz.
Marengo was rather two combats than one great battle. Frederick’s
battles were wonders of tactics and courage, but they differ from the
Napoleonic system. In Frederick’s battles the whole army was set in
motion for one manœuvre at one time to be executed under the
management of the chief. If the manœuvre was interrupted by
unforeseen events, the battle might be lost. In Napoleon’s system,
the centre might be broken and the wings still achieve victory; one
wing might be crushed while the other destroyed the enemy. A bait
was offered the enemy by the exhibition of a weak spot to attract his
eye, while Napoleon fell on the key-point with overwhelming odds.
But in this system the control passed from the hand of the leader. All
he could do was to project a corps in a given direction at a given
time. Once set in motion, these could not readily be arrested. Such a
system required reserves much more than the old method. “Battles
are only won by strengthening the line at a critical moment,” says
Napoleon. Once in, Napoleon’s corps worked out their own
salvation. He could but aid them with his reserves.
There is a magnificence of uncertainty and risk, and
corresponding genius in the management of the battles of Napoleon;
but for purely artistic tactics they do not appeal to us as do
Frederick’s. The motif of Alexander’s battles is more akin to
Napoleon’s; that of Hannibal’s, to Frederick’s.
It has been said that Napoleon never considered what he should
do in case of failure. The reverse is more exact. Before delivering a
battle, Napoleon busied himself little with what he would do in case
of success. That was easy to decide. He busied himself markedly
with what could be done in case of reverse.
Like all great captains, Napoleon preferred lieutenants who
obeyed instead of initiating. He chafed at independent action. This
was the chief’s prerogative. But as his armies grew in size he gave
his marshals charge of detail under general instructions from himself.
Dependence on Napoleon gradually sapped the self-reliance of more
than one of his lieutenants, and though there are instances of noble
ability at a distance from control, most of his marshals were able
tacticians, rather than great generals. Napoleon grew impatient of
contradiction or explanation; and he sometimes did not learn or was
not told of things he ought to know. He was no longer so active.
Campaigning was a hardship. His belief in his destiny became so
strong that he began to take greater risks. Such a thing as failure did
not exist for him. His armies were increasing in size, and railroads
and telegraphs at that day did not hasten transportation and news.
The difficulties he had to contend with were growing fast.
These things had the effect of making Napoleon’s military plans
more magnificent, more far-reaching. But all the less could he pay
heed to detail, and from now on one can, with some brilliant
exceptions, perceive more errors of execution. In the general
conception he was greater than ever, and this balanced the scale.
His ability to put all his skill into the work immediately in hand was
marvellous. But with a vast whole in view, the parts were, perhaps of
necessity, lost sight of.
The campaigns of 1806 and 1807 were in sequence. To move on
the Prussians, who, under the superannuated Duke of Brunswick,
were concentrated in Thuringia, Napoleon massed on his own right,
disgarnishing his left, turned their left,—in this case their strategic
flank, because the manœuvre cut them off from Berlin and their
allies, the Russians,—and with overwhelming vigor fell on the
dawdling enemy at Jena and Auerstädt. The Prussians had
remained stationary in the art of war where they had been left by
Frederick, and had lost his burning genius.

You might also like