Hedera
Search…
Set-up Your Local Network
While you are developing your application, you can use the Hedera supported networks (previewnet and testnet) to test your application against. In addition to using those networks, you have the option to set-up your own local consensus node and mirror node for testing purposes. With your local network set-up you can:
  • Create and submit transactions and queries to a consensus node
  • Interact with the mirror node via REST APIs

1. Set-up your local network

Set-up your local network by following the instructions found in the readme of the hedera-local-node project. This will create a Hedera network composed of one consensus node and one mirror node. The consensus node will process incoming transactions and queries. The mirror node stores the history of transactions. Both nodes are created at startup.

2. Configure your network

Once you have your local network up and running, you will need to configure your Hedera client to point to your local network in your project of choice. Your project should have your language specific Hedera SDK as a dependency and imported into your project. You may reference the environment set-up instructions if you don't know how.
Your local network IP address and port will be 127.0.0.1:50211 and your local mirror node IP and port will be 127.0.0.1:5600. The consensus node account ID is 0.0.3. This is the node account ID that will receive your transaction and query requests. It is recommended to store these variables in an environment or config file. These values will be hard-coded in the example for demonstration purposes.
Configure your local network by using Client.forNetwork(). This 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 network by providing the IP address and port.
Java
JavaScript
Go
1
//Create your local client
2
Client client = Client.forNetwork(Collections.singletonMap("127.0.0.1:50211", AccountId.fromString("0.0.3"))).setMirrorNetwork(List.of("127.0.0.1:5600"));
Copied!
1
//Create your local client
2
const node = {"127.0.0.1:50211": new AccountId(3)};
3
const client = Client.forNetwork(node).setMirrorNetwork("127.0.0.1:5600");
Copied!
1
//Create your local client
2
node := make(map[string]hedera.AccountID, 1)
3
node["127.0.0.1:50211"] = hedera.AccountID{Account: 3}
4
​
5
mirrorNode := []string{"127.0.0.1:5600"}
6
​
7
client := hedera.ClientForNetwork(node)
8
client.SetMirrorNetwork(mirrorNode)
Copied!

3. Set your local node transaction fee paying account

You will need and account ID and key to pay for the fees associated with each transaction and query that is submitted to your local network. You will use the account ID and key provided by the local node on startup to set-up your operator account ID and key. The operator is the default account that pays for transaction and query fees.
Account ID
0.0.2
Private Key
302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137
Note: It is not good practice to post your private keys in any public place. These keys are provided only for development and testing purposes only. They do not exist on any production networks.
Java
JavaScript
Go
1
client.setOperator(AccountId.fromString("0.0.2"), PrivateKey.fromString("302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"));
Copied!
1
client.setOperator(AccountId.fromString("0.0.2"),PrivateKey.fromString("302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"));
Copied!
1
accountId, err := hedera.AccountIDFromString("0.0.2")
2
privateKey, err := hedera.PrivateKeyFromString("302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137")
3
client.SetOperator(accountId, privateKey)
Copied!

4. Submit your transaction

Submit a transaction that will create a new account in your local network. The console should print out the new account ID. In this example, we are using the same key as the transaction fee paying account as the key for the new account. You can also create a new key if you wish.
Java
JavaScript
Go
1
//Submit a transaction to your local node
2
TransactionResponse newAccount = new AccountCreateTransaction()
3
.setKey(PrivateKey.fromString("302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"))
4
.setInitialBalance(new Hbar(1))
5
.execute(client);
6
7
//Get the receipt
8
TransactionReceipt receipt = newAccount.getReceipt(client);
9
10
//Get the account ID
11
AccountId newAccountId = receipt.accountId;
12
System.out.println(newAccountId);
Copied!
1
//Submit a transaction to your local node
2
const newAccount = await new AccountCreateTransaction()
3
.setKey(PrivateKey.fromString("302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"))
4
.setInitialBalance(new Hbar(1))
5
.execute(client);
6
​
7
//Get receipt
8
const receipt = await newAccount.getReceipt(client);
9
​
10
//Get the account ID
11
const newAccountId = receipt.accountId;
12
console.log(newAccountId);
Copied!
1
//Submit a transaction to your local node
2
newAccount, err := hedera.NewAccountCreateTransaction().
3
SetKey(privateKey).
4
SetInitialBalance(hedera.HbarFromTinybar(1000)).
5
Execute(client)
6
​
7
if err != nil {
8
println(err.Error(), ": error getting balance")
9
return
10
}
11
​
12
//Get receipt
13
receipt, err := newAccount.GetReceipt(client)
14
​
15
//Get the account ID
16
newAccountId := receipt.AccountID
17
fmt.Print(newAccountId)
Copied!

