THEBLOCKCHAINGUY

Personal blog byHoliviel Valdez.

Documenting and learning about
blockchain development.

Hardhat vs Truffle vs Remix - Which is the best for blockchain development?

October 25, 2021 • 👀10 min read

With the recent boom of blockchain development, many developers want to know the best tools to start working in this new and amazing world. If you spend 10 seconds googling or searching out the advice of blockchains communities, the most popular options that everyone will gonna talk about are Hardhat, Truffle and Remix.

These are really good blockchain development environments to compile, test and deploy blockchain software. But at the end of the day, is hard to not start doing comparisons of which tool is the best for your project necessities and which one will save you time and gives you the best development experience.

This article is a comparison between Hardhat, Truffle, and Remix, focusing on their characteristics and ecosystem to be able to make a decision of which library to use for your particular use case.

hardhat icon What is Hardhat?

Hardhat was created by Nomic Labs, helps developers to manage and automate the common tasks of the process of building smart contracts and Dapps, as easily introducing more functionality around this workflow. That means you can compile, run and test smart contracts at the very core.

It focuses on solidity debugging, presents explicit stack traces and error messages when transactions fail. Hardhat comes built-in with Hardhat Network, a local Ethereum network designed for development, and a CLI to interact with the core functionalities.

Example of he Hardhat CLI:

$ npx hardhat
888 888 888 888 888
888 888 888 888 888
888 888 888 888 888
8888888888 8888b. 888d888 .d88888 88888b. 8888b. 888888
888 888 "88b 888P" d88" 888 888 "88b "88b 888
888 888 .d888888 888 888 888 888 888 .d888888 888
888 888 888 888 888 Y88b 888 888 888 888 888 Y88b.
888 888 "Y888888 888 "Y88888 888 888 "Y888888 "Y888
Welcome to Hardhat v2.0.8
? What do you want to do? …
❯ Create a sample project
Create an empty hardhat.config.js
Quit

Available Hardhat commands:

$ npx hardhat
Hardhat version 2.0.8
Usage: hardhat [GLOBAL OPTIONS] <TASK> [TASK OPTIONS]
GLOBAL OPTIONS:
--config A Hardhat config file.
--emoji Use emoji in messages.
--help Shows this message, or a task's help if its name is provided
--max-memory The maximum amount of memory that Hardhat can use.
--network The network to connect to.
--show-stack-traces Show stack traces.
--tsconfig Reserved hardhat argument -- Has no effect.
--verbose Enables Hardhat verbose logging
--version Shows hardhat's version.
AVAILABLE TASKS:
accounts Prints the list of accounts
check Check whatever you need
clean Clears the cache and deletes all artifacts
compile Compiles the entire project, building all artifacts
console Opens a hardhat console
flatten Flattens and prints contracts and their dependencies
help Prints this message
node Starts a JSON-RPC server on top of Hardhat Network
run Runs a user-defined script after compiling the project
test Runs mocha tests
To get help for a specific task run: npx hardhat help [task]

truffle icon What is Truffle?

Truffle was created by Consensys, is a development environment, testing framework, and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM). With Truffle you get a lot of important characteristics that can help you to develop Dapps like an interactive console for direct contract communication, network management to deploy to any public and private network, contract compilation, linking, and binary management.

Another part of the Truffle ecosystem is Ganache a local Ethereum blockchain for test solidity contracts, you can use Ganache in two different ways you can use the Ganache CLI (the most complete version) or you can use the Ganache UI (the most friendly version especially for beginners) is up to you to test and see which version do you prefer.

Ganache UI
Ganache UI running.

Sooner or later you will have to develop a UI so the people can start to interacat with your Dapps, thats why Ganache has Drizzle a collection of front end libraries. The core of Drizzle uses redux so you can use all the tools available around redux and leave the synchronization of contract and transaction data to redux.

remix iconWhat is Remix?

Remix is an open source web and desktop app. Remix is used for write, test and deploy smart contracts, you can use it as a playground to learn and teach blockchain development. The Remix IDE (every time you see remix in this article, I am talking about the Remix IDE unless specify the contrary) is part of the Remix project which is a platform for development tools that use a plugin architecture.

