Convert Figma logo to code with AI

NomicFoundation logohardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.

7,155
1,373
7,155
517

Top Related Projects

8,104

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.

14,020

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.

Dapp, Seth, Hevm, and more

3,826

Security analysis tool for EVM bytecode. Supports smart contracts built for Ethereum, Hedera, Quorum, Vechain, Rootstock, Tron and other EVM-compatible blockchains.

5,235

Static Analyzer for Solidity and Vyper

OpenZeppelin Contracts is a library for secure smart contract development.

Quick Overview

Hardhat is a development environment for Ethereum software. It's designed to help developers manage and automate the recurring tasks inherent to building smart contracts and dApps, as well as easily introducing more functionality around this workflow. This includes compiling, deploying, testing, and debugging Ethereum software.

Pros

  • Flexible and extensible plugin-based architecture
  • Built-in Solidity compiler and debugger
  • Robust testing framework with Mocha and Chai
  • Active community and regular updates

Cons

  • Steeper learning curve compared to some alternatives
  • Can be resource-intensive for large projects
  • Some users report occasional stability issues
  • Limited support for non-Ethereum blockchains

Code Examples

  1. Deploying a smart contract:
const hre = require("hardhat");

async function main() {
  const MyContract = await hre.ethers.getContractFactory("MyContract");
  const myContract = await MyContract.deploy();
  await myContract.deployed();
  console.log("MyContract deployed to:", myContract.address);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });
  1. Writing a test for a smart contract:
const { expect } = require("chai");

describe("MyContract", function () {
  it("Should return the correct greeting", async function () {
    const MyContract = await ethers.getContractFactory("MyContract");
    const myContract = await MyContract.deploy();
    await myContract.deployed();

    expect(await myContract.greet()).to.equal("Hello, World!");
  });
});
  1. Using Hardhat Console:
// In Hardhat Console
> await ethers.provider.getBlockNumber()
12345
> const MyContract = await ethers.getContractFactory("MyContract")
undefined
> const myContract = await MyContract.deploy()
undefined
> await myContract.deployed()

Getting Started

  1. Install Hardhat:
npm install --save-dev hardhat
  1. Create a Hardhat project:
npx hardhat
  1. Compile your contracts:
npx hardhat compile
  1. Run tests:
npx hardhat test
  1. Deploy to a network:
npx hardhat run scripts/deploy.js --network <network-name>

Competitor Comparisons

8,104

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.

Pros of Foundry

  • Faster test execution due to Rust implementation
  • Built-in fuzzing capabilities for more thorough testing
  • Seamless integration with Solidity, allowing tests in Solidity

Cons of Foundry

  • Steeper learning curve, especially for developers not familiar with Rust
  • Smaller ecosystem and community compared to Hardhat
  • Limited plugin support and fewer integrations with external tools

Code Comparison

Hardhat test example:

describe("Token", function () {
  it("Should return the new greeting once it's changed", async function () {
    const Token = await ethers.getContractFactory("Token");
    const token = await Token.deploy();
    await token.deployed();
    expect(await token.greet()).to.equal("Hello, World!");
  });
});

Foundry test example:

contract TokenTest is Test {
    function testGreeting() public {
        Token token = new Token();
        assertEq(token.greet(), "Hello, World!");
    }
}

Both Hardhat and Foundry are popular Ethereum development environments, each with its own strengths. Hardhat offers a more established ecosystem and easier onboarding for JavaScript developers, while Foundry provides faster execution and native Solidity testing. The choice between them depends on project requirements and team preferences.

14,020

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.

Pros of Truffle

  • More established and mature ecosystem with a longer history in the Ethereum development space
  • Integrated with Ganache, providing a seamless local blockchain environment for testing
  • Supports multiple programming languages, including Solidity and Vyper

Cons of Truffle

  • Slower build and test execution times compared to Hardhat
  • Less flexible configuration options and plugin system
  • Limited support for newer Ethereum features and optimizations

Code Comparison

Truffle configuration:

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*"
    }
  }
};

Hardhat configuration:

module.exports = {
  networks: {
    hardhat: {},
    localhost: {
      url: "http://127.0.0.1:8545"
    }
  }
};

Both Truffle and Hardhat are popular development environments for Ethereum smart contracts. Truffle offers a more comprehensive suite of tools and has been around longer, while Hardhat provides faster performance and greater flexibility. The choice between the two often depends on specific project requirements and developer preferences.

Dapp, Seth, Hevm, and more

Pros of dapptools

  • More lightweight and Unix-philosophy aligned
  • Offers a comprehensive suite of CLI tools for Ethereum development
  • Provides powerful debugging capabilities with hevm

Cons of dapptools

  • Steeper learning curve, especially for developers new to Ethereum
  • Less extensive documentation compared to Hardhat
  • Smaller community and ecosystem

Code Comparison

dapptools (using Seth):

seth send $CONTRACT_ADDRESS "transfer(address,uint256)" $RECIPIENT $AMOUNT

Hardhat:

await contract.transfer(recipient, amount);

Key Differences

  • dapptools focuses on command-line tools, while Hardhat provides a JavaScript-based development environment
  • Hardhat offers a more user-friendly experience with extensive plugins and integrations
  • dapptools excels in low-level interactions and formal verification, while Hardhat emphasizes ease of use and testing

Use Cases

  • Choose dapptools for advanced Ethereum development with a preference for Unix-style tools
  • Opt for Hardhat when seeking a more accessible, JavaScript-centric development experience with broader ecosystem support
3,826

Security analysis tool for EVM bytecode. Supports smart contracts built for Ethereum, Hedera, Quorum, Vechain, Rootstock, Tron and other EVM-compatible blockchains.

Pros of Mythril

  • Specialized in security analysis and vulnerability detection for smart contracts
  • Utilizes symbolic execution and SMT solving for in-depth analysis
  • Supports multiple blockchain platforms beyond Ethereum

Cons of Mythril

  • Steeper learning curve for developers not familiar with security tools
  • May produce false positives that require manual verification
  • Less comprehensive development environment compared to Hardhat

Code Comparison

Hardhat (JavaScript-based development environment):

require("@nomiclabs/hardhat-waffle");

module.exports = {
  solidity: "0.8.0",
  networks: {
    hardhat: {}
  }
};

Mythril (Python-based security analysis tool):

from mythril.mythril import MythrilDisassembler, MythrilAnalyzer
from mythril.ethereum import util

disassembler = MythrilDisassembler()
analyzer = MythrilAnalyzer(disassembler)

Hardhat focuses on providing a complete development environment for Ethereum smart contracts, including testing, deployment, and network management. It's more user-friendly for developers and offers a wider range of features for the entire development lifecycle.

Mythril, on the other hand, specializes in security analysis and vulnerability detection. It's a powerful tool for identifying potential security issues in smart contracts but requires more expertise to use effectively.

5,235

Static Analyzer for Solidity and Vyper

Pros of Slither

  • Specialized static analysis tool for Solidity, offering in-depth security checks
  • Provides a wide range of detectors for common vulnerabilities and best practices
  • Can be integrated into CI/CD pipelines for automated security scanning

Cons of Slither

  • Limited to static analysis and doesn't provide a full development environment
  • Requires additional tools for compilation, testing, and deployment
  • May produce false positives that need manual review

Code Comparison

Slither (analyzing a contract):

slither = Slither('MyContract.sol')
print(slither.slither_analyzer.detectors)

Hardhat (compiling and running tests):

const { ethers } = require("hardhat");

describe("MyContract", function() {
  it("Should deploy successfully", async function() {
    const MyContract = await ethers.getContractFactory("MyContract");
    await MyContract.deploy();
  });
});

Summary

Slither is a specialized static analysis tool for Solidity smart contracts, focusing on security and best practices. Hardhat, on the other hand, is a comprehensive development environment for Ethereum. While Slither excels in detecting potential vulnerabilities, Hardhat provides a more complete toolkit for smart contract development, testing, and deployment. Developers often use both tools in conjunction to ensure both robust development and security practices.

OpenZeppelin Contracts is a library for secure smart contract development.

Pros of openzeppelin-contracts

  • Provides a comprehensive library of secure, reusable smart contracts
  • Extensively audited and battle-tested in production environments
  • Offers standardized implementations for common token standards (ERC20, ERC721, etc.)

Cons of openzeppelin-contracts

  • Focused solely on contract libraries, not a full development environment
  • May require additional tools for testing and deployment
  • Less flexibility for custom development workflows

Code Comparison

openzeppelin-contracts:

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("MyToken", "MTK") {
        _mint(msg.sender, initialSupply);
    }
}

Hardhat:

const { ethers } = require("hardhat");

async function main() {
  const MyToken = await ethers.getContractFactory("MyToken");
  const myToken = await MyToken.deploy(1000000);
  await myToken.deployed();
}

main().catch((error) => {
  console.error(error);
  process.exit(1);
});

Summary

openzeppelin-contracts excels in providing secure, standardized smart contract implementations, while Hardhat offers a comprehensive development environment for Ethereum projects. The choice between them depends on whether you need ready-to-use contract libraries or a flexible development toolkit.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

NPM Package GitPOAP Badge


Hardhat is an Ethereum development environment for professionals. It facilitates performing frequent tasks, such as running tests, automatically checking code for mistakes or interacting with a smart contract. Check out the plugin list to use it with your existing tools.

Built by the Nomic Foundation for the Ethereum community.

Join our Hardhat Support Discord server to stay up to date on new releases, plugins and tutorials.


💡 The Nomic Foundation is hiring! Check our open positions.


Installation

To install Hardhat, go to an empty folder, initialize an npm project (i.e. npm init), and run

npm install --save-dev hardhat

Once it's installed, just run this command and follow its instructions:

npx hardhat init

Documentation

On Hardhat's website you will find:

Contributing

Contributions are always welcome! Feel free to open any issue or send a pull request.

Go to CONTRIBUTING.md to learn about how to set up Hardhat's development environment.

Feedback, help and news

Hardhat Support Discord server: for questions and feedback.

Follow Hardhat on Twitter.

Happy building!

👷‍♀️👷‍♂️👷‍♀️👷‍♂️👷‍♀️👷‍♂️👷‍♀️👷‍♂️👷‍♀️👷‍♂️👷‍♀️👷‍♂️👷‍♀️👷‍♂️

NPM DownloadsLast 30 Days