Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Rust for Blockchain Application Development
Rust for Blockchain Application Development

Rust for Blockchain Application Development: Learn to build decentralized applications on popular blockchain technologies using Rust

eBook
$20.98 $29.99
Paperback
$36.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Rust for Blockchain Application Development

Blockchains with Rust

Blockchains have a lot of mystery around them, and only a few engineers have complete clarity of the inner workings and how disruptive they will be to the incumbent way of working for many industries.

With the help of this chapter, we want to tackle the very core concepts of blockchains. Since this is a book about using Rust for blockchains, we want to, at the same time, understand why Rust and blockchains are a match made in heaven. This will also provide us with insight into why some popular blockchains (Solana, Polkadot, and NEAR) have used Rust and why the latest blockchains to enter the market (Aptos and Sui) are also choosing Rust above any other technology that exists on the market today.

The end goal of this chapter is to provide a comprehensive understanding of the critical concepts around blockchains that will enable us to build a blockchain from scratch later in the book.

In this chapter, we’re going to cover the following main topics:

  • Laying the foundation with the building blocks of blockchains
  • Exploring the backbone of blockchains
  • Understanding decentralization
  • Scaling the blockchain
  • Introducing smart contracts
  • The future of the adoption of blockchains

Laying the foundation with the building blocks of blockchains

In this section, let's learn the most basic concept of blockchains—what a blockchain is made up of.

A blockchain can be imagined as a series of connected blocks, with each block containing a finite amount of information.

The following diagram demonstrates this clearly with multiple connected blocks.

Figure 1.1 – Representation of a blockchain

Figure 1.1 – Representation of a blockchain

Just like in a traditional database, there are multiple tables in which the data is stored sequentially in the form of records, and the blockchain has multiple blocks that store a particular number of transactions.

The following diagram demonstrates blocks as a store for multiple transactions:

Figure 1.2 – Blocks with transaction data

Figure 1.2 – Blocks with transaction data

The question now is, why not just use databases? Why do we even need blockchains? Well, the main difference here is that there is no admin and nobody is in charge. The other significant difference is that most blockchains are engineered to be permissionless at the core (even though permissioned blockchains exist and have specific use cases at the enterprise level), making them accessible to everyone and not just to people with access.

Another equally substantial difference is that blockchains only have insert operations, whereas databases have CRUD operations, making blockchains inherently immutable. This also implies that blockchains are not recursive in nature; you cannot go back to repeat a task on records while databases are recursive.

Now, this is a complete shift in how we approach data storage with blockchains in comparison to traditional databases. Then there is decentralization, which we will learn about shortly and that is what makes blockchains an extremely powerful tool.

Web 3.0, another confusing and mysterious term, can, at a considerably basic level, be defined as the internet of blockchains. Until now, we have had client-server architecture applications being connected to each other. That was Web 2.0, but suddenly, with the help of blockchains, we will have a more decentralized internet. Even if most of this does not make sense right now, do not despair, for we have plenty to cover.

In the following subsections, we will learn about things such as hashes, transactions, security, decentralized storage, and computing.

Blocks

The smallest or atomic part of any blockchain is a block. We learned in the previous section that blocks contain transactions, but that’s not all; they also store some more information. Let’s peel through the layers.

Let's look at a visual representation of the inner workings of a block:

Figure 1.3 – Connected blocks of a blockchain

Figure 1.3 – Connected blocks of a blockchain

In the preceding diagram, we notice that the first block is called the Genesis Block, which is an industry-standard term for the first block of the chain. Now, apart from transaction data, you also see a hash. In the next section, Hashes, we will learn how this hash is created and why it is required. For now, let's consider it to be a random number. So, each block has a hash, and you will also notice that the blocks are storing the previous hash. This is the same as the hash of the previous block.

The previous hash block is critical because it is what connects the blocks to each other. There is no other aspect that connects the blocks to make a blockchain; it’s simply the fact that a subsequent, sequential block holds the hash of the previous block.

We also notice a field called nonce. This stands for number only used once. For now, we need to understand that the nonce needs to be consistent with the hash for the block to be valid. If they’re not consistent, the following blocks of the blockchain go completely out of sync and this fortifies the immutability aspect of blockchains that we will learn about in detail in the Forking section. Now, as we go further, we will uncover more layers to this, but we’re at a great starting point and have a broad overview.

Hashes

Hashes are a core feature of the blockchain and are what hold the blocks together. We remember from earlier that blocks store hash and previous hash and hashes are simply created by adding up all the data, such as transactions and timestamps, and passing it through some hashing algorithm. One example is the SHA-256 algorithm.

The following diagram shows a visual representation of data being passed to the SHA-256 algorithm and being converted into a usable hash:

Figure 1.4 – Data to SHA-256 hash

Figure 1.4 – Data to SHA-256 hash

A hash is a unique fixed-length string that can be used to identify or represent a piece of data and a hash algorithm, such as SHA-256, is a function that computes data into a unique hash.

While there are several other SHA algorithms available (such as SHA-512), SHA-256 stands as the most prevalent choice within blockchains due to its robust hash security features and the notable fact that it remains unbroken to this day.

There are four important properties of the SHA-256 algorithm:

  • One-way: The hash generated from SHA-256 is 256 bits (or 32 bytes) in length and is irreversible; if you want to get the plaintext back (plaintext being the data that we passed through SHA-256), you will not be able to do so.
  • Deterministic: Every time you send a particular data through the algorithm, you will get the same predictable result. This means that the hash doesn’t change for the same data.
  • Avalanche effect: Changing one character of the data, completely changes the hash and makes it unrecognizable.
  • For example, the hash for abcd is

    88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589

    but the hash for abce is

    84e73dc50f2be9000ab2a87f8026c1f45e1fec954af502e9904031645b190d4f.

  • The only thing common between them is that they start with 8. There’s nothing else that matches, so you can’t possibly predict how the algorithm represents a, b, or c, and you can’t work your way backward to either get the plaintext data or predict what the hash representation for some other data will look like.
  • Withstand collision: Collision in hashing means the algorithm produces the same hash for two different values. SHA-256 has an extremely low probability of collision, and this is why it’s heavily used.

All of these properties of the SHA-256 are the reason why blockchains are the way they are.

Let’s understand the effect that these properties have by going over the following few points:

  • Irreversibility translates into immutability in blockchains (transaction data, once recorded, can’t be changed)
  • Determinism translates into a unique, identifiable hash that can identify a user, wallet, transaction, token, or account on the blockchain (all of these have a hash)
  • The avalanche effect translates into security, making the system extremely difficult to hack since the information that’s encrypted can’t be predicted by brute force (running multiple computers to estimate incrementally, starting with a hypothesis)
  • Collision tolerance leads to each ID being unique and there being an extremely high mathematical limit to the unique hashes that can be produced, and since we require hashes to represent various types of information on the blockchain, this is an important functionality

In this section, we have seen how the properties of blockchains actually come from the hashing algorithms, and we can safely say that it’s the heart and soul of a blockchain.

Transactions

Because of the previously mentioned properties of blockchains, storing financial data is one of the biggest use cases that blockchains are used for, as they have advanced security requirements.

A transaction is showcased through unspent cryptocurrency, or unspent transaction output (UTXO). This refers to unused coins owned by individuals logged on the blockchain for transparency. It’s essential to recognize that while UTXO is a key element in certain blockchains such as Bitcoin, it’s not a universal feature across all blockchain platforms.

The following diagram helps us visualize all the fields in a transaction:

Figure 1.5 – The contents of a blockchain transaction

