# SDK Client Configuration

To interact with a HashSphere network, you use a Hiero SDK client. 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

{% hint style="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.
  {% endhint %}

***

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

{% tabs %}
{% tab title="JavaScript" %}

```javascript
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);
```

{% endtab %}

{% tab title="Java" %}

```java
import com.hedera.hashgraph.sdk.Client;
import com.hedera.hashgraph.sdk.AccountId;
import java.util.Map;
import java.util.HashMap;

Map<String, AccountId> nodes = new HashMap<>();
nodes.put("xxx.xxx.xxx.xxx:50211", AccountId.fromString("0.0.3"));
nodes.put("yyy.yyy.yyy.yyy:50211", AccountId.fromString("0.0.4"));

Client client = Client.forNetwork(nodes);
```

{% endtab %}

{% tab title="Go" %}

```go
import (
    "github.com/hashgraph/hedera-sdk-go/v2"
)

nodes := map[string]hedera.AccountID{
    "xxx.xxx.xxx.xxx:50211": hedera.AccountID{Account: 3},
    "yyy.yyy.yyy.yyy:50211": hedera.AccountID{Account: 4},
}

client := hedera.ClientForNetwork(nodes)
```

{% endtab %}

{% tab title="Rust" %}

```rust
use hedera::{
    Client,
    AccountId,
};
use std::collections::HashMap;

let nodes: HashMap<String, AccountId> = [
    ("xxx.xxx.xxx.xxx:50211".to_owned(), AccountId::new(0, 0, 3)),
    ("yyy.yyy.yyy.yyy:50211".to_owned(), AccountId::new(0, 0, 4)),
].into();

let client = Client::for_network(nodes)?;
```

{% endtab %}
{% endtabs %}

***

### 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. Make sure your `.env` file is included in your `.gitignore`.

#### Using a `.env` file

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

```
OPERATOR_ID=0.0.xxxx
OPERATOR_KEY=302e020100300506032b657004220420...
```

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

{% tabs %}
{% tab title="JavaScript" %}

```javascript
import "dotenv/config";

const operatorId = AccountId.fromString(process.env.OPERATOR_ID);
const operatorKey = PrivateKey.fromString(process.env.OPERATOR_KEY);

client.setOperator(operatorId, operatorKey);
```

{% endtab %}

{% tab title="Java" %}

```java
import io.github.cdimascio.dotenv.Dotenv;

AccountId operatorId = AccountId.fromString(Dotenv.load().get("OPERATOR_ID"));
PrivateKey operatorKey = PrivateKey.fromString(Dotenv.load().get("OPERATOR_KEY"));

client.setOperator(operatorId, operatorKey);
```

{% endtab %}

{% tab title="Go" %}

```go
import (
    "os"
    "github.com/joho/godotenv"
)

err := godotenv.Load()
// ... error handling

operatorID, err := hedera.AccountIDFromString(os.Getenv("OPERATOR_ID"))
// ... error handling
operatorKey, err := hedera.PrivateKeyFromString(os.Getenv("OPERATOR_KEY"))
// ... error handling

client.SetOperator(operatorID, operatorKey)
```

{% endtab %}

{% tab title="Rust" %}

```rust
use std::env;

let operator_id: AccountId = env::var("OPERATOR_ID")?.parse()?;
let operator_key: PrivateKey = env::var("OPERATOR_KEY")?.parse()?;

client.set_operator(operator_id, operator_key);
```

{% endtab %}
{% endtabs %}

***

### 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 client](https://docs.hedera.com/hedera/sdks-and-apis/sdks/client).