Remix is composed of a chain of sub-projects including Remix Plugin Engine, Remix Libs, and of course Remix IDE. It is written in javascript and supports a browser and desktop version.

remix IDE
The Remix IDE with solidity code.

hardhat iconDocumentation

The Hardhat documentation is very clear and organized, you can find different guides of how to start with hardhat from the basics of the CLI to start running your local blockchain until the core aspects of Hardhat as the tasks, plugins, typescript support, and how to deal with different frameworks and integrations.

Another really helpful section of the documentation is the tutorial page. This is a step to step guide to create a simple smart contract from the scratch with the help of Hardhat and how to use the contract code in the Front End with React. This is very useful to start to figure out how to use Hardhat and even if you are new in blockchain development, is a good resource to know how to put everything together.

The downside of the documentation is you will not find a lot of tutorials or videos outside of the main documentation or the inner communities, at least at the moment writing this article. The good thing is more companies and developers are creating resources and articles on how to use simple and complex functionalities, plus adding feedback on how to resolve the most common problems and issues this is really crucial to growing the popularity of any library or framework.

truffle iconDocumentation

The Truffle documentation is clear and you can start learning the basics of how to create a project, migrating with Truffle develop or Ganache, connect Truffle to metamask and start interacting with the contracts.

Truffle has a guides section to guide you to common tasks of Truffle development, these guides are not a step by step guide of a single project and are not so updated. The good side is that Truffle is not a new tool for blockchain development, there are more articles and tutorials out there, so you can find many resources because of the longevity and development ecosystem built around it.

remix iconDocumentation

The Remix documentation is made in a way that even you are not experienced developing blockchain software will be easy for you to start learning. You will see multiple images with arrows and text to identify each tool of Remix so, you will familiarize yourself with it very fast and you will start to customize Remix for your own necessities. The documentation is not just limited to show you parts of the UI, they show you how to use remix with different integrations for example Hardhat, how to do unit testing, and other important aspects to master Remix.

explanation of remix compiler
Example of Remix documentation explaining the compiler tab.

The other good part is they update the documentation frequently, this is a very good thing because the documentation about blockchain tools generally is not updated and this is an important aspect for this very changing environment even if you see an error you can open an issue on Github or fix that edit yourself and made a pull request to the documentation repo.

remix docs github edit
You can edit the Remix documentation if you see any errors or want to add more content.

hardhat iconCommunity

The community is very active and helpful, you can find the core members and experienced developers in the official Discord server there you can find many channels for different topics related to Hardhat and the friendly help of many members.

The downside of community is the fact that you only will find more specific help in the Discord server, there is not a support forum or many questions related or resolved about Hardhat in places like StackOverflow because is relatively new but the good part is this will change with time and the usage.

truffle iconCommunity

The community of Truffle is not behind other developers communities you can find all the community channels in the community section of the main Truffle website, I recommend asking questions in the Discord server of Consensys there is a channel just about Truffle. Therefore, you can ask all the questions you have and you will have an answer as soon as possible.

You can find answers when you are stuck outside of the main community channels, on places like StackOverflow or Stackexchange the community is big, so finding answers in these places and other kinds of blogs or forums are something common.

remix iconCommunity

The community of Remix is very supportive, you can find the answer of your questions if you are stuck in the main channel of the gitter and ask for help from any member of the community.

If you want to help to develop a custom plugin or you have doubts to develop a plugin for you or the company you work can go to the contributors’ channel if you want more information about working on Remix tools.

The community have sometime around, to find answers in other places outside of the main community, when you are stuck your primary source will be StackOverflow and then followed by Stackexchange.

hardhat iconLibraries and Plugins

Hardhat has a complete ecosystem around plugins. Plugins are the backbone of Hardhat, they are pieces of reusable configuration that you can use in any kind of project, you can use official plugins made by Hardhat, you can use plugins made by other members of the Hardhat community or you can make your own.

Plugins behind the scenes are extending the Hardhat Runtime Environment (HRE), defining new tasks or overriding existing ones. For example, you can create a plugin to read your solidity code and create hooks ready to use for React.

You can create a basic plugin addign this to hardhat.config.js

// Will make hi available everywhere where the environment is accessible
extendEnvironment((hre) => {
hre.hi = "Hello, Hardhat!";
});
task("envhello", (args, hre) => {
console.log(hre.hi);
});
module.exports = {};
});