Figure 1.5 – The contents of a blockchain transaction

Let’s go through all the fields that form a Bitcoin transaction:

  • Version: This specifies which rules the transaction follows
  • Input counter: This is the number of inputs in the transaction (this is just a count)
  • Inputs: This is the actual input data
  • Output counter: This is similar to the input counter, but it’s for keeping a count of the transactions’ output
  • Output: This is the actual output data from the transaction
  • Blocktime: This is simply a Unix timestamp that records when the transaction happened.

Initially, blockchains were primarily designed to record financial transactions within the realm of cryptocurrencies. However, as they evolved, blockchains demonstrated their versatility by finding applications beyond this initial purpose. Soon, we’ll delve into these additional uses.

But for now, it is important to understand that when we mention transactions, it does not strictly mean financial or currency-related transactions. Rather, in modern blockchains, a transaction is anything that changes the state of the blockchain, so any program that runs or any information that’s stored is simply a transaction.

Security

So, the main selling point for blockchains is that they’re extremely secure. Now, let’s understand why this is so:

  • All the records are secured with cryptography thanks to the SHA-256 algorithm.
  • The records and other blockchain data are copied to multiple nodes; we will learn about this in the Peers, nodes, validators, and collators section. Even if the data gets deleted in one node, it doesn’t mean that it’s deleted from the blockchain.
  • To participate as a node in the blockchain network, requiring ownership of private keys is essential. Private keys and secret codes known only to you, grant access to control your cryptocurrency holdings, sign transactions, and ensure security. Possessing private keys safeguards your digital assets and enables engagement in network activities.
  • Nodes need to come to a consensus on new data to be added to the blockchain. This means bogus data and corrupted data cannot be added to the blockchain, as it could compromise the entire chain.
  • Data cannot be edited on the blockchain. This means the information you have stored cannot be tampered with.
  • They’re decentralized and don’t have a single point of failure. The bigger the network or the more decentralized the network, the lower the probability of failure.

We will learn about nodes, decentralization, validation, and consensus later on in this book, and all these points will be clearer.

Storage versus compute

Bitcoin introduced blockchain for the storage of financial transactions, but Ethereum took things a bit further and helped us imagine what it could be like if you could run programs on a blockchain. Hence, the concept of smart contracts was created (we will dig deeper into smart contracts later in this chapter, but you can think of them as code that can run decentralized on the blockchain).

Independent nodes could join a network for the blockchain and pool their processing power in the network.

According to Ethereum, they’re building the biggest supercomputer in the world. There are two ways to build the biggest supercomputer— build it centralized, where all machines will exist centrally in one location, or build a decentralized version where thousands of machines can be connected over the internet and divide tasks among themselves.

Ethereum enables you to process programs on the blockchain. This means anyone on the internet can build a smart contract and publish it on the blockchain where anyone else across the world can interact with the program.

This is the reason we see so many startups building their products on the Ethereum chain. After Ethereum, blockchains such as Solana, NEAR, and Polkadot have taken this idea much further and brought many new concepts by improving on Ethereum. This book is going to deal with all three of these blockchains.

Exploring the backbone of blockchains

This section is a deep dive into what makes blockchains so special. We will cover topics such as decentralization, forking, and mining, and we will understand how peers interact in a network and how the blocks are validated. Let’s dive in.

Decentralization

From a purely technical standpoint, Web 1.0 started with a client-server architecture, usually monoliths. When traffic and data started increasing, the monolithic architecture couldn’t scale well. Then, with Web 2.0, we had concepts such as microservices and distributed systems,which helped not only scale systems efficiently but also enhanced resilience and robustness, reduced failure instances, and increased recoverability.

The data was still centralized and private and the systems were mostly centralized, meaning they still belonged to a person/company and admins could change anything. The drawbacks were the following:

  • A failure at the company’s end took the system down
  • Admins could edit the data and block users and content from platforms
  • Security was still not prioritized, leading to easy data hacks, although this could vary depending on the company’s approach to safeguarding information
  • All the data generated on the platform belonged to the platform
  • Content created and posted on a platform became the property of the platform

Web 3.0 ushers in a new age of decentralization that is made possible with blockchains where the entire blockchain data is copied to all the nodes. But even distributed systems had nodes and node recovery, so the question is, how is this any different?

Well, in the case of distributed systems, the nodes still belonged to the centralized authority or the company that owned the platform, and nodes were essentially their own servers in a private cloud. With decentralized systems, the node can be owned by another entity, person or a company other than the company that developed the blockchain.

In fact, in a blockchain network, having nodes owned by different companies is encouraged and this increases the decentralization of the network, meaning there is no real owner or authority that can block content, data, or users out and the data is accessible to all the nodes since all of them can store a copy of the data.

Even if one node goes down, there are others to uphold the blockchain, and this makes the system highly available. Advanced communication protocols among the nodes make sure the data is consistent across all the nodes.

Nodes are usually monetized to stay in the network and to uphold the security of the network (we will read more about this in the next section). Nodes also need to come to a consensus regarding the next block that’s to be added to the chain. We will also read more about consensus shortly.

Peers, nodes, validators, and collators

In this section, we will further build upon the knowledge we have gained in the past few sections. A blockchain does not exist in isolation; it is a peer-to-peer network, and all full nodes save the complete copy of the blockchain, while some blockchains also permit other types of nodes that maintain state without necessarily possessing a full copy.

In the following diagram, we see this in a visual format:

Figure 1.6 – Multi-node networks

Figure 1.6 – Multi-node networks

So, let’s dig a layer deeper. Nodes are listening to events taking place in the network. These events are usually related to transactions. It is important to reiterate that a transaction is anything that changes the state of the system.

As we know, a block contains the information of multiple transactions.

The following diagram shows a block with some example transactions:

Figure 1.7 – Transactions finalized to a block

Figure 1.7 – Transactions finalized to a block

Once a new block is added by a node, which is known as mining, this new event is advertised to the entire network. This is visually represented in the following diagram:

Figure 1.8 – The created block is advertised

Figure 1.8 – The created block is advertised

Once the new block is advertised, the rest of the nodes act as validators that confirm the outputs of the transactions once the block has been validated by the rest of the nodes. The nodes come to a consensus that yes, this is the right block that needs to be added to the chain. We can visualize this with the help of the following diagram:

Figure 1.9 – Other nodes validate the block data

Figure 1.9 – Other nodes validate the block data

The new block is then copied to the rest of the nodes so that all of them are on the same page and added to the independent chains being maintained at each node. This can be seen in the following diagram:

Figure 1.10 – A block gets finalized

Figure 1.10 – A block gets finalized

Once the blocks are added to the node, and the blockchain at each node is updated on any other node. Another block could be listening to all the new transactions that have happened, and these are then collated onto a block and the entire process then repeats.

The following criteria vary from blockchain to blockchain in terms of the following:

  • The number of transactions that the block will store
  • The mechanism that nodes use to collate the transactions (time-based or number-based)
  • The validation mechanism
  • The consensus mechanisms

Contemporary chains improved upon the Bitcoin and Ethereum blockchains by varying and innovating on either all or some of these criteria, but the consensus mechanism is something that is most often innovated upon. This is done to try and save the time required for new nodes to be added and copied by the entire network, which is what really slows down the network.

We learned earlier that the nodes need to be incentivized to stay in the network and keep adding the blocks to the chain. In chains such as Ethereum, this is achieved using gas fees, which are simply small fees that users pay to carry forward their transactions. We know that blocks can contain only a few transactions, and if the users want their transactions to get priority, they need to pay gas fees.

