Blockchain Engineering Playbook 2024
Blockchain Engineering Playbook 2024
Engineering
Playbook
2024
Rohas Nagpal
Version 1.4 dated 1 January 2024
This book is part of the Official Courseware of the
free Blockchain Engineering Program
conducted by Rohas Nagpal.
1. Blockchain Basics..............................................................8
1.1 Blockchain Nodes..........................................................14
1.2 Mining...............................................................................17
1.3 Layers of a Blockchain Network................................18
1.4 Types of Blockchains....................................................20
1.5 Blockchain Consensus Mechanisms.........................23
1.6 Blockchain Bridges........................................................27
1.7 Blockchain Metrics........................................................30
1.8 Merged Mining................................................................32
1.9 Blockchain Forks...........................................................34
1.10 Blockchain Addresses................................................36
1.11 Blockchain Wallets.....................................................38
1.12 Blockchain Record-keeping Models........................42
1.13 Asset Tokenization......................................................44
1.14 Smart Contracts..........................................................49
1.15 Blockchain use-cases.................................................52
2. Blockchain APIs...............................................................56
5. Bitcoin................................................................................92
6. Ethereum...........................................................................97
7. Multichain.......................................................................105
8. HYFI Blockchain............................................................120
9. Hyperledger....................................................................133
Rohas Nagpal
Chief Blockchain Architect,
Hybrid Finance Blockchain
(HYFI)
6
(c) 2023-24 Rohas Nagpal. All rights reserved.
9
Conceptual Image of a Blockchain Network
10
While Blockchains have a linear chronological
structure, Distributed Ledger Technologies (DLTs) can
have different structures, such as:
11
12
13
1.1 Blockchain Nodes
14
A conceptual overview of a Blockchain Node
15
Archival Full Nodes
They are the most important. They host the entire
blockchain, validate blocks & maintain consensus.
Master nodes
Users run masternodes to earn network rewards. Some
amount of native tokens have to be "locked" by
masternode operators.
Light nodes
A light node does not hold the full copy of the
blockchain. It saves download time & storage space by
only downloading block headers.
Cold nodes
They are used for signing transactions offline and
storing private keys away from the network.
Lightning nodes
They reduce the load on the network by enabling
off-chain transactions. These nodes enable faster and
cheaper transactions.
16
1.2 Mining
17
1.3 Layers of a Blockchain Network
18
19
1.4 Types of Blockchains
Layer-0 Blockchains
20
Layer-1 Blockchains
Layer-2 Blockchains
Permission-less blockchains
Permissioned blockchains
21
Federated blockchains
EVM-compatible chains
22
1.5 Blockchain Consensus
Mechanisms
Proof-of-Work (PoW)
This was the world’s first consensus algorithm. Miners
"solve" mathematical puzzles by investing in electricity
and computational power e.g. Bitcoin.
23
Proof-of-Work-Time (PoWT)
This features a variable blocktime that scales with
mining power. The blockchain speeds up with power
increases. This mechanism scales the blockchain well
and increases transaction speed with power.
Proof-of-replication (PoRep)
Storage miners prove 2 things:
● that they are using space to store replicas of
data,
● that the data can easily be accessed.
24
Delegated Proof of Stake (DPoS)
Holders "lock" a number of coins as a "stake" but
outsource validation to "delegates" selected based on
reputation and trustworthiness e.g. Bitshares.
Proof-of-Spacetime (PoSt)
Randomly selected miners prove that they have been
physically storing data for a certain period of time e.g.
Filecoin.
Proof-of-burn (PoB)
Miners reach a consensus by sending coins to an
"eater" or "burn" address. This permanently eliminates
coins from circulation, reduces inflation, and validates
transactions e.g. Slimcoin.
Proof-of-Authority (PoA)
Identified, known, and credible validators produce
blocks in this system. It is meant for private &
enterprise blockchains.
25
This mindmap shows 82 blockchain consensus
mechanisms divided into 9 categories.
26
1.6 Blockchain Bridges
27
In simple terms, here's how a typical bridge works:
28
Ronin worked "off-chain" - it interfaced with the
blockchain but existed on external servers that were
not a part of the blockchain.
29
1.7 Blockchain Metrics
Throughput
Throughput is the number of transactions per second
that a Blockchain consensus algorithm can process.
Finality
Finality (also called Latency) represents the time it
takes for a transaction to be settled in the "ledger" of a
blockchain.
Scalability
Scalability is the ability of a blockchain to expand
without degrading performance.
Bitcoin
● Throughput: 7 tps
● Threshold: 51%
● Finality: 60 min
30
Ethereum Mainnet
● Throughput: 14 tps
● Threshold: 51%
● Finality: 6 min
Polkadot
● Throughput: 1500 tps
● Threshold: 33%
● Finality: 60 secs
31
1.8 Merged Mining
32
Merged Mining increases the profitability and
performance of mining and is hugely beneficial for
miners.
33
1.9 Blockchain Forks
Hard Fork
Soft Fork
Ethereum Fork
34
But a hacker exploited a bug in the "smart contract"
and siphoned out all the money!
35
1.10 Blockchain Addresses
b5ba96aae89dc703c27ec5b3d478a8b176b874f248c8
3e533d9edc18e6356d44
36
This is what happens in most crypto ‘hacks’.
That's why we say that "Not your keys, not your coins".
Sample WIF
L3Jy6k2KCJ6uDNEj1hirw49sPWghT7Cg77rSDvfpAkA
C7F63PhGe
Sample Address
1AAE1EDcCAUmyBfi46G3vpik8oCaKVoabT
37
1.11 Blockchain Wallets
38
Paper wallets are inconvenient to use but are the
safest option. Consider using them if you have a large
number of crypto assets to keep for a long period of
time.
Site: https://www.bitaddress.org
39
Hardware wallets are a little pricey and there’s always
the risk of losing or breaking them.
40
So remember to back up the seed phrase - a bunch of
words that you can write down. Example:
history
lumber
quote
board
young
dove
robust
kit
invite
plastic
regular
skull
41
1.12 Blockchain Record-keeping Models
43
1.13 Asset Tokenization
44
1. What are Illiquid Assets?
Examples:
45
6. Real Estate: Properties including residential,
commercial, industrial, and agricultural.
2. What is Tokenization?
46
4. Bringing liquidity to markets that are traditionally
illiquid.
47
Download the
Tokenization Playbook by Rohas Nagpal
rohasnagpal.com/docs/Tokenization_Playbook.pdf
48
1.14 Smart Contracts
Smart contracts:
● financial transactions,
● supply chain management,
● digital identity,
● legal agreements.
49
Here's the code for a very basic smart contract called
"HelloWorld".
50
● The constructor function executes automatically
when the contract is first deployed. In this case, it
sets the initial value of the "message" variable to
"Hello, World!".
51
1.15 Blockchain use-cases
52
● Electronic health record management
● Digital evidence management system
● Public service delivery
● Blockchain for social good use cases (charity,
donations)
● Metering and settlement
● Payment security mechanism
● Authentication and authorization services
● Automated control of decentralized power
● Smart grid application and grid management
● Microfinance for Self-Help Groups (SHG)
● Customs and trade finance
● Cross border trade
● Renewable energy trading and management
● Insurance underwriting and claims management
● Aggrotech environment
● Micro-financing, financing small businesses or
individuals
● Secured logistics document exchange (SLDE)
● Cold chain for supply chain
● National and state highways, toll collection,
tracking of public infrastructure
● Blockchain for urban development tracking
through Public Private Partnership
● Tracking the progress on climate agreement
through Blockchain
53
● Asset transfer across different government
departments
● Digital identities, and verifiable credentials to
secure privacy and enable new use cases
● Safe and secure vaccine distribution and
administration
● IoT device management and security
● Vehicle lifecycle management
● Chit fund operation and administration
54
55
02
Blockchain
API
2. Blockchain API
Start with this video:
https://www.youtube.com/live/mX-WNX3C6VQ?featur
e=share&t=52
1. Private Key
57
A private key can be represented in multiple formats:
2. Public Key
58
3. Address
60
6. Hierarchical Deterministic Wallets
{
"address":
"0xa7673161CbfE0116A4De9E341f8465940c2211d4"
}
https://gist.github.com/rohasnagpal/c791fd4573e8408
8437688a4859ae673#file-generate-private-key
{"key":"cMotAJwwC3hruht3gYKBBLm9kUhEWvfovDTL
GPy4biyNbR2VBXLG"}
62
Sample BTC HD Wallet:
https://www.rohasnagpal.com/web3/files/hd_wallet_bt
c.php
63
03
Network
Security
& Privacy
3.1 Blockchain Network Attacks &
Vulnerabilities
51% Attack
Sybil Attack
Eclipse Attack
Routing Attack
Replay Attack
Timejacking Attack
66
Phishing Attacks
67
3.2 Node Security Best Practices
Securing a blockchain node is essential to maintain the
integrity of the overall network and to protect the
information stored within the node.
68
❏ Role-Based Access Control: Use Role-Based
Access Control (RBAC) to limit who can access
what resources. It should be ensured that users
and applications only have the permissions that
they need and nothing more.
69
❏ Patch Management: Regularly apply security
patches to all software. Unpatched software can
be a security vulnerability.
70
3.3 Network Monitoring Tools
Network monitoring is an essential part of maintaining
a healthy and secure blockchain node.
Wireshark
Nagios
Zabbix
71
Prometheus
Netdata
IFTOP
72
TCPdump
73
3.4 Privacy Enhancing Technologies
Privacy Enhancing Technologies (PETs) are designed to
uphold data minimization principles and allow
individuals to retain control and ownership of their
personal data.
Ring Signatures
74
Coin Mixing or CoinJoin
Mimblewimble
Homomorphic Encryption
75
Secure Multi-Party Computation (sMPC)
Tor/I2P Networks
76
Download the Blockchain Security Controls from:
https://www.rohasnagpal.com/docs/blockchain-security/blockc
hain_security_controls.pdf
77
04
Node Maintenance
& Performance
Optimization
4.1 Blockchain Data Storage and
Management
In a blockchain network, data storage and management
is a crucial aspect of maintaining efficient operations
and reliability.
Blockchain Structure
On-Chain Storage
79
Off-Chain Storage
Sharding
80
Pruning
State Channels
Database Management
Backups
81
A combination of these techniques can be used
depending on the specific use case and requirements.
82
4.2 Node Performance Metrics
Node performance metrics help in understanding the
overall health and efficiency of a blockchain node.
Memory Usage
CPU Usage
Disk Usage
84
Uptime
85
4.3 Performance Tuning &
Optimization
Performance tuning and optimization for a blockchain
node involves identifying and resolving issues that
hinder its efficiency and reliability. Here are some
strategies:
Hardware Upgrade
OS Optimization
Database Optimization
86
Node Configuration
Sharding
Off-Chain Transactions
Pruning
87
Network Optimization
88
4.4 Backup & Disaster Recovery
Backup and disaster recovery are crucial aspects of
maintaining a reliable and resilient blockchain node.
Regular Backups
Offsite Storage
Secure Storage
Redundancy
Failover Mechanisms
Backup Software
Documentation
90
Node Software Backups
91
05
Bitcoin
If blockchain technology were a religion, the Bitcoin
whitepaper would be its Bible.
https://www.youtube.com/watch?v=3BBRF1XgjTE&t=75s
93
94
Setting up a Bitcoin node
95
This file allows you to set various parameters, such as
enabling RPC (Remote Procedure Call) for interacting
with your node.
96
06
Ethereum
Ethereum is NOT a blockchain. It's NOT a
cryptocurrency either! It's actually a protocol (a set of
rules or procedures) like "HTTP" or "HTTPS".
Ethereum standards
ERC-20
99
ERC-721
ERC-777
ERC-1155
100
ERC-4626
Others
For a detailed list of Ethereum Token Standards, see:
https://github.com/PhABC/ethereum-token-standards-l
ist
101
102
Setting up an Ethereum node
103
After installation, open a terminal or command prompt.
3. Creating an Account
104
07
Multichain
Multichain is a framework for creating permissioned
blockchains.
● https://www.multichain.com/download-community
● https://www.multichain.com/developers/creating-co
nnecting
106
Practical 2: Addresses & Permissions
https://www.youtube.com/live/mZk1K0NEUyw?feature
=share&t=102
getnewaddress
Returns a new custodial address whose private key is
added to the wallet.
getaddresses true
Returns a list of addresses in this node’s wallet with
more information about each address,
107
getaddresses false
Returns a list of addresses in this node’s wallet.
listaddresses
Returns information about the addresses in the wallet.
createkeypairs
validateaddress
108
importaddress
connect
to connect to other nodes and see the blockchain’s
contents
send
to send funds
receive
to receive funds
issue
to create new native assets
create
to create data streams
109
mine
to create blocks
activate
to change connect, send and receive permissions for
other users
admin
to change all permissions for other users, including
issue, mine, activate and admin
listpermissions
Returns a list of all permissions which have been
explicitly granted to addresses.
110
Practical 3: Smart Asset Management
listpermissions issue
listaddresses
111
If there is no address with issue permissions, you can
give an address this permission using this:
Depending upon the use case, the issue from and issue
to addresses can be the same.
112
● Can open and Can close: Whether to allow the
asset to be closed and/or (re)opened for future
issuance using the update command.
113
See the sample code for issuing this asset:
https://gist.github.com/rohasnagpal/610a906ff2954fe7
2c5f14b6959d8b11
listassets
displays details of all assets
listassets <identifier>
Displays details of asset having the specified:
● Name e.g. Cessna-Skyhawk-172.8
● Issuance transaction ID e.g. 269-266-32631
● Asset reference number e.g.
777feac622d9af4c5ae91f8cdb62f3575e3153093
0feecf839e9febaa8567f63
or
or
update
777feac622d9af4c5ae91f8cdb62f3575e31530930feecf
839e9febaa8567f63 '{"open":true}'
114
115
Step 5: Issue more tokens (Optional)
issuemorefrom
1WQ65QwRZFyvUDhUDFKTHBgPqEYvA1C5vRNxyU
1WQ65QwRZFyvUDhUDFKTHBgPqEYvA1C5vRNxyU
Cessna-Skyhawk-172.8 2500 0 '{"Metadata":"Reasons
for issuing more tokens e.g. token split"}'
Examples:
116
Practical 4: Atomic Exchange Transactions
https://www.multichain.com/developers/atomic-excha
nge-transactions
117
Production blockchain parameters
118
Cold nodes and wallets
119
08
HYFI Blockchain
Hybrid Finance Blockchain (HYFI) is a Legally-compliant
Permissioned Layer-1 Blockchain for the Tokenization
of Real World Assets (Authentication, Provenance,
Fractional Ownership, and Trading).
Website: https://www.hyfiblockchain.com/
121
3. How HYFI provides Enhanced Privacy:
As a permissioned blockchain, HYFI members have
control over who can access the network. This helps to
keep sensitive data confidential.
122
8.2 Legal & regulatory compliance
Hybrid Finance (HYFI) Blockchain supports regulatory
compliance in 7 ways:
123
3. How HYFI supports CFT (Countering the Financing
of Terrorism)
124
Role-based asset controls allow for business,
compliance, and regulatory oversight.
125
2. The P2P connections in HYFI Blockchain are fully
encrypted, preventing intermediate routers from
seeing any private data.
126
8.4 HYFI Scalability Features
Some of the scalability features of Hybrid Finance
(HYFI) Blockchain are:
127
6. The scalability of the HYFI Blockchain is
improved through Selective Stream Indexing and
Selective Data Retrieval.
128
8.6 Integrating HYFI with other
applications
Hybrid Finance (HYFI) Blockchain can be integrated
with other applications through its unified JSON-RPC
API.
129
By providing a simple and flexible API, HYFI enables
developers to create a wide range of custom
applications, from simple web interfaces to complex
decentralized applications (dApps), that can interact
with the blockchain in a secure and efficient manner.
130
Data streams provide a mechanism for organizing &
managing data within the blockchain in a secure and
scalable manner, making it possible for a wide range of
use cases, including but not limited to, content
distribution, copyright licensing, and secure data
sharing.
131
Smart Filters are written in JavaScript and run within a
deterministic version of Google’s V8 JavaScript engine,
which is embedded directly within MultiChain 2.
1. HYFI Nodes
2. Addresses
3. Tokenizing Assets on HYFI Blockchain
4. Transactions
132
09
Hyperledger
Hyperledger is an open-source initiative for growing
enterprise use of blockchain technologies.
Distributed Ledgers
Libraries
134
Tools
135
Hyperledger Besu
136
Hyperledger Fabric
137
Hyperledger Indy
138
Hyperledger Iroha
139
Hyperledger Sawtooth
140
AnonCreds
141
Aries
142
Transact
143
Ursa
144
Bevel
145
Cacti
146
Caliper
147
Cello
148
Firefly
149
Solang
150
10
Blockchain & Web3
Tech Stack
1. Akash Network
2. Alchemy
152
● Mempool Visualizer enables troubleshooting
transactions that may be delayed, stuck or
dropped in the mempool.
3. API3
4. Aragon
Aragon App is a simple, modular and adaptable DAO
platform.
153
Aragon Client is a DAO platform for communities to
raise funds, pay contributors, and govern together.
Aragon Voice is a gasless and universally verifiable
voting solution for web3.
5. Arweave
6. Audius
154
Audius is built on both Ethereum and Solana.
7. Band Protocol
155
● Content creators earn ad revenue, user
contributions, and tips.
9. Chainlink
156
How can a smart contract get data from the outside
world? That's the problem that Oracles solve. They act
as middleware between smart contracts and external
sources of data.
157
LINK is the crypto token that is used for paying
Chainlink node operators for providing oracle services.
12. Drizzle
158
13. Ethereum Name Service
14. Filecoin
159
Filecoin is integrated with Ethereum. This enables
developers to access Ethereum blockchain data and
interact with Ethereum smart contracts.
15. Ganache
160
16. Gnosis Safe
161
The Helium network is a decentralized wireless
network. It enables IoT devices to wirelessly connect to
the Internet and geolocate themselves without satellite
location hardware or cellular plans.
18. Infura
19. IPFS
162
Traditional URLs & file paths identify a file by where it's
located.
Examples:
https://www.rohasnagpal.com/web3/index.html
file:///Users/sanyanagpal/Documents/hyfi.pdf
163
20. Livepeer
21. Moralis
164
22. NuCypher
24. Ontology
25. OpenZeppelin
165
OpenZeppelin Defender manages smart contract
administration including access controls, upgrades, and
pausing. It Works with popular multi-sigs including
Gnosis Safe.
166
28. Sia
167
Step 3: Files are sent to hosts using smart contracts -
Storage renters enter into file contracts (smart
contracts) with hosts for pricing, uptime commitments,
etc. Service Level Agreements (SLAs) are stored on the
Sia blockchain and automatically enforced by the
network.
29. Steemit
168
31. Theta
169
32. TokenTerminal
33. Truffle
170
This video covers:
1. Web Storage
2. Web Workers
3. Server-Sent Events
4. Hash calculations
5. Password Security using Salt & Pepper
6. Cryptographically strong pseudorandom number
generator (CSPRNG)
7. Encryption & Decryption
https://www.youtube.com/live/68u-GVvdbds?feature=
share&t=74
171
11
ChatGPT
Super Prompt
Templates
ChatGPT Super Prompt Templates
Here are some ChatGPT super prompt templates that
you can customize and use:
173
2. Building scalable decentralized applications (dApps)
174
4. Suggesting improvements to existing blockchain
systems
175
6. Choosing blockchain consensus mechanisms
176
8. Implementation of blockchain-based payment
systems
177
10. Design & implementation of blockchain-based
gaming systems
178
12. Simulating a Bitcoin node
179
12
Interview
Questions
12.1 Blockchain Basics
1. How would you explain blockchain technology to
someone without a technical background?
181
12.2 Blockchain APIs
1. Can you explain what a Blockchain API is and
how it differs from traditional APIs?
182
8. How do Blockchain APIs handle scalability and
efficiency issues, especially in systems with high
transaction volumes?
183
12.4 Node Maintenance &
Optimization
1. What are some key considerations for blockchain
data storage and management?
12.5 Bitcoin
1. Can you explain what Bitcoin is and how it differs
from traditional fiat currencies?
184
5. Can you explain the process of a Bitcoin
transaction from one wallet to another? What
role do private and public keys play in this?
12.6 Ethereum
1. Can you explain what Ethereum is and how it
differs from Bitcoin?
185
4. How does Ethereum's consensus mechanism
work?
12.7 Multichain
1. Can you explain what MultiChain is and how it
differs from Ethereum and Hyperledger?
186
3. What are some key features of MultiChain that
make it suitable for enterprise blockchain
applications?
188
12.9 Hyperledger
1. Can you explain what Hyperledger is and how it
differs from other blockchain platforms like
Ethereum?
190
13
Quiz
Questions
BEP-1. Which of these Blockchain performance
indicators represents the transactions per second that
a consensus algorithm can process?
192
BEP-4. Which of these Blockchain performance
indicators represents the ability for a network to
expand without degrading performance?
A. Layer-0 Blockchains
B. Layer-1 Blockchains
C. Layer-2 Blockchains
A. Blockchain Frameworks
B. Cosmos & Horizen
A. Layer-0 Blockchains
B. Layer-1 Blockchains
C. Layer-2 Blockchains
193
BEP-8. Which type of blockchain nodes enable faster
and cheaper transactions?
A. Cold nodes
B. Light nodes
C. Lightning nodes
A. True
B. False
A. Nodes
B. Smart contracts
194
BEP-12. In which type of Blockchain fork does each
node need to upgrade its software to be compatible
with the new processes?
A. Hard Fork
B. Soft Fork
A. Light nodes
B. Lightning nodes
A. Cold nodes
B. Lightning nodes
A. Blockchain Frameworks
B. Layer-2 Blockchains
195
BEP-16. Which of these consists of the hardware,
software, and networks that enable the functioning of a
blockchain?
A. Infrastructure Layer
B. User Interface Layer
A. Application Layer
B. User Interface Layer
A. Trusted
B. Trustless
196
BEP-20. Which of these enables fungible Ethereum
tokens to be re-used by other applications such as
wallets and decentralized exchanges?
A. ERC-20
B. ERC-721
A. ERC-918
B. ERC-1178
A. True
B. False
A. ERC-10
B. ERC-777
197
BEP-24. Which standard outlines a smart contract
interface that can represent any number of fungible
and non-fungible token types?
A. ERC-1203
B. ERC-1155
A. ERC-1178
B. ERC-1203
A. True
B. False
198
BEP-28. Which is a structure where every address gets
its own chain that only it can write to, and everyone
holds a copy of all of the chains?
A. Block-lattice
B. Proof of Zero
C. VeriBlock
A. Hashgraph
B. Magi's POS
C. Raft
A. Proof of Process
B. Proof of Stake Boo
C. Proof of Work
199
BEP-32. The goal of which of these blockchain attacks
is to perform a double spend?
A. 51% Attack
B. Sybil Attack
A. 51% Attack
B. Sybil Attack
A. 51% Attack
B. DDOS Attack
C. Sybil Attack
A. 51% Attack
B. DDOS Attack
C. Sybil Attack
A. 51% Attack
B. Eclipse Attack
200
14
Quiz
Answers
BEP-1: D BEP-2: A BEP-3: B
202
Credits
● Cover image: https://www.freepik.com
● https://blockchainblog.substack.com
● https://ethereum.org
● https://bitcoin.org
● https://blog.coinbase.com/a-simple-guide-to-the-
web3-developer-stack-8364b612d69c
● https://alchemy.com/blog/web3-stack
● https://en.bitcoin.it
● https://www.multichain.com
203