This Hedera Hardhat Example Project offers boilerplate code for testing and deploying smart contracts via Hardhat. It includes configuration for both community-hosted and local (Hedera Local Node) instances of the Hedera JSON RPC Relay.
🔥 Check out the step-by-step tutorial here.
-
hardhat.config.js
- This is the configuration file for your Hardhat project development environment. It centralizes and defines various settings like Hedera networks, Solidity compiler versions, plugins, and tasks. -
/contracts
- This folder holds all the Solidity smart contract files that make up the core logic of your dApp. Contracts are written in.sol
files. -
/test
- This folder contains test scripts that help validate your smart contracts' functionality. These tests are crucial for ensuring that your contracts behave as expected. -
/scripts
- This folder contains essential JavaScript files for tasks such as deploying smart contracts to the Hedera network. -
.env.example
- This file is contains the environment variables needed by the project. Copy this file to a.env
file and fill in the actual values before starting the development server or deploying smart contracts. To expedite your test setup and deployment, some variables are pre-filled in this example file.
- Clone this repo to your local machine:
git clone https://github.com/hashgraph/hedera-hardhat-example-project.git
- Once you've cloned the repository, open your IDE terminal and navigate to the root directory of the project:
cd hedera-hardhat-example-project
- Run the following command to install all the necessary dependencies:
npm install
-
Get your Hedera testnet account hex encoded private key from the Hedera Developer Portal and update the
.env.example
TESTNET_OPERATOR_PRIVATE_KEY
-
Rename
.env.example
to.env
-
Run the test script from the root directory of the project. The default network is set to "local."
# runs test on default network
npx hardhat test
# runs test on testnet
npx hardhat test --network testnet
Expect an output similar to the following:
RPC
The address 0xe0b73F64b0de6032b193648c08899f20b5A6141D has 10000000000000000000000 weibars
✔ should be able to get the account balance (1678ms)
Greeter deployed to: 0xD9d0c5C0Ff85758BdF05A7636F8036d4D065F5B6
✔ should be able to deploy a contract (11456ms)
Contract call result: initial_msg
✔ should be able to make a contract view call (1249ms)
Updated call result: updated_msg
Contract call result: updated_msg
✔ should be able to make a contract call (6806ms)
4 passing (22s)
- Run the following command to deploy the smart contract.
# deploys to the default network
npx hardhat deploy-contract
# deploys to testnet
npx hardhat deploy-contract --network testnet
Contributions are welcome. Please see the contributing guide to see how you can get involved.
This project is governed by the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code of conduct. Please report unacceptable behavior to [email protected].