The gas fee depends on what other users are willing to pay to get their transactions forwarded; the higher the gas fee, the higher the chance of getting your transaction accepted. Think of gas fees as the rent that the nodes get paid for the users to use the nodes’ processors to process and validate their transactions. The words peers and nodes are used interchangeably, and validators and collators can also be used interchangeably depending on the blockchain you are on.

Consensus

In the last section, we learned that a node listens to transaction events, collates these transactions, and creates a block. This is called mining. After a block is mined, other nodes need to validate it and come to a consensus.

In this section, we want to peel the layers of consensus to understand it deeply. Understanding the mechanics behind some popular consensus mechanisms will help us to learn by running through actual examples, rather than learning in an abstract way. So, let’s understand some of these concepts:

  • Proof of work (PoW): Nodes need to solve a particular cryptography problem (we will look at this in detail in the Mining section), and the node with the highest processing power is usually able to solve faster than others. This keeps the system decentralized but increases electricity consumption by a huge amount. It’s not considered to be very efficient and is even considered bad for the environment, as it increases power wastage since all the nodes are up against each other trying to solve the problem. Examples are Bitcoin, Litecoin, and Dogecoin.
  • Proof of authority (PoA): This is a consensus mechanism in blockchain where transactions and blocks are verified by identified validators, typically chosen due to their reputation or authority. Unlike energy-intensive mechanisms such as PoW, PoA offers efficiency by requiring validators to be accountable for their actions. It’s commonly used in private or consortium blockchains, ensuring fast transactions and reducing the risk of malicious activities. However, PoA’s centralized nature may raise concerns regarding decentralization and censorship resistance compared to other consensus methods.
  • Proof of stake (PoS): Nodes need to buy stakes in the network—basically, they buy the cryptocurrency native to the network. Only a few nodes with a majority stake get to participate in the mining activity in some cases. This is highly power efficient, and this is the reason why Ethereum recently switched from PoW to PoS. However, it is considered to be less decentralized, as only the nodes with enough resources get to add the next blocks and it can be seen that some big players have been slowly taking ownership of the majority of the network since Ethereum switched to PoS. The main benefit of PoS is that since nodes have a stake in the system, they are de-incentivized to add unscrupulous blocks to the chain. Since the copy of the chain exists with all the nodes of the entire network, the nodes are running the software of the blockchain where the output hashes need to be consistent with the rest of the chain. Hence, when a node tries to add the wrong block, the rest of the nodes do not validate this block, and if such a scenario takes place, these nodes are then penalized where the amount of native cryptocurrency owned by the node that is taken away can differ depending on the seriousness of the violation. Generally, this penalty entails a partial loss of funds rather than a complete forfeiture of all holdings. Some examples are Cardano, Ethereum, and Polkadot.
  • Proof of burn (PoB): Burning is a process where cryptocurrency is sent to a wallet address from which it’s irrecoverable. The nodes that can burn the highest amount of cryptocurrency get to add a node. Miners must invest in the blockchain to demonstrate their commitment to the network. Even though PoB is the most criticized consensus model, it can actually be highly effective for some blockchains that want to ensure deflationary tokenomics. Slimcoin is an example of PoB.
  • Proof of capacity: In this consensus mechanism, the nodes with the highest storage space get to add a node. This means that the nodes that partake in the network can use their hard drive space to compete with each other to win the mining rights. An example is Permacoin.
  • Delegated PoS: Participants in the network, such as end users buying cryptocurrency, can stake their coins in a pool, and the pool belongs to a particular node that can add blocks to a chain. The more tokens you stake, the bigger your payout. Examples are EOS, BitShares, and TRON.

In this section, we’ve developed a rich understanding of consensus mechanisms, and this will help us throughout the book, especially while building the blockchain.

Mining

By now, we have a very basic idea of what mining is and why it’s necessary. In this section, we will dive into the specifics of mining. Mining happens quite differently in different consensus mechanisms. We will look at mining for the two major consensus mechanisms: PoW and PoS. For instance, in PoS, let’s consider the example of Ethereum 2.0, where validators are chosen to create new blocks and secure the network based on the amount of cryptocurrency they hold and are willing to “stake” as collateral.

In a PoW blockchain, to add a block to the blockchain, a cryptographic problem needs to be solved. The node that comes up with the solution first gets to win the competition. This means that nodes with the highest computational power usually win and get to add a block.

The blockchain’s cryptography challenge adjusts in complexity over time to ensure consistent block creation. Nodes predict a specific hash, focusing on a segment that aligns with the existing blockchain, maintaining chain coherence.

Nodes employ a nonce, a unique value, to address the challenge. Incrementing from zero, this value is adjusted until a matching hash is computed, pivotal for generating a valid hash in line with the network’s rules.

Solving the cryptographic problem validates transactions and creates new blocks. A successful node broadcasts its solution, swiftly verified by others. The first to find a valid solution is rewarded with newly minted cryptocurrency, incentivizing participation and bolstering network security.

The following diagram shows the different fields that add up to produce a hash:

Figure 1.11 – All the data that makes up a hash

Figure 1.11 – All the data that makes up a hash

Now, this means the following:

  • This can only be solved with brute forcing, iterating from zero to a particular number, and cannot be solved smartly
  • All the nodes in the network compete with each other regardless of whether they ever win, and this means a lot of computational energy gets wasted
  • Nodes need to keep upgrading their computational power to win the competition

Now that we understand what mining is and how it works, it’s time to learn about forking—an important blockchain concept.

Forking

There is one small detail about blockchains that we have talked about but haven’t discussed in detail yet, and that’s immutability. In one of the earlier sections, we learned how SHA-256’s properties translate into immutability for blockchains. This means all transactions that happen on-chain are immutable, and tokens once sent from one account to another cannot be reversed unless an actual transaction is initiated from the second account.

In traditional payment systems, this is not the case. If money is sent to the wrong account by mistake, this can be reversed, but this feature has been manipulated by centralized authorities and therefore immutable transactions are valued highly.

Let’s take as an example the decentralized autonomous organization (DAO) attack in 2016 that led to $50 million being stolen from the Ethereum blockchain due to a code vulnerability. The only way to reverse this was to create an entire copy of the chain where this particular transaction didn’t take place. This process of creating a different version chain is simply called forking. This event divided the blockchain between Ethereum and Ethereum Classic.

The following diagram demonstrates what forking looks like:

Figure 1.12 – Forks in a blockchain

Figure 1.12 – Forks in a blockchain

Forking also comes into use when rules for the blockchain need to be modified. Traditional software gets upgraded and new updates and patches are applied, whereas the way to upgrade a blockchain is to fork (though some blockchains such as Polkadot have invented mechanisms to have forkless upgrades).

Forks typically occur intentionally, but they can also happen unintentionally when multiple miners discover a block simultaneously. The resolution of a fork takes place as additional blocks are appended, causing one chain to become longer than the others. In this process, the network disregards blocks that are not part of the longest chain, labeling them as orphaned blocks.

Forks can be divided into two categories: soft forks and hard forks.

A soft fork is simply a software upgrade for the blockchain where changes are made to the existing chain, whereas with a hard fork, a new chain is created and both old and new blockchains exist side by side. To summarize, both forks create a split, but a hard fork creates two blockchains.

Permissioned versus permissionless

