Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hardhat

Package Overview
Dependencies
Maintainers
3
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hardhat

Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.

  • 2.13.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created

What is hardhat?

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software. It helps developers manage and automate the recurring tasks that are inherent to the process of building smart contracts and dApps, as well as easily introducing more functionality around this workflow.

What are hardhat's main functionalities?

Compiling Smart Contracts

Hardhat can compile your smart contracts using the Solidity compiler. You can specify the version of Solidity you want to use in the configuration file.

module.exports = {
  solidity: "0.8.4",
};

Running Tests

Hardhat allows you to write tests for your smart contracts using popular testing frameworks like Mocha and Chai. This example shows a simple test for a token contract.

const { expect } = require("chai");

describe("Token contract", function () {
  it("Deployment should assign the total supply of tokens to the owner", async function () {
    const [owner] = await ethers.getSigners();
    const Token = await ethers.getContractFactory("Token");
    const hardhatToken = await Token.deploy();
    const ownerBalance = await hardhatToken.balanceOf(owner.address);
    expect(await hardhatToken.totalSupply()).to.equal(ownerBalance);
  });
});

Deploying Contracts

Hardhat makes it easy to deploy your smart contracts to the Ethereum network. This script deploys a token contract and logs the address to which it was deployed.

async function main() {
  const [deployer] = await ethers.getSigners();
  console.log("Deploying contracts with the account:", deployer.address);
  const Token = await ethers.getContractFactory("Token");
  const token = await Token.deploy();
  console.log("Token deployed to:", token.address);
}

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

Debugging

Hardhat provides a powerful debugging tool that allows you to inspect the state of your contracts at any point in time. This example shows a custom task that prints the list of accounts.

const { task } = require("hardhat/config");

task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
  const accounts = await hre.ethers.getSigners();
  for (const account of accounts) {
    console.log(account.address);
  }
});

Other packages similar to hardhat

Keywords

FAQs

Package last updated on 02 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc