A great way to learn to test and build on the Hedera network is setting up your own Hedera local nodes. The local network consists of one local mirror node and one local consensus node and can be started using Docker or using the CLI tool. You can find the official GitHub repository for Hedera Local Node here.
This article is focused on how to set up your own local network using Docker and how to test that it is operating correctly.
What Can I Accomplish With My Own Local Network?
Create and submit transactions to your consensus node
Query transactions on your consensus node
Interact with your local mirror node through Rest API's
Test and debug your application while using tools like hardhat
Why Should I Set Up My Own Local Network?
Application testing and debugging should be done on your own local network. A benefit of having your own local network is ensuring your work isn't being interrupted by others throttling the network while conducting their own testing/debugging. It is also a great way to start to learn how to build on the Hedera network.
You may be wondering, when should I use the public networks like testnet and previewnet? You should use testnet when your application is almost ready for production and are thinking of transitioning to mainnet soon. Testnet nodes run the same codebase as the Hedera mainnet nodes.
Start the network using docker compose which will configure and start up multiple docker containers.
docker-compose up -d
Great! Once you've got the containers running you will see the following output.
[+] Running 11/11
[+] Running 13/14storage Created 0.0s
[+] Running 12/14storage Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 12/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 12/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 13/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 13/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 13/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 12/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 12/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 12/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 12/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 12/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 12/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 12/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 13/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 12/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 12/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 12/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 12/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 12/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 12/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 14/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 14/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 14/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 14/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 14/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
[+] Running 15/15-node Created 0.0s
⠿ Network cloud-storage Created 0.0s
⠿ Network mirror-node Created 0.0s
⠿ Network network-node-bridge Created 0.0s
⠿ Volume "mirror-node-postgres" Created 0.0s
⠿ Volume "minio-data" Created 0.0s
⠿ Container mirror-node-db Started 1.0s
⠿ Container minio Started 1.0s
⠿ Container haveged Started 0.7s
⠿ Container account-balances-uploader Started 1.6s
⠿ Container record-streams-uploader Started 1.4s
⠿ Container mirror-node-importer Started 1.6s
⠿ Container network-node Started 2.1s
⠿ Container mirror-node-web3 Started 2.2s
⠿ Container mirror-node-rest Started 2.2s
⠿ Container mirror-node-grpc Started 2.5s
You can list which containers are currently running by typing the following command.
docker container ls
// Output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
876da819ad8a gcr.io/mirrornode/hedera-mirror-grpc:0.57.2 "java org.springfram…" About a minute ago Up About a minute (healthy) 0.0.0.0:5600->5600/tcp mirror-node-grpc
50cdd0b4f830 gcr.io/hedera-registry/main-network-node:0.26.2 "/opt/hgcapp/service…" About a minute ago Up About a minute 50111/tcp, 0.0.0.0:50211-50212->50211-50212/tcp network-node
0be902a7ba69 gcr.io/mirrornode/hedera-mirror-rest:0.57.2 "node server.js" About a minute ago Up About a minute (healthy) 0.0.0.0:5551->5551/tcp mirror-node-rest
2e2f501712d1 gcr.io/mirrornode/hedera-mirror-web3:0.57.2 "java org.springfram…" About a minute ago Up About a minute (healthy) 0.0.0.0:8545->8545/tcp mirror-node-web3
03e5236690cc gcr.io/mirrornode/hedera-mirror-importer:0.57.2 "java org.springfram…" About a minute ago Up About a minute (healthy) mirror-node-importer
8f481bfce674 gcr.io/hedera-registry/uploader-mirror:0.5.0 "/usr/bin/env python…" About a minute ago Up About a minute record-streams-uploader
d45bae1bb9da gcr.io/hedera-registry/uploader-mirror:0.5.0 "/usr/bin/env python…" About a minute ago Up About a minute account-balances-uploader
5efcbd44018e postgres:13.5-alpine "docker-entrypoint.s…" About a minute ago Up About a minute 5432/tcp mirror-node-db
0ccd6696972c minio/minio "sh -c 'mkdir -p /da…" About a minute ago Up About a minute 0.0.0.0:9000-9001->9000-9001/tcp minio
c04dae19a4e5 gcr.io/hedera-registry/network-node-haveged:0.26.2 "/usr/bin/env havege…" About a minute ago Up About a minute haveged
Setting Up Your Client
In order to start interacting with your local network you will need to set up your client by configuring it to point to your local network. You can do this by using any project of your choice and ensuring you have your language specific Hedera SDK as a dependency and imported into your project. If you need a quick refresher you can reference the environment set-up instructions.
The first step is to configure your client to point to your local network. Client.forNetwork() allows you to set a custom consensus network by providing the IP address and port. Client.setMirrorNetwork() allows you to set a custom mirror node.
//Create your local client
const node = {"127.0.0.1:50211": new AccountId(3)};
const client = Client.forNetwork(node).setMirrorNetwork("127.0.0.1:5600");
Next you will need to set an account to pay for the fees associated with each transaction and query that is submitted to your local network. You’ll need an account ID and key which you will get from the local node on startup.
It is important to stop and remove containers, volumes and clean up any generated files. If you would like to keep any files generated inside your working directory please save them before executing the below command.
docker-compose down -v; git clean -xfd; git reset --hard
This concludes learning how to set up your local network, start it using docker, and interact with it.
For any feedback on this article or future articles you would like to see, let us know via the Hedera Discord Server.