Ethereum vs Hyperledger Fabric: A Comparison of Blockchain Platforms

Marco Maigua
The Blockchain Artist
4 min readJan 4, 2023

If you’re considering building a decentralized application (DApp) on a blockchain platform, you may be wondering whether to use Ethereum or Hyperledger Fabric. Both platforms are popular choices for building DApps, but they have some key differences that make them better suited for different use cases.

One key difference between Ethereum and Hyperledger Fabric is the type of blockchain they use. Ethereum is a public blockchain platform, which means that anyone can join the network and participate in the consensus process. In contrast, Hyperledger Fabric is a private blockchain platform, which means that access to the network is restricted to authorized members. This makes Hyperledger Fabric well-suited for use cases where privacy and confidentiality are important, such as supply chain management and financial services.

Another difference between the two platforms is the way that smart contracts are implemented and executed. On Ethereum, smart contracts are stored on the blockchain and are executed by the Ethereum Virtual Machine (EVM). The EVM is a sandboxed environment that runs on all nodes in the Ethereum network, which ensures that all nodes have the same view of the blockchain and can execute the same code. Here is an example of a simple Solidity contract that stores a single value on the Ethereum blockchain:

pragma solidity ^0.7.0;

contract SimpleStorage {
uint256 public storedData;

function set(uint256 x) public {
storedData = x;
}

function get() public view returns (uint256) {
return storedData;
}
}

Hyperledger Fabric, on the other hand, uses a more modular architecture that separates the execution of smart contracts (called chaincode in Hyperledger Fabric) from the ordering and validation of transactions. In Hyperledger Fabric, transactions are first submitted to an ordering service, which constructs a block of transactions and passes it to a set of validating nodes for endorsement. Once a transaction has been endorsed by a sufficient number of validating nodes, it can be committed to the blockchain. This architecture allows Hyperledger Fabric to support private transactions, where the contents of a transaction are only visible to a subset of the network. Here is an example of a simple chaincode contract written in JavaScript that stores a single value on the Hyperledger Fabric blockchain:

'use strict';

const { Contract } = require('fabric-contract-api');

class SimpleStorage extends Contract {
async set(ctx, key, value) {
await ctx.stub.putState(key, Buffer.from(value.toString()));
}

async get(ctx, key) {
const data = await ctx.stub.getState(key);
return data.toString();
}
}

module.exports = SimpleStorage;

Another difference between Ethereum and Hyperledger Fabric is the programming languages that are supported for writing smart contracts. Ethereum uses Solidity, a high-level language specifically designed for writing smart contracts on Ethereum. Solidity is based on ECMAScript and is similar in syntax to C++, Python, and JavaScript. Hyperledger Fabric, on the other hand, supports smart contracts written in a variety of languages, including Go, JavaScript, and Java. This allows developers to choose the language that they are most familiar with when writing chaincode.

Finally, Ethereum and Hyperledger Fabric use different consensus algorithms to validate transactions and add them to the blockchain. Ethereum uses a proof-of-work consensus algorithm, which requires participating nodes to perform a computation-intensive task in order to validate transactions and add them to the blockchain. This process is resource-intensive and can be slow, but it is secure and ensures that the blockchain is resistant to tampering.

Hyperledger Fabric, on the other hand, supports pluggable consensus algorithms, including proof-of-work, proof-of-stake, and practical byzantine fault tolerance. This allows users to choose the consensus algorithm that is most appropriate for their use case, depending on factors such as the desired level of security, the size of the network, and the resources available to participating nodes.

Overall, Ethereum and Hyperledger Fabric are both powerful blockchain platforms, but they are designed for different use cases and have some important technical differences. If you’re not sure which platform is right for your project, here are some book recommendations that can help you learn more:

  • “Mastering Ethereum: Building Smart Contracts and DApps” by Andreas M. Antonopoulos and Gavin Wood: This book is a comprehensive guide to Ethereum, covering everything from the basics of smart contracts to advanced topics such as Gas, the EVM, and decentralized governance.
  • “Building Blockchain Projects” by Narayan Prusty: This book is a practical guide to building decentralized applications on Hyperledger Fabric. It covers topics such as chaincode development, network deployment, and smart contract testing.

--

--

The Blockchain Artist
The Blockchain Artist

Published in The Blockchain Artist

These articles are dedicated to software development, DevOps, and mainly blockchain consulting

Marco Maigua
Marco Maigua

Written by Marco Maigua

Master in Computer Science, Blockchain Developer, Scientist. marco.maigua1346@gmail.com