Output:

$ npx hardhat envhello
Hello, Hardhat!

truffle iconLibraries and Plugins

The ecosystem of Truffle is around boxes. Truffle boxes are helpful boilerplates that speed up your project development so you can focus on the important parts. Boxes have a combination of solidity contracts, libraries, and front end ready to use, you can find official boxes, made by the community or you can make your own too.

Each Box essentially revolves around a truffle-box.json configuration file. This file dictates what commands should be run at the point of unboxing so that it’s ready to go. If you're starting from scratch, there is blueprint box with the configuration file with common values.

// Example of truffle-box.json
{
"ignore": ["README.md", ".gitignore"],
"commands": {
"Compile contracts": "truffle compile",
"Migrate contracts": "truffle migrate",
"Test contracts": "truffle test"
},
"hooks": {
"post-unpack": ""
}
}

The downside of boxes is not flexible when you want specific things. You have to use the complete box not just a part of it, and when you want to override or extend Truffle to add specific functionality, like generate a UML grammar for each contract and use it in different projects, this is not an easy functionality to add.

remix iconLibraries and Plugins

Remix has a plugin manager, where you can access the plugins made by the Remix team (solidity compiler, solidity unit testing) and made by other members of the community (optimism compiler, celo). If you click the icon plug you will see the list of all available plugins, you can connect local plugins made by yourself when you want to create a custom functionality of your project.

list of remix plugins
The plugin manager of Remix with the list of all the available plugins.

The downside of the plugins of Remix is there is not a diversity of plugins, but this will be fixed when the blockchain ecosystem grows and more developers participate in coding and provide more plugins for each framework.

hardhat iconTesting

To test your smart contracts with Hardhat you have to use javascript or typescript. The most popular option to test your contracts is the library Ethers.js to interact with the smarts contracts and Waffle to test the smarts contracts (tests using Waffle are written with Mocha and Chai).

Example of the test using Ethers.js and Waffle:

const { expect } = require("chai");
const { ethers } = require("hardhat");
describe("Greeter", function () {
it("Should return the new greeting once it's changed", async function () {
const Greeter = await ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, world!");
await greeter.deployed();
expect(await greeter.greet()).to.equal("Hello, world!");
const setGreetingTx = await greeter.setGreeting("Hola, mundo!");
await setGreetingTx.wait();
expect(await greeter.greet()).to.equal("Hola, mundo!");
});
});

Output:

$ npx hardhat test
Contract: Greeter
✓ Should return the new greeting once it's changed (762ms)
1 passing (762ms)

You can use Truffle and Web3.js too to test your smart contracts, with this you will have compatibility with the @truffle/contract package. Truffle 4 and Truffle 5 are supported using the @nomiclabs/hardhat-truffle4 and @nomiclabs/hardhat-truffle5.

Example of a test using Web3.js and Truffle:

const Greeter = artifacts.require("Greeter");
// Truffle test
contract("Greeter", (accounts) => {
it("Should return the new greeting once it's changed", async function () {
const greeter = await Greeter.new("Hello, world!");
assert.equal(await greeter.greet(), "Hello, world!");
await greeter.setGreeting("Hola, mundo!");
assert.equal(await greeter.greet(), "Hola, mundo!");
});
});
describe("Greeter contract", function () {
let accounts;
before(async function () {
accounts = await web3.eth.getAccounts();
});
describe("Deployment", function () {
it("Should deploy with the right greeting", async function () {
const greeter = await Greeter.new("Hello, world!");
assert.equal(await greeter.greet(), "Hello, world!");
const greeter2 = await Greeter.new("Hola, mundo!");
assert.equal(await greeter2.greet(), "Hola, mundo!");
});
});
});

Output:

$ npx hardhat test
Contract: Greeter
✓ Should return the new greeting once it's changed (265ms)
Greeter contract
Deployment
✓ Should deploy with the right greeting (114ms)
2 passing (398ms)

truffle iconTesting

Truffle comes with a suite of testing libraries to make testing easier out of the box, the first way to test your smart contracts is with javascript and typescript. Truffle comes with Mocha, Chai, and Web3.js to write javascript tests.

