Overview
Hardhat is a development environment for Ethereum software. It consists of different components for editing, compiling, debugging and deploying your smart contracts and dApps, all of which work together to create a complete development environment.
Using Hardhat
Installing Hardhat
You can skip this section if you already have Hardhat installed or follow that Hardhat Installation guide on the Hardhat website for all details.
We provide you with a very basic process here for convenience:
- Install the Hardhat package.
npm install --save-dev hardhat
- Initialize a new Hardhat project using the following Hardhat command.
This creates a basic project for you to set up directories and configuration files.
npx hardhat
- After executing the Hardhat command, this menu appears:
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.10.1 👷
? What do you want to do? …
❯ Create a JavaScript project
Create a TypeScript project
Create an empty hardhat.config.js
- In this menu, select Create a JavaScript project and select Enter.
- Select the current directory as your project base.
- Type Y when asked to add a
.gitignore
file. - Type Y when asked to install this sample project’s dependencies with
npm
.
After you complete these steps, you'll have a new Hardhat project.
Hardhat integration
The Fireblocks Hardhat Plugin helps seamlessly integrate Fireblocks into your Hardhat development stack.
You can use it to deploy contracts, sign messages, and send transactions.
Installation
npm install @fireblocks/hardhat-fireblocks
Import the plugin into your hardhat.config.js
or hardhat.config.ts
file:
require("@fireblocks/hardhat-fireblocks");
const { ApiBaseUrl } = require("@fireblocks/fireblocks-web3-provider");
import "@fireblocks/hardhat-fireblocks";
import { ApiBaseUrl } from "@fireblocks/fireblocks-web3-provider";
Configuration
This plugin extends the HttpNetworkUserConfig
object with an optional fireblocks
field.
This is an example of how to set this up in your Hardhat configuration file:
module.exports = {
solidity: "0.8.17",
networks: {
sepolia: {
url: "https://sepolia.drpc.org",
fireblocks: {
apiBaseUrl: ApiBaseUrl.Sandbox, // If using a sandbox workspace
privateKey: process.env.FIREBLOCKS_API_PRIVATE_KEY_PATH,
apiKey: process.env.FIREBLOCKS_API_KEY,
vaultAccountIds: process.env.FIREBLOCKS_VAULT_ACCOUNT_IDS,
}
},
},
};
If you are not using a Sandbox environment, but rather a regular one, just comment the apiBaseUrl line.
Delete the Lock.sol
file that came with your Hardhat boilerplate template:
rm contracts/Lock.sol
Deploy Contract
Now that you have a Hardhat project set up, create your smart contract contracts/hello.sol
in the project folder and then deploy it to the Sepolia Ethereum Testnet.
Step 1: Create and compile the Solidity file
pragma solidity ^0.8.17;
contract HelloWorld {
string public greet = "Hello World!";
}
Run the following command to compile it:
npx hardhat compile
Step 2: Update the deployment script
Replace the contents of the deploy.js
script with the following basic contract deployment flow:
const hre = require("hardhat");
async function main() {
const factory = await hre.ethers.getContractFactory("HelloWorld");
const contract = await factory.deploy();
await contract.deployed();
console.log("contract deployed to:", contract.address);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Step 3: Deploy smart contract
Deploy your contract to the Ethereum Sepolia Testnet:
npx hardhat run --network sepolia scripts/deploy.js
Or:
HARDHAT_NETWORK=sepolia node scripts/deploy.js
This should take a couple of minutes to run if everything was configured correctly.
Once the deploy script has finished running, you will see this message if the contract was deployed successfully:
contract deployed to: <contract_address>