Modular blockchains & Getting started w/Fuel

Modular blockchains & Getting started w/Fuel

·

12 min read

TL;DR:

  • Modular Blockchains present a new design by decoupling the core functions of blockchains into distinct modules. Each module is specialized for the function they provide allowing for more customization and better performance.

  • Fuel is building the fastest execution layer for the modular blockchain stack together with its full suite of developer products. (In the Ethereum world, you can think of Fuel as a rollup that can also be customized and deployed in different ways.)

  • Fuel has its own Virtual Machine called FuelVM. Sway is a domain-specific language inspired by Rust to write smart contracts for the Fuel network. Fuel Orchestrator(Forc) is the system and package for Sway.

Over the past few months, I've been learning a lot about Modular Blockchains. As an app developer, the protocol layer is not something I spend most of my time researching. However, the need for scalability becomes very clear if you've made any transaction on Ethereum mainnet; the costs are high, and the transactions are slow, especially during peak times.

Modular Blockchains present a new design to solve blockchain scalability. It's an architecture where the core functions of the blockchain are handled by separate, specialized layers which can unlock the scale required for mass adoption.

In this post, I want to talk about:

  • Blockchains architectures: Monolithic & Modular

  • An introduction to Fuel, the fastest modular execution layer, and why it's important for an app developer

  • Building with Fuel: How to write a smart contract in Sway & deploy to Fuel


Introduction to Modular Blockchains

Blockchain Scalability

Blockchain scalability is still a major issue. Blockchains are slow and expensive compared to other alternative architectures. However, in recent years, several innovations have been developed that have the potential to improve scalability.

You may have heard of the Scalability Trilemma (aka Blockchain Trilemma). It describes the trade-off between three key properties of a blockchain network: decentralization, scalability, and security.

  • Decentralization: distribution of power among network participants

  • Scalability: ability to handle large amounts of transactions

  • Security: trustworthiness of the network

Screen Shot 2022-12-13 at 12.28.21.png

The Scalability Trilemma states that it's only possible to get 2 out of the three properties with current technologies for a traditional (monolithic) blockchain. Therefore, one feature can only be improved by sacrificing another.

For example, a blockchain can prioritize execution and optimize to have fast transactions by having fewer nodes which would also increase the cost to run a node and hence give away from decentralization. The Solana Blockchain can be given as an example.

There have been many approaches to improving scalability for a monolithic blockchain where one should consider the Blockchain Trilemma. Some of these solutions are being researched, while others have proven to be a dead end. There have also been approaches to enhance the blockchain architecture, rather than trying to solve the Blockchain Trilemma. A new perspective 🙂

First, in short, a Monolithic Blockchain is an architecture where the blockchain's core functions are handled on the same layer, Layer 1. With monolithic blockchains the Blockchain Trilemma comes in, suggesting that it is very difficult to optimize a single layer with three features.

Rather than trying to optimize for all three properties on a single layer, some have suggested designing systems that break down the layer into multiple building blocks. This is where Modular Blockchains come in. It's an architectural design that aims to solve scalability issues with a new approach.

Let's start with an introduction to blockchain architecture and then have a deeper look at the monolithic & modular blockchains.

Blockchain Architecture

At its core, a blockchain provides 4 core functions: Consensus, Execution, Data Availability and Settlement. We can think of these as modules or layers that make up the blockchain.

  1. Consensus: Orders transactions, and ensures that all nodes have the same state. The consensus protocol defines the rules on how transactions are ordered and how new blocks are added (e.g., PoW and PoS).

  2. Execution: Processes transactions and changes the state of the blockchain (e.g., when Alice sends 1ETH to Bob, the state of the blockchain needs to be updated)

  3. Data availability: Ensures data is available. When new blocks are added, the data must be available upon request.

  4. Settlement: Dispute resolution. This is how the blockchain determines valid transactions.

Screen Shot 2022-12-13 at 12.47.00.png

Monolithic Blockchains

In the monolithic(aka traditional) blockchain architecture, all 4 core components of the blockchain are handled on a single layer: Layer 1. Bitcoin and Solana are examples of monolithic blockchains.

In a monolithic blockchain, since the same layer is asked to do too many things there will be a significant trade-off and/or very high hardware requirements, and the scalability trilemma comes into play.

Alongside the high hardware requirements, monolithic blockchains present limited control & flexibility. All apps on the blockchain must follow the pre-determined rules and standards defined by the Layer 1. (E.g., the programming languages you can write your smart contract in.)

Modular Blockchains

A modular blockchain breaks the blockchain down into smaller modules that are specialized for certain functions to build customizable, scalable, and flexible blockchain systems.

Screen Shot 2022-12-14 at 10.05.20.png