Blockchains can be permissionless or permissioned depending on the use case. A permissionless blockchain is open to the public with all transactions visible, but they may be encrypted to hide some crucial details and information if required. Anyone can join the network, become a node, or be a validator if the basic criteria are met. Nodes can become a part of the governing committee as well once they can meet additional requirements, and there are no restrictions on who can join the network. You can freely join and participate in consensus without obtaining permission, approval, or authorization.

Most of the commonly known blockchains, such as Ethereum, Solana, and Polkadot, are all permissionless chains and are easily accessible. Their transaction data is publicly available. So, a perfect use case for permissionless chains is hosting user-facing and user interaction-based applications.

Permissioned chains have gatekeepers that define a permission, approval, or authorization mechanism that only a few pre-authorized nodes can operate. So, to be a part of the permissioned blockchain network, you may need a special set of private keys and may also need to match some security requirements. Since the nodes copy the entire data of the chain and are also involved in adding blocks to the chain and being a part of the governing committee for the blockchains, some use cases where data and information need to be kept private can use permissioned chains.

The following diagram shows the difference between a public and a private blockchain network:

Figure 1.13 – Permissioned versus permissionless chains

Figure 1.13 – Permissioned versus permissionless chains

Governments, institutions, NGOs, and traditional corporations have found plenty of use cases for permissioned chains, where only a few actors trusted by the centralized authorities are permitted to join the network. Permissioned blockchains also have multiple business-to-business use cases and may be centrally stored on a single cloud provider.

Blockchains help us decentralize computing and resources, and we have been using the word decentralization quite often. In the next section, we will understand the concept of decentralization in more depth.

Understanding decentralization

Decentralization is the guiding principle for Web 3.0. It’s designed to create a win–win environment for the builders of a platform, the people that build on the platform decentralized applications (dApps), and the people that interact with the platform (users of dApps).

Let’s try and understand why decentralization is so important. In 2013, Twitter had a centralized developers platform where developers could use their APIs to build apps on the Twitter platform. A few years later, Twitter stopped the API support and also brought in a few restrictions, and every few months, the API’s terms and conditions would change. This affected many app developers who were either banned from the platform due to the restrictions or were unable to stay up to date with the changing terms for API usage.

Similarly, Facebook had an app developer program as well, which many developers built their apps with. However, developers faced similar problems here as well, and this problem is quite common wherever a centralized platform is involved. Play Store and App Store can ban any app from their platform, and Amazon can decide which sellers can sell and Uber can decide which drivers get more rides.

The issue is not just about getting banned from the platform and the policy changes, but it’s also about monetization. For example, the Apple App Store can take about 30% of the entire revenue from app developers. To prevent institutions, banks, and governments from curbing the freedom of individuals and communities, decentralization is a popular solution that ensures everyone gets a voice and a few owners of the platform do not end up controlling the entire platform.

It’s shared ownership where the ownership of the platform is not held closely by the founding team or the committee; rather, it belongs to the community at large where each user can hold tokens and gets a say in the system. We will read about this further in the DAOs section.

A blockchain network implements decentralization in a highly efficient manner, and this is why it’s the primary technology for a decentralized use case.

So, now that we have a clearer understanding of decentralization, let’s dig into some of the concepts that are closely related with decentralization that make it possible.

Replication

Replication is at the core of decentralization. Multiple copies of the same data exist at different participatory nodes. If one of the copies gets corrupted, there are other copies to reference the final state of the data. If one of the participatory nodes fails completely, there are mechanisms by which a new node can be appointed to take its place, and this ensures that the entire network can’t go down easily.

Even if the network does go down, recoverability is way easier when the data is replicated as opposed to having a centralized store of data. In decentralized systems, both the data and the power to govern the system can also be decentralized. This means that multiple nodes that have access to and copies of the data or that simply have a stake in the network can come to a consensus on the new data that gets added and how the network behaves/can be improved.

This leads us to the next important topic of governance.

Governance

Every blockchain follows a unique way of governance, but, in general, blockchains are governed by token holders that can be users, developers, investors, the founding team, or nodes. Governance tokens are issued to reward the loyalty of token holders and are usually issued when they have a high stake in the network. Owners of governance tokens can propose changes and vote for the implementation of those changes to the protocol.

Each governance token is equal to one vote, so this leads to a very fair and just system, as the holders with more stake in the network get more influence. The details of each vote are publicly available for all to see. Blockchain networks sometimes suffer from the whale problem, where some network participants end up holding most of the tokens. This can lead to the network becoming more centralized than expected. In most cases, whales end up being the founding team, and votes are cast to push the agenda of the founding team. This ends up centralizing the network.

For a blockchain network to be more effective, it is important to ensure a fair distribution of tokens to ensure decentralization. Governance usually aims to ensure that the blockchains update continuously and the protocols align with the right direction. However, it’s worth noting that in certain cases, due to the influence of governance token holders, updates might not occur, potentially causing a divergence from the intended path.

Cryptocurrencies and gas fees

In the earlier sections, we read about cryptocurrencies and gas fees, and now that we have preliminary knowledge of blockchains, it’s a great time to understand this topic even better. We will look at cryptocurrencies and gas fees from a slightly different perspective to get a more wholesome understanding of the topic.

Cryptocurrency is simply a currency that’s cryptographically secure and is backed by a blockchain. Since a hashing algorithm is used to create hashes in a blockchain and this secures the blockchain cryptographically, using blockchains to store currency-related financial information makes a currency a cryptocurrency.

Blockchain can be thought of as a distributed ledger, and therefore it is referred to as distributed ledger technology (DLT). This is where a ledger is being maintained for the transactions that are being recorded, but also, multiple copies of the ledger exist with different nodes.

Since multiple copies of this ledger exist with multiple different nodes, the nodes must commit their storage space for this ledger. We also learned that when the blocks are mined, substantial processing power is utilized (PoW). This implies that nodes also need to commit processors along with storage space.

Since in this section we have focused on decentralization, it is important to understand that the higher the number of independent nodes that maintain a copy of the ledger and participate in the mining of new blocks, the more decentralized the network is. Hence, it makes it more trustworthy for developers and users to either build on this or interact with it respectively.

To keep the nodes incentivized to dedicate substantial storage and processing resources to the network, we need to pay them a fee or reward them with new tokens, which is simply gas fees. We’ve read a little about this in the previous sections.

The gas fee is paid out to the nodes in simply the native cryptocurrency of the blockchain. For blockchains to be effective, a coin that represents some limited digital asset is introduced. Please note that coins and tokens have various similarities, but they also have differences, and we will learn about them in one of the later sections.

In this section, we have filled in many gaps in our knowledge. It is now clear to us that for blockchains to be effective, they need to be decentralized, and for them to be decentralized, they need to have more nodes in the network. If we’d like the nodes to dedicate resources, they need to be incentivized, and if they want to be incentivized, we need them to have some monetary benefit that can be created with the help of a coin. This is a cryptocurrency, as it is secured by a blockchain for which security originates from a hashing algorithm. This is a cryptography hashing algorithm, hence the term cryptocurrency. While the compensation given to nodes for their role in maintaining the system and keeping the records safe is referred to as a gas fee.

Decentralized platforms

In traditional Web 2.0 platforms, the data, as soon as uploaded or created by the users, legally belongs to the platform. Every time a user logs into a traditional Web 2.0 platform, the request for authentication is sent to the centralized server with a centralized database, both of which are entirely owned by the platform. The platform can decide if a user can stay on the platform or is asked to leave. This centralizes ownership and control.

Now, the platform has complete ownership rights over all the data that is generated by the users that use the platform.

Since the platform is the owner of the data, the platform is responsible and is also incentivized to keep the data secure.

But since the data is users’ data, it’s actually the users that stand to lose the most when the data actually gets hacked or stolen.

We have seen this pattern multiple times in the past; platforms get hacked often and user data is stolen and sold by hackers for a small profit.

So, even though the platform is incentivized to secure the data, the platform doesn’t really stand to lose much when it’s stolen, and therein lies the problem.

In addition to this, the platforms also sell this data themselves to third parties or use the data for advertising to these users, sometimes without consent. This further deteriorates the user experience and trust in the platform.

Web 3.0 re-imagines this model; the data instead stays with the user and they can choose to hold it in their own secure wallet and use this wallet as an authentication mechanism on different platforms. This means they can take their data with them.

This means that there’s no central ownership over the data and no control over the rules of the platform, as the data exists with multiple nodes. Multiple nodes can vote for governing the network. This creates a healthy ecosystem for developers to come and build decentralized applications on the platform that will further attract even more users. At the beginning of this section, we read that decentralization creates a win–win solution for all the parties involved, but we hadn’t understood why. Now we know the reason.

The whole purpose of Web 3.0 and decentralization is to create healthy, secure ecosystems where more people trust the system inherently, not because they trust the central authority that controls the system but because they trust the mechanism and processes around how the system is set up.

So, to summarize, in Web 2.0, the tagline was Don’t be evil (this is Google’s famous tagline), meaning that even though the platform owns the data and is responsible for securing it, everything depends on the trust that users have in the platform. This trust has been exploited multiple times, whereas in Web 3.0, the motto is Can’t be evil since the system is set up to not have a central authority. This means it’s built on a zero-trust system where users don’t have to trust the platform since the system takes care of the fact that the platform never ends up owning users’ information.

Tokens versus coins and ICOs

We learned that cryptocurrencies are created to incentivize the nodes in a network to dedicate their storage and processing resources. These native cryptocurrencies running on original chains and their forks are considered coins.

All native cryptocurrencies, without exceptions, run on their own blockchains and have an intrinsic value that’s linked to multiple factors, with the efficiency and security of the underlying blockchain being two of the primary ones.

Tokens, on the other hand, don’t need an underlying blockchain and can be used by the following:

  • Technology projects to raise capital
  • Technology companies to represent digital assets
  • Corporations, institutions, and individuals to represent a real-world resource in the digital world

Now, let’s discuss these three use cases in order.

The first use case is for technology projects when the technology required to be built is complex or advanced and will require some runway expenses for the team to research and build the project.

For early-stage and research-driven tech projects, raising capital from the general public is not an option, as that space is highly regulated.

So, instead of raising capital from traditional venture capitalists, such tech projects can leverage initial coin offerings (ICOs) to raise capital wherein a particular amount of tokens are generated. A small percentage of these are distributed among the founding team, developers, and some early-stage users. After this distribution, the majority that are left are purchased by the next set of users.

When users buy the token, they are essentially buying into the vision of the tech project and funding the runway required to build it. This process can be likened to a crowd-funding process.

The second use case is related to representing digital assets, such as the following:

  • Smart contracts to indicate property ownership, mortgages, and digital identity
  • Non-fungible tokens (NFTs) to represent art, music, in-game assets, and so on

We will learn about both in the next section.

The third use case is related to representing real-world, physical resources and assets in the digital world. Tokens have the perfect use case for this. Real estate assets, crops, medicines, and so on can be tokenized in the digital world and represented on the blockchain. They can then be traded between users, each trade representing an actual transfer of value between the users.

The presence of blockchain ensures that the immutable ledger is maintained and updated, and the immutability and cryptographic security provided by the blockchain bring trust in trading such physical assets digitally. This opens the possibility of cross-border transactions and trades since such transactions are scalable digitally.

Smart contracts and NFTs

In the Tokens versus coins and ICOs section, we learned how tokens can be used to create smart contracts and NFTs. Now, let’s discuss what these are in a little more detail. It is important for us to understand them because as a blockchain developer, you will be creating smart contracts and even NFTs all throughout your career.

Let’s first tackle smart contracts. For a real-world, regular contract to take place, there is a governing, intermediary body such as a bank, legal authorities, or the government. This is basically an entity that has some enforceable power in the real world in case the parties signing the contract do not hold up their end of the bargain.

In the case of smart contracts, there is no intermediate party. Instead, there’s just a program/computer code that runs on the blockchain, and this code is cryptographically secure and immutable (the two properties that are induced due to the SHA-256 algorithm).

The smart contract ensures that none of the parties can back out of the contract or make any changes, and it also ensures that the parties hold up their end of the bargain without involving any manual intervention or human beings and institutions as authorities and witnesses.

Irreversible, immutable smart contracts are objective in nature, whereas regular contracts can be highly subjective in nature because the differences in interpretations of the contract usually lead to discord and conflict.

We mentioned that a smart contract runs on a blockchain, but how does that actually work? A smart contract gets its own hash, which is used to recognize it, and once the smart contract is executed in a particular way with different values, you get a different application binary interface (ABI) (a representation of your contract to be called from the external world). This is what’s stored onto the blockchain.

Let’s walk through a use case example to understand how this actually functions. Let’s say there are two parties involved. The first is a corporation that wants to transfer some stocks to an individual who works in that firm but the firm wants these stocks to be transferred based on the number of months that the individual works at the firm rather than all at once. This process can be completely automated with a smart contract that can be integrated to send push events to the stock vesting service based on a CRON script that runs every few months based on the frequency and schedule mentioned in the contract.

Now, this brings in a lot of trust between the corporation and the employee who will be given the stocks since there is no intermediary who can be swayed. There is just a computer program that gets executed and is immutable. Now that we have a solid understanding of smart contracts, let’s dive into NFTs, which are simply an extension of smart contracts.

In the previous section, we read that NFTs can be used to represent art, music, and in-game assets. Now, let’s understand how that works. NFTs are non-fungible tokens, meaning they are different from regular tokens that are fungible.

Although each NFT is distinguishable from another, they can be exchanged with each other. The fact that they are distinguishable makes them non-fungible, not their exchangeability.

We can convert images such as a JPEG file into an NFT by assigning it a hash, and this process is called tokenization. Each NFT token has a unique hash and it cannot be exchanged since each NFT is associated with only one unique hash.

But we know that a crypto token is fungible and can be exchanged (if you have one crypto token and your friend has one crypto token and you exchange them, it doesn’t matter because those tokens aren’t unique, thereby making them fungible).

Since you can assign unique hashes to NFTs, this means you can represent real-world contracts in the digital world using NFTs. This is quite different from a smart contract, which isn’t a real-world contract and has no authorities involved.

DAOs

In the previous sections, we learned how real-world assets can be represented in the real world with tokens and NFTs, but what if we applied the same concept to organizations and corporations?

Using blockchain, we can imagine a different future for organizations where the power will not be centralized. Currently, many issues can be pointed out in organizations that are centrally run by just a handful of people. Such organizations can sometimes work against the society and the community.

But here’s a revolutionary thought: what if an entire community takes up the responsibility of running an organization? This means tokens would be issued to the people from this community and they would represent ownership. Some of these tokens would be governance tokens and would have more weight in the voting process.

An elaborate voting process would take place for critical decisions, and the voting weightage would be based on the tokens you hold.

All of the decisions resulting from the voting process would be made public and the rest of the community that has regular tokens and not governance tokens would be apprised of the updates.

The public would also decide to buy these tokens and take up a seat at the table for governance.

Building such a community-led organization would ensure that the decisions are always taken for the benefit of a very small percentage of society. Since all the decisions are available on a public blockchain, they are mostly irreversible, so all the promises made by corporations would need to be fulfilled.

This model of organization is known as a decentralized autonomous organization (DAO).

This is a great model to run a highly democratic organization, and it is thought that even governments can run like this.

This presents us with a completely digital way to run a real-world organization fully remotely. Currently, many companies are experimenting with this model. It is important to note that the DAO model is not currently completely free of issues and vulnerabilities, and the factors that affect organizational decision-making in the real world can also affect DAOs. It is an evolving model and something that’s widely agreed upon as the future.

Non-censorable apps

Decentralization makes it extremely difficult to censor information since multiple copies of the same information exist, and it also makes it significantly more difficult to spread fake news and propaganda, as facts can be recorded on a blockchain. The facts are immutable, as the information cannot be changed later.

A significant number of dApp developers are focusing on creating Web 3.0 versions of apps such as Twitter, Reddit, and Quora where posts cannot be taken down by admins, firstly because there would not be any admins since the app would be community-driven and secondly because the information would be immutable so there would be no edit or delete functions. This enables true freedom of expression on an unprecedented scale.

So, now we have clarity on how information on apps can be resistant to censorship, we can go beyond by making websites and web apps censorship-resistant at the fundamental level.

This means that it shouldn’t be easy to take down websites by just restricting traffic to them. This is made possible by decentralized storage platforms such as Arweave and EmbassyOS, where independent individuals can buy special physical storage devices.

These storage devices can be used to store the websites on their own devices rather than on a cloud server, making it significantly more difficult to take websites down.

Digital assets with real-world limits

Blockchains would only matter to the common man if they’re able to affect the real world or our daily lives. So, let’s learn about how blockchains model real-world limits and how blockchains can be used to represent real-world resources.

Up until now, we’ve never had a way to represent real-world resources in a digital format, but blockchain and tokenization enable this for us. It’s important to discuss this, as it opens tons of possibilities, so let’s walk through a few use cases to understand it better.

Let’s say there’s an apartment in Japan with 1,000 square meters of space. If you want to buy this apartment, you must buy it as a whole, and you also need to meet a lot of criteria, such as being a resident of Japan. But what if there was a way to not buy the entire apartment and buy only a fraction of the apartment? With tokenization, this is made possible.

This is how the process works: a tech enablement company acquires this apartment and tokenizes the square meters. Each token represents one square meter of the apartment, and this currency is restricted to 1,000 tokens (since the total space of the apartment is 1,000 square meters). This total limit cannot change since it’s backed by a blockchain, and now these tokens can be purchased by anyone in the world.

This means that if you want to buy just two square meters of that apartment in Japan, you must buy two tokens. The benefit of this is that you can invest in the real estate market of Japan and the growth that Japan will see in the coming years by just buying the token. This opens the market up for multi-ownership models and removes long processes from the equation. Since these tokens can be traded, all trades will be recorded on the blockchain, and the latest ownership state will be maintained and updated. This same concept can be applied to many other things in the real world, and right now, we’re just at the cusp of a new wave of tech enablement that may end up changing our reality for the better.

We now know that blockchains have a lot of use cases, and for blockchains to be truly adopted, we need blockchains that can process a lot of transactions and handle a lot of users. In the next section, let’s look at how blockchains can be scaled to handle millions of transactions and users with ease.

Scaling the blockchain

Multiple nodes are involved in a blockchain network, and the number of nodes determines the decentralization coefficient, or the Nakamoto coefficient.

The Nakamoto coefficient measures the number of nodes required to maintain healthy decentralization in the network. This means the higher the number of nodes, the higher the Nakamoto coefficient.

Now, we know that all of the nodes in a blockchain network not only need to be aware of the transactions that are taking place in the network but also need to process these transactions and communicate with the other nodes to reach a consensus on the block to be finalized.

Since so many operations are taking place between the nodes in a network at any given point in time, it makes it difficult to scale transactions beyond a particular point. For example, the limit for Ethereum is 20 transactions per second. Many new blockchains are trying to solve this problem, and some companies are trying to solve this problem for existing blockchains such as Ethereum using some innovative solutions. In this section, our focus will be the problem of scalability.

In the next few sub-sections, we will cover the factors affecting blockchain scalability and some solutions to help scale blockchains with ease.

The blockchain trilemma

Before we dive deeper into scalability and look at the factors affecting it and its possible solutions, we first need to understand the blockchain trilemma, as just looking at scalability in isolation and solving for scalability does not provide us with an efficient solution.

Three different elements are highly desirable in blockchains: decentralization, security, and scalability. The blockchain trilemma states that as a blockchain network evolves, it becomes difficult to maintain all three of these traits, and usually there’s an imbalance. One of the traits ends up being more dominant than the other two, and trying to enhance the others may end up weakening the dominant one.

The more nodes in the network, the higher the decentralization, but the scalability (number of transactions) goes down, as all nodes need to process these three elements and come to a consensus. Also, security can be more easily compromised since there are more points of entry.

So, to address scalability without affecting the other two elements and solving the problem effectively, we have a few options. We will go over them now.

Sharding

Blockchain sharding is a technique used to scale blockchain networks and improve their performance by dividing the network into smaller, more manageable components called shards. Each shard is like a separate blockchain with its own set of validators and transaction history, but they are all interconnected.

The primary goal of sharding is to increase the transaction processing capacity of a blockchain network by enabling parallel processing. In a traditional blockchain, every node in the network has to process and validate every transaction, which can result in bottlenecks as the network grows larger. Sharding overcomes this limitation by dividing the network into smaller shards, each capable of processing a subset of the total transactions.

Here’s a simplified explanation of how blockchain sharding works:

  • Shard creation: The blockchain network is divided into multiple shards, with each shard assigned a subset of accounts or addresses. For instance, one shard could manage transactions related to addresses starting with the letter A, while another shard takes care of addresses starting with the letter B, and so forth. However, when considering sharding methods, the approach described resembles range partitioning, where data is distributed based on predefined ranges or categories. However, there are alternative methods such as hashing. Hash-based sharding involves distributing data across shards based on the outcome of a hash function applied to the data, offering a different way to achieve load distribution and network efficiency.
  • Shard processing: Each shard operates independently and processes transactions related to the accounts or addresses assigned to it. This allows for parallel processing of transactions within each shard, significantly increasing the overall transaction throughput.
  • Cross-shard communication: Since transactions can involve accounts or addresses from different shards, a mechanism is needed for communication between shards. This is typically achieved through a cross-shard communication protocol, where transactions that affect multiple shards are coordinated and validated.
  • Consensus and security: Each shard has its own set of validators responsible for validating transactions within that shard. This means that the consensus mechanism of the blockchain network must be designed to handle cross-shard transactions and ensure the overall security and integrity of the network.
  • Shard coordination: To maintain the consistency of the blockchain across shards, some form of coordination is required. Techniques such as cross-links, where the state of one shard is included in the block of another shard, or periodic checkpoints can be used to synchronize the shards and maintain a consistent global state.

By implementing sharding, blockchain networks can achieve higher transaction throughput, lower latency, and improved scalability. However, sharding introduces additional complexity in terms of shard coordination, cross-shard communication, and consensus mechanisms. Designing an efficient and secure sharding solution is an active area of research and development in the blockchain space.

Interoperability

Interoperability is an interesting concept and has multiple implications. An indirect implication of interoperability can be scalability. Each blockchain has its own set of data, digital assets, and tokens stored on the chain, but if a user wants to move this data to another chain, there can be various migration and compatibility issues.