5. View your transaction

You can view the executed transaction by querying your local mirror node.
The local mirror node endpoint URL is http://localhost:5551/.
You can view the transactions that were submitted to your local node by submitting this request:
1
http://localhost:5551/api/v1/transactions
Copied!
The list of supported mirror node REST APIs can be found here. You have now set-up your local environment. Check out the following links for more examples.

Code Check
βœ…
​

Java
JavaScript
Go
1
import com.hedera.hashgraph.sdk.*;
2
import java.io.IOException;
3
import java.util.Collections;
4
import java.util.List;
5
import java.util.concurrent.TimeoutException;
6
​
7
public class LocalNode {
8
public static void main(String[] args) throws TimeoutException, PrecheckStatusException, ReceiptStatusException, InterruptedException, IOException {
9
​
10
//Create your local client
11
Client client = Client.forNetwork(Collections.singletonMap("127.0.0.1:50211", AccountId.fromString("0.0.3"))).setMirrorNetwork(List.of("127.0.0.1:5600"));
12
​
13
//Set the transaction fee paying account
14
client.setOperator(AccountId.fromString("0.0.2"), PrivateKey.fromString("302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"));
15
16
//Submit a transaction to your local node
17
TransactionResponse newAccount = new AccountCreateTransaction()
18
.setKey(PrivateKey.fromString("302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"))
19
.setInitialBalance(new Hbar(1))
20
.execute(client);
21
22
//Get the receipt
23
TransactionReceipt receipt = newAccount.getReceipt(client);
24
25
//Get the account ID
26
AccountId newAccountId = receipt.accountId;
27
System.out.println(newAccountId);
28
}
29
}
Copied!
1
const {
2
Client,
3
PrivateKey,
4
Hbar,
5
AccountId,
6
AccountCreateTransaction,
7
} = require("@hashgraph/sdk");
8
​
9
async function main() {
10
​
11
//Create your local client
12
const node = {"127.0.0.1:50211": new AccountId(3)}
13
const client = Client.forNetwork(node).setMirrorNetwork("127.0.0.1:5600");
14
​
15
//Set the transaction fee paying account
16
client.setOperator(AccountId.fromString("0.0.2"),PrivateKey.fromString("302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"));
17
​
18
//Submit a transaction to your local node
19
const newAccount = await new AccountCreateTransaction()
20
.setKey(PrivateKey.fromString("302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"))
21
.setInitialBalance(new Hbar(1))
22
.execute(client);
23
​
24
//Get receipt
25
const receipt = await newAccount.getReceipt(client);
26
​
27
//Get the account ID
28
const newAccountId = receipt.accountId;
29
console.log(newAccountId);
30
}
31
void main();
Copied!
1
package main
2
​
3
import (
4
"fmt"
5
​
6
"github.com/hashgraph/hedera-sdk-go/v2"
7
)
8
​
9
func main() {
10
//Create your local node client
11
node := make(map[string]hedera.AccountID, 1)
12
node["127.0.0.1:50211"] = hedera.AccountID{Account: 3}
13
​
14
mirrorNode := []string{"127.0.0.1:5600"}
15
​
16
client := hedera.ClientForNetwork(node)
17
client.SetMirrorNetwork(mirrorNode)
18
​
19
//Set the transaction fee paying account
20
accountId, err := hedera.AccountIDFromString("0.0.2")
21
privateKey, err := hedera.PrivateKeyFromString("302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137")
22
client.SetOperator(accountId, privateKey)
23
​
24
//Submit a transaction to your local node
25
newAccount, err := hedera.NewAccountCreateTransaction().
26
SetKey(privateKey).
27
SetInitialBalance(hedera.HbarFromTinybar(1000)).
28
Execute(client)
29
​
30
if err != nil {
31
println(err.Error(), ": error getting balance")
32
return
33
}
34
​
35
//Get receipt
36
receipt, err := newAccount.GetReceipt(client)
37
​
38
//Get the account ID
39
newAccountId := receipt.AccountID
40
fmt.Print(newAccountId)
41
}
Copied!