Skip to content

An example Hedera Hardhat project where you can use an instance of the Hedera JSON RPC Relay to test and deploy a smart contract.

Notifications You must be signed in to change notification settings

hashgraph/hedera-hardhat-example-project

Repository files navigation

Hedera Hardhat Example Project

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.

Project Files and Folders

  • 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.

Setup

  1. Clone this repo to your local machine:
git clone https://github.com/hashgraph/hedera-hardhat-example-project.git
  1. Once you've cloned the repository, open your IDE terminal and navigate to the root directory of the project:
cd hedera-hardhat-example-project
  1. Run the following command to install all the necessary dependencies:
npm install
  1. Get your Hedera testnet account hex encoded private key from the Hedera Developer Portal and update the .env.example TESTNET_OPERATOR_PRIVATE_KEY

  2. Rename .env.example to .env

  3. 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)
  1. 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

Contributing

Contributions are welcome. Please see the contributing guide to see how you can get involved.

Code of Conduct

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 oss@hedera.com.

License

Apache License 2.0

About

An example Hedera Hardhat project where you can use an instance of the Hedera JSON RPC Relay to test and deploy a smart contract.

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •