SDK Client Configuration

To interact with a HashSphere network, you use a client from a Hiero SDK. The Hiero SDKs provide a common foundation for interacting with any Hedera-powered network, including the public Hedera Mainnet, its testnets, and private networks like HashSphere. While the public networks have helper functions for easy connection (Client.forMainnet(), Client.forTestnet()), configuring a client for a private network requires explicitly providing the network's node addresses.

Prerequisites

circle-info

Before you begin, ensure you have the following:

  • The appropriate Hiero SDK installed for your preferred language (Java, JavaScript, Go, or Rust).

  • Your network address book and account credentials, provided by the HashSphere team during onboarding.


1. Configure Your Network Connection

For local networks and private HashSpheres, you configure the SDK client by passing it the node address book. The address book is a map containing the IP addresses or domain names of the network nodes and their corresponding node account IDs.

The HashSphere team provides you with the node address book and required identifiers during the onboarding process.

import { Client, AccountId } from "@hashgraph/sdk";

const nodes = {
  "xxx.xxx.xxx.xxx:50211": new AccountId(3),
  "yyy.yyy.yyy.yyy:50211": new AccountId(4),
};

const client = Client.forNetwork(nodes);

2. Define the Operator

The operator is the account that pays for transactions and queries submitted through the client. You must configure the client with an operator account ID and its corresponding private key.

For improved security and convenience, we recommend using a .env file to store your credentials rather than hardcoding them in your application. Remember to ensure your .env file is included in your .gitignore file.

Using a .env file

Create a .env file in the root of your project:

Then, load these variables into your application and set the operator on the client.


Client Configuration API Reference

The following table lists the primary methods for configuring the SDK client for a HashSphere network.

Method
Description

Client.forNetwork(<network>)

Constructs a client for a custom network using a provided address book.

client.setOperator(<accountId>, <privateKey>)

Sets the account that will pay for transactions and queries.

client.setMirrorNetwork(<network>)

Defines a specific mirror node network for the client to use.

client.getMirrorNetwork()

Returns the configured mirror node network.

client.setDefaultMaxTransactionFee(<fee>)

Sets the default maximum fee the client is willing to pay for a transaction.

client.setDefaultMaxQueryPayment(<payment>)

Sets the default maximum payment the client is willing to pay for a query.

For a complete list of client configuration options, see Building your Hedera clientarrow-up-right.

Last updated