Hardhat
What is Hardhat?
Hardhat is a development environment for Ethereum that helps developers manage and automate the common tasks involved in building smart contracts and decentralized applications. It can directly interact with Caldera's Ethereum API, allowing for the deployment of smart contracts into the Caldera network.Additionally, Hardhat is a comprehensive set of tools for creating Ethereum-based software, which includes various components that aid in editing, compiling, debugging, and deploying smart contracts and decentralized applications. All of these components work together to create a complete development environment.
Creating a Hardhat Project
Create a directory for your project:
Copy
mkdir hardhat && cd hardhatInitialize the project, which will create a
package.jsonfile
Copy
npm init -yInstall Hardhat
Copy
npm install hardhatCreate a project
Copy
npx hardhatCreate an empty
hardhat.config.jsand install the Ethers plugin to use the Ethers.js library to interact with the network.
Copy
Creating Your Smart Contract
Create a
contractsdirectory
Copy
Create
your_contract.solfile incontractsdirectory
Copy
Creating Your Configuration File
Modify the Hardhat configuration file and create a secure file to store your private key in.
Create a
secrets.jsonfile to store your private key
Copy
Add your private key to
secrets.json
Copy
Add the file to your project's
.gitignore, and never reveal your private key.Modify the
hardhat.config.jsfile
Import the Ethers.js plugin
Import the
secrets.jsonfileInside the
module.exportsadd the Caldera network configuration
Copy
Deploying Your Smart Contract
Compile the contract
Copy
Create a new directory for the script and name it scripts and add a new file to it called
deploy.js
Copy
Create a deployment script, like the one below
Copy
Deploy
your_contract.solusing the command below
Copy
Last updated