Interoperability is when you have different blockchain protocols built with different technologies and their own way of operations to work together and exchange resources and assets seamlessly.

A lot of companies are trying to solve the interoperability problem by building bridges that make it possible to transfer assets across multiple blockchain networks. This also means that if a blockchain is unable to scale beyond a particular point in terms of storage of assets and transactions, these can be shipped off to other chains.

Consensus for scale

The developers of Solana figured out that the consensus mechanism of the chain itself can be a factor that limits the scalability of the network.

Solana has implemented a novel Proof of History (PoH), which is used in tandem with practical Byzantine Fault Tolerance (PBFT). PBFT addresses Byzantine Faults, where malicious nodes can disrupt consensus. By integrating PoH, which cryptographically validates time passage and event order, Solana streamlines the chronology crucial for Byzantine Fault Tolerance. However, this integration adds complexity, as each node needs to execute sophisticated software for consensus participation.

Using PoH enables Solana to theoretically process 65,000 transactions per second (TPS) (currently, it is around 3,000 TPS) as opposed to the 20 TPS provided by Ethereum. This proves that innovating with different consensus mechanisms can enhance the speed and scalability of a network.

Parallel processing

Many blockchain systems lack parallel processing, hindering scalability and speed. Without this capability, transactions are processed sequentially, causing bottlenecks and slower network performance. This limitation restricts their ability to handle a high volume of transactions efficiently, ultimately impeding widespread adoption and real-world applications of blockchain technology.

Newer blockchains such as Aptos and Sui, developed using Rust, have introduced a groundbreaking Layer-1 scaling solution known as parallel processing. This innovation significantly enhances scalability by allowing multiple transactions or tasks to be executed simultaneously within individual blocks. Unlike Layer-2 solutions that build upon existing blockchains, Layer-1 solutions such as parallel processing directly optimize the blockchain’s core protocol. This approach fundamentally increases transaction throughput and network efficiency, paving the way for nearly limitless scalability and improved performance, thus addressing a major limitation of traditional blockchain systems.

In older blockchains, all the present nodes in the network process all transactions individually. The new transactions that are recorded on the blockchain are all present in the mempool. All of the nodes create new blocks using the same transactions. So, this means the more nodes in the network, the more decentralized the network is.

But this does slow down the network because instead of leveraging the processing power of the nodes in the network to divide and process the blocks to enhance speed, all the nodes are essentially processing the same transactions and a lot of computational energy is used up.

Aptos (the new blockchain we talked about) processes pending transactions from the mempool. At the same time, the nodes in the network divide these transactions among themselves and process different transactions instead of processing the same transactions. This makes the process way more efficient and highly scalable at the same time since the more nodes you add, the more transactions you can theoretically handle. Adding more nodes speeds up the network rather than slowing it down (as in the case of older blockchains).

Layer 2s and side chains

Sharding, consensus, and parallel processing are all Layer-1 scaling solutions. What if, instead of trying to scale at Layer-1, which may require us to make changes to the blockchain’s architectural structure, we try to solve the blockchain trilemma by building on top of the blockchain on Layer-2? It’s important to note that all the layers are imaginary and the terminology is used for better understandability.

An example of a Layer-2 solution is a sidechain, which is essentially a separate blockchain connected to the main chain. It’s set up in a way that assets can flow between the chain flawlessly. The biggest difference is that sidechains can be configured with different modes of operation and rules, which can make them way faster than the main chain.

Transactions can be shipped off to the side chain for faster speeds, but they may still be verified by the main chain once the side chain sends the output of the transactions back to the main chain.

ZK rollups and optimistic rollups

Rollups are another highly popular Layer-2 scaling solution for blockchains. They take the transactions off-chain and, at the same time, ensure storage on the main chain for high security.

The way they do this is by compressing the transaction data to a great extent so that it becomes a fraction of the size and can be stored very easily on-chain. This results in significant throughput enhancement. Prominent examples of this approach include Arbitrum (an optimistic rollup) and PLONK (a zero-knowledge rollup). These rollups employ different techniques but share the common goal of enabling seamless and secure scaling, making them pivotal in advancing the capabilities of blockchain technology.

Now that we have understood rollups, it’s time to talk about the two types of rollups: zero-knowledge (ZK) rollups and optimistic rollups. Optimistic rollups don’t need to provide any proof when sending the compressed transactions to the main chain, whereas ZK rollups need to submit cryptographic validation proof.

Since with optimistic rollups there is no validation proof being submitted, they are essentially operating on the assumption that the nodes are not going to submit any fraud transactions, and this is why these are called optimistic. On the other hand, ZK rollups assume that they have no knowledge of the type of transactions that can be submitted, and thus comprehensive crypto validation is required.

Now that we have learned about blockchain basics, let’s now understand how smart contracts work.

Introducing smart contracts

Interacting with blockchains involves a dynamic interplay between external code and the blockchain’s internal architecture, particularly smart contracts. Smart contracts are self-executing contracts with predefined rules that automatically execute actions when specific conditions are met. External code refers to applications, scripts, or software components running outside the blockchain network.

To bridge the gap between external code and blockchain functionality, most blockchain platforms offer remote procedure call (RPC) APIs. Application programming interfaces (APIs) facilitate communication and interaction between distinct software applications, enabling them to work together harmoniously.

An API defines a set of rules and protocols that govern how software components should interact, making it easier for developers to use functionalities provided by another system without needing to understand its internal workings.

Think of an API as a waiter taking orders in a restaurant. Customers (developers) interact with the waiter (API) to request specific dishes (functions or data) from the kitchen (the system providing the service). The waiter conveys the order to the kitchen, brings back the dishes, and serves them to the customers. The customers do not have to know how the kitchen operates; they just need to know how to communicate their orders effectively to the waiter.

Similarly, in the context of blockchain platforms such as Ethereum, RPC APIs act as intermediaries between external code (applications) and the core blockchain software. They provide a standardized way for external code to send requests for actions, data retrieval, or other operations to the blockchain. The blockchain’s core software processes these requests and sends back the relevant information or results.

For instance, if developers want to retrieve the balance of an Ethereum address, they can use an RPC API call to request that information from the Ethereum network. The API handles the communication between the external code and the blockchain’s internal systems, abstracting away the complexity of direct interaction.

The future of the adoption of blockchains

In this section, we will learn about the real-world implications of blockchain technology, how it will affect various industries and its effects on social and cultural aspects.

Industries disrupted

Blockchains provide a secure representation of real-world assets in the digital realm, thanks to their cryptographic security. This introduces a revolutionary perspective across all industries.

The following use industries are well covered by blockchains:

  • Banking and finance
  • Healthcare and medicare
  • Supply chains and warehousing
  • Governance and policy-making
  • NGOs, associations, and institutions

Many of these industries are getting disrupted by blockchain technology simply because it adds trust, security, and decentralization, creating a win–win solution for all the parties involved in the ecosystem.

Sociocultural and economic changes

Apart from disrupting industries and bringing about technological change, efficiency, and effectiveness into the system, blockchains are also triggering social change, as it becomes easy to track whether all social strata are benefiting or if there are any individuals that are left behind. Applied with the right policymaking, they can ensure a reduction in economic disparity and wealth equality and ensure that economic welfare funds reach the intended audiences.

It is easy to see that applications and effects of blockchain technology go well beyond a few industries and can alter the way society and culture function at large, especially since blockchains allow the digital representation of real-world assets and thereby enable cross-border trading of these assets in a highly secure and efficient manner.