A modular design can be thought of as similar to building with Lego blocks. Each block is a module, and each module has a specific function or purpose. Modules can be combined in various ways to create a larger, more complex structure.

Screen Shot 2022-12-14 at 07.25.01.png

Having separate layers provides scalability and flexibility.

  • Scalability: Modular blockchains are more scalable because the resources are separated. Each module of the stack is specialized for a specific function. Therefore, the module can optimize the resources for the particular operation, and so this would increase efficiency.

  • Flexibility: Modular blockchains are built from modules that can be updated and swapped out. You're not limited to a particular set of resources but can choose the layers that best fit your use case. This allows the creation of chains that are tailored to specific needs and allows developers to quickly and easily make changes to the blockchain without performing a full-scale upgrade.

Modular Blockchain Platforms: Ethereum, Celestia, Polygon Avail, Optimism & Fuel

Different teams are working on blockchain modularization & let's talk about a few of them. 🌍

Ethereum

The Ethereum roadmap has been shifted to being modular by becoming rollup-centric and with sharding.

Rollups are one of the best examples of modular architectures. A Rollup will do the execution and then leave consensus, data availability, and settlement for Layer 1. That's how a rollup can scale exponentially compared to L1. This lowers the costs and leads to faster transactions.

Ethereum sharding is a potential solution to the scalability problem for the Ethereum blockchain. It proposes to divide the network into smaller sub-networks called "shards", which can process transactions and store data independently.

Screen Shot 2022-12-13 at 12.33.59.png

Celestia

Celestia is the first blockchain pioneer the modular blockchain architecture. It's the network that coined the term: Modular Blockchain. Celestia is a minimal-layer 1 that provides data availability & consensus.

Celestia orders data and makes it available but does not execute the transactions. Instead, the execution is outsourced to specialized execution layers like rollups. Celestia aims to solve the data availability problem that blockchains face. The Data Availability problem refers to the need to make sure all nodes in the network have access to the same complete and accurate data stored on the blockchain. Sounds easier that is, especially as the network grows in size and complexity. You can read more about Celestia and the data availability problem over here.

Screen Shot 2022-12-14 at 07.38.40.png

Polygon Avail

Polygon Avail is Polygon's data availability solution. It provides ordering and recording of transactions and leaves the other tasks for separate layers to scale other blockchains with the modular architecture.

Screen Shot 2022-12-14 at 07.41.01.png

Optimism

Optimism's architecture which is a modular approach is called the OP Stack. The Optimism team has been working on a Bedrock update for the OP Stack that uses the principles of modularity. The idea is to have different modules with certain functionalities (consensus, execution, settlement) that can be swapped.

Fuel

Another core layer in the modular blockchain stack is Fuel which is the execution layer. We'll be talking more about Fuel in the next sections.

Challenges w/Modular blockchains

Before moving on it's worth mentioning some of the main challenges of modular blockchain networks:

  • The time and effort required to build the infrastructure to support independent modules that can work. They can be very complex to design and require specialized expertise. The layers need to communicate and share data effectively as well as provide security and be sufficiently decentralized.

  • Bootstrapping a community to build and use modular blockchains. This is a common challenge for many new developer tools. There need to be educators, teams building products, users willing to try it out etc. I generally view the lack of people in a new, emerging and exciting technology as an opportunity to get involved. 😌

I'm excited to see the modular tech stack evolve and see many top-tier teams building in the space and pivoting to becoming modular.


Getting started w/Fuel ⛽️

In the modular blockchain architecture, the execution, data availability and consensus are separate layers, Fuel is the fastest Execution Layer for modular blockchains.

Fuel network is created by Fuel Labs, which is creating a full suite of developer tools for building on Fuel, including the Sway the programming language and Fuel orchestrator (Forc) which is the toolchain.

Why Fuel

Here are some of the key features that make Fuel stand out:

  1. Its own Virtual Machine: Fuel Virtual Machine (FuelVM) aims to overcome some of the main drawbacks of EVM. You can read about the comparison of FuelVM and EVM over here.

  2. Parallel transaction execution: Most blockchains are single-threaded, meaning that only one thread is executed at a certain instant. Fuel uses a UTXO model, which allows for parallel execution; this way, it can execute more threads simultaneously.

  3. Focused on Developer Tooling: Fuel is internally building and maintaining a full suite of developer tools and resources to provide the best developer experience.

  4. Flexibility that comes with being a modular execution layer: A modular execution layer is different than a rollup, and one of the key differences is that it is not closely connected to a specific layer 1, which gives Fuel the flexibility to be deployed in a variety of settings. You can choose the data availability which fits your case best for example. Read more over here.

How can I build on Fuel?

First, here are your go-to resources to learn more:

And the Fuel Forum for questions and updates.

In the next section, we will be writing a smart contract in Sway & deploying it to the Fuel Testnet.


Writing a smart contract in Sway & Deploying to Fuel

The goal of this section is to:

  • Provide an overview of the tools needed to build on Fuel

  • Understand how to write & compile a smart contract in Sway

Tools

  • Fuel: The execution environment (blockchain)

    • beta-2 testnet: Fuel's second public testnet which has a bridge to Ethereum's Goerli test network.
  • Sway🌴: Domain-specific language for writing smart contracts on the FuelVM

  • Fuel Orchestrator(Forc): Package manager for Sway containing tools and commands for building on the Fuel ecosystem.

  • Fuel wallet

  • Fuel TestNet Faucet

  • Fuel Network Explorer

\Please note that some tools are under active development*

Installation & Setup

  1. Install the Rust toolchain by following the steps here

  2. The Fuel toolchain is required to compile Sway contracts & run them on the FuelVM. Install the Fuel toolchain by the command below; you can also find the steps here

    $curl --proto '=https' --tlsv1.2 -sSf \ https://fuellabs.github.io/fuelup/fuelup-init.sh | sh

    • Toolchain is a new terminology; it refers to installing the Fuel Orchestrator(Forc) and related plugins (like the fuel-core).

    • fuelup is the official package manager for Fuel that installs The Fuel Toolchain; you can read more on the fuelup docs and find some example commands
      Run the following to verify that toolchain was installed:
      fuelup --version forc --version fuel-core --version

  3. The beta-2 network is the second public Fuel testnet. Install the beta-2 toolchain by using the following command:
    fuelup toolchain install beta-2

    Verify that the toolchain was successfully installed by running the following: fuelup show

    You can also build your own toolchain with fuelup, more on it here

  4. You can install the VS Sway🌴 Language extension for convenience in working with sway files on VisualStudio.

Create & Deploy a Smart Contract in Sway to Fuel

  1. Create a smart contract project by running the following:
    forc new fuel-project

    Here's what the project folder looks like:

    • Forc.toml: manifest file that defines the project metadata for Fuel

    • src/main.sw: sample smart contract

  2. Have a look at the main.sw file which is the smart contract. I've added comments to explain the code. (For this blog post, I have not changed the boiler template smart contract).

     contract; // specify the sway program as a contract
    
     abi MyContract { // defines the details of the contract
         fn test_function() -> bool; // describs function & return type
     }
    
     impl MyContract for Contract { // implementation for contract
         fn test_function() -> bool { // define function that returns boolean
             true
         }
     }
    

    For this project, we will not be looking into tests; you can use "forc test "to run tests on your smart contract.

  3. In the project folder, run the command below to compile your contract:
    forc build

    You'll see new folders created in the project repo:

    • out: A new folder contains the JSON files of the contract & the byte code.

    • Forc.lock: Contains the information about your dependencies (similar to cargo.lock). This file should not be manually edited and is generated after the build.

  4. We need a deployer account, which is the account to deploy the contract from. Set up a Fuel wallet & create your account by following the steps here.

    I've also added the steps here for convenience:

    1. Initialize a wallet and make sure to save your seed phrase: forc-wallet init

    2. Create a new account & save your address: forc-wallet new

      • You can use forc-wallet list to view your wallet addresses and the account index.

      • To sign transactions with this wallet we nee the transaction id and the account index.

  5. Get some Testnet tokens from the faucet.

  6. Time to deploy the smart contract. There are a few different options for deploying the smart contract: forc from the command line (we'll be using this option), RustSDK or TypeScriptSDK

    1. Deploy the contract to the beta-2 tesnet: forc deploy --url node-beta-2.fuel.network/graphql --gas-price 1

      You'll need to provide the wallet address on the next prompt, leave the terminal open while we get the signature.

    2. On a new terminal generate a signature from your wallet by:
      forc wallet sign <transaction_id> <account_index>

    3. Enter the signature to the first terminal. If all goes well, you should see the contract id & the block number on the console.

      You can search for the transaction-id on the Fuel block explorer, make sure to add "0x" to the start of the transaction number.

🙌 There you go, congrats! You've deployed a smart contract on the Fuel Beta-2 Testnet. Here's a repo to follow along that contains a comprehensive list of Fuel resources and other projects to checkout!


Modular blockchains have the potential to provide exponential scalability to smart contract platforms, which is one of the most critical barriers to adoption. A second advantage unlocked by the modular architecture is flexibility. This can enable the creation of more efficient blockchain networks that are better suited to the needs of users and applications.

I hope that this was helpful in getting a start on Fuel & catch you on the next one! 👋