- Developers
- Developer Blog
- Blockchain Development
- How to Set up Hyperledger Smart Contracts for Ethereum
profile
By Aran Davies
Verified Expert
8 years of experience
Aran Davies is a full-stack software development engineer and tech writer with experience in Web and Mobile technologies. He is a tech nomad and has seen it all.
Planning on using Hyperledger Fabric to set up Ethereum smart contracts? This is an important topic that we will cover here.
In this article
- Hyperledger Fabric Smart Contracts for Ethereum
- Fabric embraces “Ethereum Virtual Machine” (EVM)
- How to set up a Fabric Smart Contract using Ethereum?
- Frequently Asked Questions on Hyperledger smart contracts
According to a report, the global smart contract market is expected to reach $2.5 billion by 2032 — up from $192.7 million back in 2022. The same report states that the Ethereum segment accounted for nearly one-third of the global smart contract market revenue in 2022 and is projected to retain its highest share during the forecast period (2022-2032).
Hyperledger Fabric Smart Contracts for Ethereum
So long, Fabric allowed developers to code chaincodes, but not Ethereum smart contracts. An Ethereum smart contract is important in the history of blockchain technology. This is due to the following reasons:
- Bitcoin has always been a “Peer-to-Peer”(P2P) network for transferring Bitcoin without the intervention of 3rd parties like banks. It didn’t cater to any other use case.
- Ethereum introduced smart contracts, i.e., open-source code with “If-Then-Else” statements that transferred cryptographic assets based on fulfillment of predetermined conditions.
- This smart contract executes autonomously, and they are stored transparently in the Ethereum blockchain.
- No one can tamper with them after deployment. I have explained this in “How to Deploy Smart Contract on Ethereum?”.
- Smart contract execution is irreversible.
- These transformative characteristics of a smart contract enabled entrepreneurs and developers to build decentralized business models using the Ethereum blockchain.
- This significantly improved the adoption of blockchain technology, as the wave of ICOs has shown.
You see, blockchain skills are niche. This is true for Ethereum as well as for key enterprise blockchain like Fabric. However, Ethereum enjoys considerable mindshare due to the popularity of smart contracts, written in Solidity. There is also Vyper, a relatively new language to write Ethereum smart contracts.
A perceived disadvantage of Fabric was that it didn’t offer the ability to write a simple smart contract on ethereum. That’s changing now, as Fabric is now allowing developers to do this.
Fabric embraces “Ethereum Virtual Machine” (EVM)
To enable the development of Ethereum smart contracts on Fabric, the Fabric project has incorporated the following:
Component #1: “Ethereum Virtual Machine” (EVM)
Ethereum is a collection of protocols that allow developers to create “Decentralized Applications” (DApps). “Ethereum Virtual Machine” (EVM) assumes the central position in this collection of protocols. This executes the code the developers write as part of their DApps.
Get a complimentary discovery call and a free ballpark estimate for your project
Trusted by 100x of startups and companies like
Read more about EVM in “What is EVM?”.
Fabric used to have Hyperledger Burrow. It was a project under the Hyperledger community that provided a blockchain client. It also provided a smart contractor interpreter, modeled after EVM. You can read more about Hyperledger Burrow.
Component #2: Accounts
Ethereum features the following types of accounts:
- “Externally Owned Accounts” (EOAs): On the Ethereum blockchain network, these are the user accounts. These represent the public address of users and their Ether (ETH) balance. Users control these with their private keys. Read more about EOAs in “What Are Externally Owned Accounts (EOAs) in Ethereum?”.
- “Contract Accounts” (CAs): These are controlled by smart contracts. These contain the runtime EVM bytecode for a contract.
At the time of writing, there is no known plan of any Hyperledger Fabric coin. Therefore, Fabric will generate EOAs on the fly. Fabric will store CAs on the chain.
Component #3: Ethereum client
Ethereum developers use the “TestRPC” Ethereum client. Read more about it in their GitHub repository. Fabric EVM implementation uses the JSON RPC API partially.
Ethereum developers also use “Web3.js”, i.e., a tool to communicate with the Ethereum blockchain. The Fabric EVM implementation uses Fab3, which allows the partial implementation of the JSON RPC API. You can read more about Fab3 in this tutorial on GitHub.
Component #4: “Gas”
“Gas” is a kind of fee. Users need to pay enough gas to execute any operation on the Ethereum blockchain network. Smart contract transactions that require more computation requires higher gas than the ones with less computing requirements.
A smart contract transaction won’t execute if users provide insufficient gas. Ethereum users pay for gas with Ether (ETH), i.e., the native cryptocurrency of the platform.
Read this Ethereum stack exchange Q&A thread for more information. In case the Fabric EVM implementation, a large amount of gas is hardcoded.
How to set up a Fabric Smart Contract using Ethereum?
I will now explain the process to set up a basic smart contract on Fabric, as follows:
Hire expert developers for your next project
1,200 top developers
us since 2016
Step #1: Install the required tools
You need to install the following tools:
- cURL: It’s a tool for transferring files from or to a server. Install it following the instructions here.
- Docker: Developers increasingly use “Docker” to create, deploy, and run applications using containers. Docker helps programmers to create a complete package for an app, including libraries and dependencies. They can then deploy it on their choice of platform. Read the installation instructions on the Docker website. The installation process includes “Docker Compose”, i.e., a tool to define and run multi-container apps.
- Programming languages: You are setting up Ethereum smart contracts on Fabric to use in your application. Developers typically write apps on Fabric using “Go” or Node.js. You need to install either of them. Check the Go programming language website for installation instructions. Fabric currently supports Node.js v8.9, and you can install it using their instructions.
Read more in this Fabric prerequisites web page.
Step #2: Install binaries, samples, and Docker images
Fabric documentation already includes sample applications, and developers can use these to expedite their project. Fabric also provides binaries and Docker images for these. You will find these useful to fast-track your projects. Read “Install Samples, Binaries and Docker Images” for more details.
Step #3: Install Fabric EVM chaincode
Now, you need to install the Fabric EVM chaincode. This will enable you to interact with the Ethereum smart contracts you will write, using Fabric. Follow the detailed instructions in this guide.
Step #4: Use “Remix” IDE to write Solidity smart contracts
Remix is a web-based “Integrated Development Environment” (IDE) for Ethereum smart contract development. You don’t need to install anything, just start writing Solidity smart contracts on Remix.
Step #5: Initial configuration of Fabric EVM chaincode
From this point onwards, I will use a guide that Rahul Bairathi, a Fabric expert has written. The article explains how to code Ethereum smart contracts using Fabric. You can read it in “Solidity smart contract on Hyperledger Fabric”. I will refer to it as a “reference article”.
After you have cloned the sample projects from GitHub as I have mentioned above, you need to do the following configurations:
- Navigate to the “first-network” folder, and modify the Docker compose “Command Line Interface” (CLI) file. This is to map the folder where you have stored the code you had cloned from GitHub.
- Start the network.
- Navigate to the CLI Docker container and install the EVM chaincode.
- Instantiate the EVM chaincode.
Follow the commands in the “reference article”.
Step #6: Write Solidity smart contracts
The next step involves writing Solidity smart contracts using the Remix IDE. If your team guidance, they can get check out this Remix documentation.
Step #7: Compile and deploy smart contracts
You need to take the following steps:
Hire expert developers for your next project
- Compile the smart contract on Remix.
- Copy the Bytecode. You need it to deploy the smart contract. Read more about it in this Ethereum stack exchange Q&A thread.
- Paste the bytecode in any text editor. This will be in JSON format.
- Deploy the smart contract using the “peer chaincode invoke” process. Your team can find the syntax of this command in this Fabric documentation page.
Read the “reference article” for more details.
Planning to build blockchain solutions using Fabric and Ethereum smart contracts?
Fabric and Ethereum have significant documentation. However, these are niche skills. A smart contract defines different business objects and logics. Developing smart contracts and other blockchain solutions using Ethereum on Fabric is a complex project. Consider engaging a reputed software development partner.
Read our guide “How to find the best software development company?” before you select a partner for your smart contract project.
If you, as a CEO or CTO, are still finding the right blockchain developers to develop fabric smart contracts for your business processes, DevTeam.Space can help you. We have a community of expert software developers, well-versed in the latest blockchain technology.
Leave us your initial smart contract development requirements via this quick form and one of our technical managers will get back to you at the earliest and assit you in team building, product development, management etc.
Frequently Asked Questions on Hyperledger smart contracts
You need to do the following to set up Ethereum smart contracts on Hyperledger Fabric:
Install the Hyperledger Fabric framework on a “Blockchain-as-a-Service” (BaaS) platform like AWS.
Install tools like Docker, cURL. Install either Golang or Node.js.
Install binaries, sample chaincodes (smart contracts on Hyperledger Fabric), Docker images, and EVM (Ethereum Virtual Machine) chaincode.
Write Solidity smart contracts using the Remix IDE and configure the Fabric EVM chaincode.
Compile, test, and deploy smart contracts on Hyperledger Fabric.
Hyperledger Fabric supports smart contracts. The Hyperledger Fabric developer community uses the term “chaincodes” to denote smart contracts.
Starting Q4-2018, Hyperledger Fabric supports Ethereum smart contracts. Developers can write smart contract business logic in Solidity or Vyper.
Alexey Semeney
Founder of DevTeam.Space
Hire Alexey and His Team To Build a Great Product
Alexey is the founder of DevTeam.Space. He is award nominee among TOP 26 mentors of FI's 'Global Startup Mentor Awards'.
Alexey is Expert Startup Review Panel member and advices the oldest angel investment group in Silicon Valley on products investment deals.