Skip to content

Commit 6994223

Browse files
feat(example): Custom web proxies usage and documentation (#2729)
* feat: Added example for custom web proxies usage and documentation Signed-off-by: ivaylogarnev-limechain <[email protected]> * fix: Comments and CommonJS test Signed-off-by: ivaylogarnev-limechain <[email protected]> * fix: Typo in README Signed-off-by: ivaylogarnev-limechain <[email protected]> * refactor: Introduced .env for credentials Signed-off-by: ivaylogarnev-limechain <[email protected]> * refactor: Removed unecessary comment within README Signed-off-by: ivaylogarnev-limechain <[email protected]> --------- Signed-off-by: ivaylogarnev-limechain <[email protected]>
1 parent ea62edf commit 6994223

File tree

10 files changed

+20578
-0
lines changed

10 files changed

+20578
-0
lines changed

common_js_test/src/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ describe("CommonJS", function () {
1818
console.log(`Failed for ${nodeAccountId}`);
1919
}
2020
}
21+
22+
// Close the client connection
2123
client.close();
24+
25+
// Ensure that at least one attempt was successful
2226
if (!succeededAtLeastOnce) {
2327
throw new Error("No successful query attempts were made.");
2428
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Hedera Operator Account ID
2+
REACT_APP_OPERATOR_ID="YOUR_OPERATOR_ID"
3+
4+
# Hedera Operator Private Key
5+
REACT_APP_OPERATOR_KEY="YOUR_PRIVATE_KEY"
6+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
6+
# production
7+
/build
8+
9+
.env
10+
11+
npm-debug.log*
12+
yarn-debug.log*
13+
yarn-error.log*
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Custom Network Configuration with gRPC Web Proxies
2+
3+
This guide demonstrates how to configure the Hedera SDK to communicate with a custom network using gRPC web proxies in a React application. The example sets up a transfer transaction, which is triggered when the page is loaded, using a custom network configuration with multiple gRPC web proxies.
4+
5+
## Steps to configure the custom network
6+
7+
### Prerequisites
8+
9+
- Install the required Node modules by running `npm install`
10+
- Create a `.env` file in the root directory and add your credentials.
11+
12+
### 1. Setup the operator account
13+
14+
First, you need to set up your operator account and private key. These credentials are required to sign and authorize the transaction.
15+
16+
```javascript
17+
const operatorId = AccountId.fromString("<YOUR_ACCOUNT_ID>");
18+
const operatorKey = PrivateKey.fromStringECDSA("<YOUR_PRIVATE_KEY>");
19+
```
20+
21+
### 2. Create a custom network with gRPC web proxies
22+
23+
Define a list of gRPC web proxies to communicate with your custom network. Each entry consists of a proxy URL and its associated account ID.
24+
25+
```javascript
26+
const nodes = {
27+
"https://testnet-node02-00-grpc.hedera.com:443": new AccountId(5),
28+
"https://testnet-node03-00-grpc.hedera.com:443": new AccountId(6),
29+
"https://testnet-node04-00-grpc.hedera.com:443": new AccountId(7),
30+
};
31+
```
32+
33+
These proxy URLs correspond to the gRPC web proxies you wish to use for the custom network.
34+
35+
### 3. Setup the `Client` using `Client.forNetwork()`
36+
37+
To configure the client with the custom network, use `Client.forNetwork()` and pass the list of nodes you defined. The SDK automatically detects the environment (whether it's a browser or Node.js environment).
38+
39+
```javascript
40+
const client = Client.forNetwork(nodes);
41+
client.setOperator(operatorId, operatorKey);
42+
```
43+
44+
In the browser environment, this will use gRPC web proxies.
45+
46+
### 4. Configure the transaction for the Custom Network
47+
48+
Before sending a transaction, you need to configure it with the necessary parameters, such as the sender, receiver, and amount. Here's how to create a transfer transaction using the configured client for the custom network.
49+
50+
```javascript
51+
const transferTransaction = new TransferTransaction()
52+
.addSender(senderAccountId, amountToSend)
53+
.addReceiver(receiverAccountId, amountToReceive)
54+
.setTransactionMemo("Transfer via custom gRPC web proxy network")
55+
.setTransactionFee(transactionFee);
56+
57+
const response = await transferTransaction.execute(client);
58+
```
59+
60+
### 5. Running the application
61+
62+
Once you've set up the client and transaction as described above, you can run your React application with `npm start`. The transfer transaction will be executed using the **custom gRPC web proxies** configured in the Client.forNetwork() method.

0 commit comments

Comments
 (0)