const MetaCoin = artifacts.require("MetaCoin");
contract("2nd MetaCoin test", async (accounts) => {
it("should put 10000 MetaCoin in the first account", async () => {
const instance = await MetaCoin.deployed();
const balance = await instance.getBalance.call(accounts[0]);
assert.equal(balance.valueOf(), 10000);
});
it("should call a function that depends on a linked library", async () => {
const meta = await MetaCoin.deployed();
const outCoinBalance = await meta.getBalance.call(accounts[0]);
const metaCoinBalance = outCoinBalance.toNumber();
const outCoinBalanceEth = await meta.getBalanceInEth.call(accounts[0]);
const metaCoinEthBalance = outCoinBalanceEth.toNumber();
assert.equal(metaCoinEthBalance, 2 * metaCoinBalance);
});
it("should send coin correctly", async () => {
const account_one = accounts[0];
const account_two = accounts[1];
let balance;
const amount = 10;
const instance = await MetaCoin.deployed();
const meta = instance;
balance = await meta.getBalance.call(account_one);
const account_one_starting_balance = balance.toNumber();
balance = await meta.getBalance.call(account_two);
const account_two_starting_balance = balance.toNumber();
await meta.sendCoin(account_two, amount, { from: account_one });
balance = await meta.getBalance.call(account_one);
const account_one_ending_balance = balance.toNumber();
balance = await meta.getBalance.call(account_two);
const account_two_ending_balance = balance.toNumber();
assert.equal(
account_one_ending_balance,
account_one_starting_balance - amount,
"Amount wasn't correctly taken from the sender"
);
assert.equal(
account_two_ending_balance,
account_two_starting_balance + amount,
"Amount wasn't correctly sent to the receiver"
);
});
});

Output:

Contract: MetaCoin
√ should put 10000 MetaCoin in the first account (83ms)
√ should call a function that depends on a linked library (43ms)
√ should send coin correctly (122ms)
3 passing (293ms)

The other way to make tests is in Solidity, for test your contracts in scenarios more advanced. Truffle's Solidity testing framework was made with these kinds of issues in mind:

  • ▪︎ Solidity tests shouldn't extend from any contract. This gives you complete control of the contracts you write.

  • ▪︎ Solidity tests shouldn't be beholden to any assertion library. Truffle comes with a default assertion library, but you can change this library to fit your project requirements.

  • ▪︎ You should be able to run your Solidity tests against any Ethereum client.

Example of solidity test:

pragma solidity >=0.4.25 <0.6.0;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/MetaCoin.sol";
contract TestMetaCoin {
function testInitialBalanceUsingDeployedContract() {
MetaCoin meta = MetaCoin(DeployedAddresses.MetaCoin());
uint expected = 10000;
Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially");
}
function testInitialBalanceWithNewMetaCoin() {
MetaCoin meta = new MetaCoin();
uint expected = 10000;
Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially");
}
}

Output:

$ truffle test
Compiling your contracts...
===========================
> Compiling ./test/TestMetaCoin.sol
TestMetaCoin
✓ testInitialBalanceWithNewMetaCoin (65ms)
Contract: MetaCoin
✓ should put 10000 MetaCoin in the first account (38ms)
1 passing (7s)

remix iconTesting

Testing with Remix is done only with solidity and is the easiest way to implement tests to your smart contracts especially when you are starting to learn about blockchain development. The solidity unit testing plugin is already active and you will see a contract test example to have an example of how testing works inside Remix.

Example of solidity test with Remix:

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "remix_tests.sol"; // this import is automatically injected by Remix.
import "../contracts/3_Ballot.sol";
contract BallotTest {
bytes32[] proposalNames;
Ballot ballotToTest;
function beforeAll () public {
proposalNames.push(bytes32("candidate1"));
ballotToTest = new Ballot(proposalNames);
}
function checkWinningProposal () public {
ballotToTest.vote(0);
Assert.equal(ballotToTest.winningProposal(), uint(0), "proposal at index 0 should be the winning proposal");
Assert.equal(ballotToTest.winnerName(), bytes32("candidate1"), "candidate1 should be the winner name");
}
function checkWinninProposalWithReturnValue () public view returns (bool) {
return ballotToTest.winningProposal() == 0;
}
}

