- How to Set up Hyperledger Smart Contracts for Ethereum
We hope you enjoy reading this article.
If you want our expert developers and designers to work on your online product, click here
Latest posts by Aran Davies (see all)
- How to Build a Dental Practice Management Software - 16 Mar, 2023
- The Future of Tech is Here: The Foldable Phone Revolution - 14 Feb, 2023
- What are AI Development Tools? - 13 Feb, 2023
Planning on using Hyperledger Fabric to set up Ethereum smart contracts? This is an important topic that we will cover here.
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.
Read more about EVM in “What is EVM?”.
Hire expert developers for your next project
Fabric has incorporated Hyperledger Burrow. This is another Hyperledger project, which provides a blockchain client. It also provides a smart contractor interpreter, modeled after EVM. Read more about Hyperledger Burrow here. Developers can create chaincode on it.
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 “Blockchain basics 02: a complete view on Ethereum blockchain”.
- “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 Hyperledger Burrow-based EVM chaincode. This will enable you to interact with the Ethereum smart contracts you will write, using Fabric. Follow the detailed instructions in this GitHub repository.
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
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 Hyperledger Burrow-based 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.