How to Set Up a Hedera Local Node
The Hedera Local Node project enables developers to establish their own local network for development and testing. The local network comprises the consensus node, mirror node, JSON-RPC relay, and other Hedera products, and can be set up using the CLI tool and Docker. This setup allows you to seamlessly build and deploy smart contracts from your local environment.
By the end of this tutorial, you'll be equipped to run a Hedera local node and generate keys, allowing you to test your projects and deploy projects in your local environment.
Prerequisites
Node.js >= v14.x
NPM >= v6.14.17**
Minimum 16GB RAM
Docker >= v20.10.x
Docker Compose >= v2.12.2
Have Docker running on your machine with the correct configurations.
**Local node can be run using Docker or NPM but we will use Docker for this tutorial. Here are the installation steps for NPM.
Table of Contents
Step 1: Local Node Setup
Open a new terminal and navigate to your preferred directory where your Hedera Local Node project will live. Run the following command to clone the repo and install dependencies to your local machine:
git clone https://github.com/hashgraph/hedera-local-node.git
cd hedera-local-node
npm install && npm install -g
For Windows users: You will need to update the file endings of compose-network/mirror-node/init.sh
by running this in WSL:
dos2unix compose-network/mirror-node/init.sh
Step 2: Start Local Node
Let's start by initializing and starting your local environment. Make sure Docker is installed and open on your machine before running this command:
hedera start -d
The hedera start -d
command will start your local node and generate 10 accounts with predefined private keys for each key type. There are three key types: ECDSA, ECDSA alias, and ED25519. All of them are usable via HederaSDK. Only Alias ECDSA accounts can be imported into a wallet like Metamask or used in ethers.
Step 3: Generate Keys
To generate accounts with random private keys, run the generate-accounts
command. Specify the number of accounts generated by appending the number to the hedera start
or hedera generate-account
command. For example, to generate 5 accounts at startup, run hedera start 5
.
Grab any of the account private keys generated from the Alias ECDSA keys Accounts list. This will be used as the LOCAL_NODE_OPERATOR_PRIVATE_KEY
environment variable value in your .env
file of your project.
Step 4: Stop Local Node
To stop your local node, you can run the hedera stop
command to stop and remove the Docker container volumes and clean the manually generated files. If you want to keep any files created manually in the working directory, please save them before executing this command.
Alternatively, run docker compose down -v; git clean -xfd; git reset --hard
to stop the local node and reset it to its original state.
Additional Resources
➡ Hedera Local Node Repository
➡ Hedera Local Node CLI Tool Commands
➡ Hedera Local Node Docker Setup [Video Tutorial]
Last updated
Was this helpful?