To see if your test pass or fails, click the check icon and click run to run your tests if your test passes you will see a green text if your test fails you will see a red label. You can research the reason why they are failing, there will be assertion details to the reason for failure if you click the failed test you will see the line of code where the test fails.

example of solidity remix test
Remix test using solidity unit testing plugin.

You can customize your tests just with few clicks, like the compiler version of solidity or the EVM version to test your smart contracts in different scenarios.

remix customization tab
Remix customization tab.
hardhat iconWhat Companies Use Hardhat?

Openzeppelin

OpenZeppelin provides security products to build, automate, and operate decentralized applications. OpenZeppelin is the premier crypto cybersecurity technology and services company, trusted by the most used DeFi and NFT projects for leading crypto organizations including Coinbase, Ethereum Foundation, etc...

Optimism

Optimism is a Layer 2 scaling solution for Ethereum that can support all of Ethereum’s Dapps. Instead of running all computation and data on the Ethereum network, Optimism puts all transaction data on-chain and runs computation off-chain, increasing Ethereum’s transactions per second and decreasing transaction fees.

Aave

Aave is a decentralised non-custodial liquidity market protocol where users can participate as depositors or borrowers. Depositors provide liquidity to the market to earn a passive income, while borrowers are able to borrow in an overcollateralised (perpetually) or undercollateralised (one-block liquidity) fashion.

truffle iconWhat Companies Use Truffle?

Bitgo

BitGo is the leader in institutional digital asset custody, trading, and finance. BitGo enables clients to navigate the complex landscape of digital assets with a connected, compliant, and secure suite of solutions.

1inch

1inch's protocol scrapes many DEXs to find the cheapest platform, accounting for fees and the price of the asset itself.This DEX aggregator automatically pinpoints the cheapest trade to execute, making it a valuable tool for any trader. Instead of relying on a single DeFi protocol to buy a crypto asset

JPMorgan Chase & Co

JPMorgan Chase & Co. is an American multinational investment bank and financial services holding company headquartered in New York City. it is a major provider of various investment banking and financial services. As of 2021 it is the largest lender to the fossil fuel industry in the world.

remix iconWhat Companies Use Remix?

OpenSea

OpenSea is a decentralized non-fungible token (NFT) marketplace for buying, selling, and trading NFTs. OpenSea brands itself as the biggest marketplace for digital goods was built through lean collaboration and an eagerness to invest in exciting new technologies.

Ethereum org

Ethereum.org is a public, open-source resource for the Ethereum community that anyone can contribute to, is an educational resource, designed to help new users become familiar with Ethereum and its key concepts.

Moonbeam

Moonbeam is a developer-oriented blockchain that strives to provide compatibility with the existing Ethereum developer toolchain and network. It does this by providing a full EVM implementation, a Web3-compatible API, and bridges that connect Moonbeam to existing Ethereum networks.

hardhat icontruffle iconremix iconPopularity

Fortunately to know who are the most used blockchain framework you can consult the data from the last solidity developer survey 2020. The survey received 193 responses from 48 different countries. In the question about Ethereum-specific development environment, Truffle was the most popular with 35% of responses, followed by Remix 29% and Hardhat 23%.

Even if this is a small number of people participating in this survey, you can have an idea of how are these frameworks distributed around professionals and amateurs blockchain devs.

Most popular frameworks of blockchain
Survey results from solidity developer survey 2020.

hardhat icontruffle iconremix iconConclusion

With all the information in this article, you may have a better idea of the options that give you the most popular blockchain development tools, maybe you even know what option you want to start your next project.

My advice is you can start with Remix because you don't even have to deal with installing dependencies in your local and you can start without so much trouble coding and learn the basics of solidity, testing, and deployment to test net even mainnets.

Then you can go with Hardhat because of its unopinionated nature, you can install what you exactly want and expand the Hardhat Runtime Environment, good documentation and the growing community is one of the reasons why many companies and myself use Hardhat as our main blockchain development tool.

At the end of the day, the only thing you need to do is start with a tool and start creating things with it, then you can translate all the knowledge you have to any tool. The most important thing is the knowledge and experienced that will lead any project you want without worried about too much about the tool you are using.