This is why it is important for engineers to gain expertise and a foothold in this new and upcoming technology.

Summary

In this chapter, we’ve gained deep insight into blockchains and how they operate. We covered many concepts that are important to understanding how blockchains truly work, such as immutability, forking, validation, transactions, nodes, the different consensus mechanisms, gas fees, and processing fees.

Then, we broke down how blockchains power decentralization and applications that are deployed to blockchains, such as DAOs, DeFi apps, NFT platforms, and so on. We also went through some topics such as scalability involving interoperability, consensus, and sharding. These are the hottest topics in blockchain technology since experts are working on them to try and scale blockchains for millions of users.

In the next chapter, we will understand what makes Rust the perfect fit for building blockchains and we will learn some Rust concepts hands-on before diving into building our own blockchain using Rust.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Implement peer-to-peer blockchain using features of the Rust programming language
  • Use Rust to build dApps on popular blockchains like Ethereum, Solana, and NEAR
  • Optimize Rust code and enhance security updates to deploy a blockchain to production
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

Before Rust, blockchain developers didn’t have a systems programming language that was type-safe, fast, and, at the same time, had stable and easy memory management. Rust proved to be a boon for developers and works as the perfect solution for not only blockchain and protocol development but also dApp development. Rust for Blockchain Application Development focuses on demonstrating solutions that can help blockchain developers productize decentralized applications using Rust, which is a complex language with a steep learning curve. This book starts with basic Rust language concepts and then builds on these concepts to enable you to develop your own blockchain from scratch. As you progress, you’ll learn how to build dApps on popular chains like Solana and NEAR. You’ll also be guided through creating Ethereum dApps using Foundry (Rust). Finally, you’ll develop a custom blockchain using Substrate by Parity (Polkadot). The book provides a complete 360-degree view of Rust in the blockchain ecosystem. By the end of this Rust book, you’ll have a thorough understanding of how to apply your Rust knowledge to building dApps and blockchains from scratch.

Who is this book for?

This Rust programming book is for blockchain developers interested in building dApps on popular blockchains using Rust. Blockchain architects wanting to save time required to go through documentation and understand each technology can also use this book as a quick-start guide. Experience in building applications on blockchain is required, and familiarity with Rust will be helpful but not necessary.

What you will learn

  • Understand essential Rust concepts required to build blockchain
  • Apply blockchain features such as nodes and p2 communication using Rust
  • Understand and implement consensus in blockchain
  • Build and deploy a dApp on Ethereum with the Foundry framework in Rust
  • Develop and deploy a dApp on Solana and the NEAR protocol
  • Build a custom blockchain using the Substrate framework by Polkadot

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 30, 2024
Length: 392 pages
Edition : 1st
Language : English
ISBN-13 : 9781837630059
Category :
Languages :
Concepts :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Apr 30, 2024
Length: 392 pages
Edition : 1st
Language : English
ISBN-13 : 9781837630059
Category :
Languages :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 101.96 130.97 29.01 saved
Building LLM Powered  Applications
$34.98 $49.99
React and React Native
$29.99 $43.99
Rust for Blockchain Application Development
$36.99
Total $ 101.96 130.97 29.01 saved Stars icon
Banner background image

Table of Contents

18 Chapters
Part 1:Blockchains and Rust Chevron down icon Chevron up icon
Chapter 1: Blockchains with Rust Chevron down icon Chevron up icon
Chapter 2: Rust – Necessary Concepts for Building Blockchains Chevron down icon Chevron up icon
Part 2: Building the Blockchain Chevron down icon Chevron up icon
Chapter 3: Building a Custom Blockchain Chevron down icon Chevron up icon
Chapter 4: Adding More Features to Our Custom Blockchain Chevron down icon Chevron up icon
Chapter 5: Finishing Up Our Custom Blockchain Chevron down icon Chevron up icon
Part 3: Building Apps Chevron down icon Chevron up icon
Chapter 6: Using Foundry to Build on Ethereum Chevron down icon Chevron up icon
Chapter 7: Exploring Solana by Building a dApp Chevron down icon Chevron up icon
Chapter 8: Exploring NEAR by Building a dApp Chevron down icon Chevron up icon
Part 4: Polkadot and Substrate Chevron down icon Chevron up icon
Chapter 9: Exploring Polkadot, Kusama, and Substrate Chevron down icon Chevron up icon
Chapter 10: Hands-On with Substrate Chevron down icon Chevron up icon
Part 5: The Future of Blockchains Chevron down icon Chevron up icon
Chapter 11: Future of Rust for Blockchains Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8
(5 Ratings)
5 star 60%
4 star 0%
3 star 0%
2 star 40%
1 star 0%
Dhananjai Sep 14, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This exceeded my expectations in every way! As someone with experience in blockchain development but new to Rust, I found this book to be an incredible resource. It walks you through everything from the basics of Rust to building full-fledged decentralized applications (dApps) on popular blockchains like Solana, Ethereum, and NEAR. The explanations are clear, and the progression from simple to complex topics is seamless. I especially loved the deep dive into building custom blockchains with Substrate—it really gave me a 360-degree view of Rust in the blockchain space. The hands-on approach and real-world examples made complex concepts easy to grasp. Plus, the accompanying GitHub repo with all the code examples is a huge help, making it easier to follow along and experiment. This book is a must-have for anyone serious about blockchain development and looking to master Rust!
Amazon Verified review Amazon
Amazon Customer Aug 21, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great book if you are already a rust engineer and don't want to spend time rereading documentation of all different blockchains - this book gives you great projects to help you learn faster. I would definitely recommend it to all blockchain enthusiasts!
Amazon Verified review Amazon
AP Jun 11, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Just picked up my copy of the book, this is a gold mine and the ONLY resource on the internet that covers multiple Rust blockchains. I would highly recommend knowing Rust really well before picking this up though since otherwise it's going to be very difficult to follow along as the third, fourth and fifth chapters are about building your own blockchain in Rust, so things get very serious very fast.Highly recommended if you're a Rust engineer and want a comprehensive resource about blockchains that use Rust.My favorite chapters are the Solana chapter (uses Anchor for smart contract development) and the Substrate one (building your own blockchain).
Amazon Verified review Amazon
Ing. Jaime Calahorrano Gallardo Jun 07, 2024
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
not that enjoyable book, the solana chapter is not very well explained, hard to visualize what is going on, not clear example and vague code, i rather watch a solana course with anchor in youtube
Amazon Verified review Amazon
Josh Notter May 23, 2024
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
I bought this book after learning Rust, as I wanted to get into blockchain development with Rust.The book starts off strong if you don't know much about blockchain. However, I noticed printing errors almost immediately - but not a big deal. There are also several grammatical errors throughout the book, indicating that English is the author's second language - also not a big deal.Then we get to the first code walkthrough, which is what really makes me give this book a 2-star rating. The instructions are not clear, and I am left trying to deduce where to put certain blocks of code in the starter project that is depicted in the book. For someone who doesn't know much about blockchain and has never worked on anything related before: this has me lost and confused.On top of that, I have already discovered two instances of Rust code that were incorrect, and they were very basic examples.I don't know if a better resource is out there, but I'll keep looking.EDIT: After completing chapter 3, which is where we are to set up our own blockchain, I was completely confused. After writing some code, the chapter ended without even running the code. I found the GitHub repo for the book and located the section on chapter 3 and discovered a TON of code left out of the book that is required to make it all come together and work. Baffling that this book was published by Pakt.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.