From 2ba24db5baf869af61758c5cd610d42c7ebae569 Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Tue, 3 Dec 2024 00:03:03 +0200 Subject: [PATCH 01/16] docs: add configuration.md file Signed-off-by: Ivaylo Nikolov --- CONFIGURATION.md | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 CONFIGURATION.md diff --git a/CONFIGURATION.md b/CONFIGURATION.md new file mode 100644 index 000000000..1df3e174c --- /dev/null +++ b/CONFIGURATION.md @@ -0,0 +1,88 @@ +# Configuration + +The packages of the JS SDK support loading of configuration from an .env file or via the environment. + +## Environment Variables + +### Required + +|------|-------|---------| +| OPERATOR_ID | Account ID of the operator account used to pay for transactions and queries | 0.0.12345 | +| OPERATOR_KEY | Private key of the operator account | 302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10 | +| HEDERA_NETWORK | Network to connect to: mainnet, testnet, previewnet, or localhost | testnet | + +## ED25519 or ECDSA key + +### Integration tests + +When you run integration tests you should use an Ed25519 private key. This is set up [here](test/integration/BaseIntegrationTestEnv.js:95). If you have an ECDSA key you should change the line to: + +```javascript +const operatorKey = PrivateKey.fromStringECDSA(options.env.OPERATOR_KEY); +``` + +### Examples + +The examples use both ED25519 and ECDSA keys. These examples come with a pre-filled .env file, so you generally don’t need to make changes. However, if you modify the .env file, ensure the correct type of private key is used. + +To verify which type of key is required, check the example code for the initialization method in the client/wallet. Look for either `fromStringED25519` or `fromStringECDSA`. + +_Note that some examples are designed to work only with ECDSA private keys._ + +#### `fromStringDer` + +This example uses `fromString`, which internally calls `fromStringED25519`. + +#### Optional Parameters + +Certain examples simulate different actors in the network, such as Alice, Bob, or Treasury. These examples require additional environment variables, which are pre-configured in the .env file. Examples of such variables include: + +- `ALICE_KEY` +- `BOB_KEY` +- `TREASURY_KEY` +- `ALICE_ID` +- `BOB_ID` +- `TREASURY_ID` + +### React Native Example + +This example uses `fromString`, which internally calls `fromStringED25519`. + +### Simple REST Signature Provider + +This behaves the same as the React Native example. + +## Which network to use? + +- The maintainers of this repository use `hedera-local-node` when running integration tests. Running integration tests on testnet costs far too much HBARs. +- When running examples you can use any network you want. The examples are used for us to demonstrate to the community how a features is supposed to work so they optimized to work on any network you want. +- Unit tests do not require environment variables. + +## How to get my account keys and IDs? + +### Local network + +If you have followed our best practices, such as using hedera-local-node for running integration tests, you can retrieve account keys and IDs when starting the local node. Upon startup, the local node generates accounts and displays their details. + +You can copy one of these accounts and use its key and ID for the following: + +- `OPERATOR_KEY` and `OPERATOR_ID` +- `ALICE_ID` and `ALICE_KEY` +- `BOB_ID` and `BOB_KEY` +- `TREASURY_ID` and `TREASURY_KEY` + +### Testnet and previewnet + +To run the examples on the testnet, you can obtain your account keys and IDs from the Hedera Portal Dashboard. + +## Possible configuration issues + +- Most common problem is that users use ED25519 key when the code asks for ECDSA key or vice versa. Please double check if you sue the correct key. +- You might have ran the unit tests while running local-node. This will break multiple tests. +- Doesn't happen often but on rare ocassions some of the tests will break but rerunning them will give the expected result. +- If you hadn't used `local-node` for a long time sometimes it goes in sleep mode and you need to restart it to rerun the tests. This is not an issue with the SDK itself but still a very common problem. +- Please use the command `task install` and do not install the packages manually using `npm` or `yarn`. This might create some configuration issues. + +## Should I have multiple .env files like .env.local, .env.production, .envdevelopment etc? + +[Owner of dotenv says - no.](https://github.com/motdotla/dotenv#should-i-have-multiple-env-files) From dba60877be7b02f1cc452247a2eab666efb6209e Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Sun, 8 Dec 2024 18:20:17 +0200 Subject: [PATCH 02/16] docs: updat econfiguration Signed-off-by: Ivaylo Nikolov --- CONFIGURATION.md | 146 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 1df3e174c..ac809465b 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -86,3 +86,149 @@ To run the examples on the testnet, you can obtain your account keys and IDs fro ## Should I have multiple .env files like .env.local, .env.production, .envdevelopment etc? [Owner of dotenv says - no.](https://github.com/motdotla/dotenv#should-i-have-multiple-env-files) + +## Client Configuration + +### Network Configuration + +- `setNetwork` - The setNetwork method configures the network nodes that your client will communicate with on the Hedera network. It's a fundamental configuration step that determines which nodes will process your transactions and queries. + +Example: + +```javascript +const client = Client.forNetwork(); +client.setNetwork({ + "2.testnet.hedera.com:50211": new AccountId(0, 0, 5), +}); +``` + +- `setMirrorNetwork` - Configure the mirror nodes + +```javascript +const client = Client.forNetwork(); +client.setMirrorNode(["https://testnet.mirrornode.hedera.com"]); +``` + +- `setNetworkFromAddressBook` - Set network using address book response from the AddressBookQuery execution. + + ```javascript + const result = await new AddressBookQuery() + .setFileId(FileId.ADDRESS_BOOK) + .execute(client); + + client = client.setNetworkFromAddressBook(result); + ``` + +- `setLedgerId` - Set the network ledger ID (mainnet/testnet/previewnet) + +``` +let client = Client.forNetwork().setLedgerId(LedgerId.PREVIEWNET); +``` + +or + +``` +let client = Client.forNetwork().setLedgerId("previewnet"); +``` + +- `setTransportSecurity` - Configure transport security settings + +### Operator Settings + +- `setOperator` - Set the operator account and private key. This operator is the account that will pay for the transactions you execute. + +``` +const operatorId = AccountId.fromString("..."); +const operatorKey = PrivateKey.generateED25519(); +let client = Client.forNetwork().setOperator(operatorId, operatorKey); +``` + +- `setOperatorWith` - Set the operator id and key and also provide a custom transaction signer function instead of using the default one. + +``` +tx.setOperatorWith(accountId, key.publicKey, (message) => + Promise.resolve(key.sign(message)), + ); +``` + +### Transaction Settings + +- `setDefaultMaxTransactionFee` - Set maximum transaction fee user is willing to pay. +- `setDefaultRegenerateTransactionId` - Configure transaction ID regeneration. This function accepts a boolean type of value. When set to true it will regenerate the transaction ID when a `TRANSACTION_EXPIRED` status is returned. +- `setSignOnDemand` - Configure on-demand transaction signing + +The setSignOnDemand method in the Hedera JavaScript SDK allows you to configure how transactions are signed before being submitted to the Hedera network. By default, transactions are signed immediately after being constructed. However, in some cases, you may want to delay the signing process until just before the transaction is submitted. This can be useful in scenarios where you need to perform additional operations or validations on the transaction before signing it. + +When you call client.setSignOnDemand(true), it instructs the SDK to defer the signing of transactions until the transaction.sign() method is explicitly called. This means that when you create a transaction using the SDK, it will not be signed automatically. Instead, you will need to call transaction.sign() manually before submitting the transaction to the network. + +### Query Settings + +- `setDefaultMaxQueryPayment` - Set maximum query payment. + +### Retry and Timeout Settings + +- `setMaxAttempts` - Sets maximum retry attempts before an error is thrown. +- `setMaxNodeAttempts` - Set maximum node retry attempts +- `setMinBackoff` - Set minimum backoff time for retries. + There's a time the SDK waits for after every failed attempt. A lower minBackoff value will result in more frequent retries initially, which can be useful for faster recovery from transient failures. This time increases exponentially. The default values provided by the SDK are generally reasonable for most use cases, but you may want to adjust them based on your specific requirements. +- `setMaxBackoff` - Set maximum backoff time for retries + Same as above but this sets on the maximum amount of seconds the backoff time may go. +- `setRequestTimeout` - This method in the Hedera JavaScript SDK is used to set the maximum amount of time (in milliseconds) that the SDK will wait for a response from a node before considering the request as timed out + +``` +const client = Client.forNetwork(); +client.setRequestTimeout(10000); // Set the request timeout to 10 seconds (10000 milliseconds) +``` + +### Node Management + +- `setMaxNodesPerTransaction` - Set maximum nodes per transaction + This sets the maximum amount of nodes that the transaction will try to execute to.Setting a higher value for setMaxNodesPerTransaction can improve the reliability of transaction execution, but it also increases the network load and the overall cost of the transaction (since you'll be paying transaction fees for each node that executes the transaction). +- `setNodeMinBackoff` - Set minimum node backoff time + +The setNodeMinBackoff method in the Hedera JavaScript SDK is used to set the minimum backoff time (in milliseconds) for retrying operations on a specific node. +When you send a request to a node in the Hedera network, and the node fails to respond or encounters an error, the SDK will attempt to retry the request on the same node after a certain amount of time. This time is known as the backoff time, and it starts at a minimum value (set by setNodeMinBackoff) and increases exponentially with each subsequent retry attempt, up to a maximum value (set by setNodeMaxBackoff). +The backoff mechanism is designed to prevent overwhelming the nodes with too many retries in a short period of time, while still allowing the SDK to recover from transient failures or network issues. +Here's an example of how you can set the minimum node backoff time using the setNodeMinBackoff method: + +``` +const client = Client.forNetwork(); +client.setNodeMinBackoff(500); // Set minimum node backoff to 500 milliseconds (0.5 seconds) +``` + +- `setNodeMaxBackoff` - Set maximum node backoff time + +Same as above but it sets the maximum seconds allowed for a node backoff. + +- `setNodeMinReadmitPeriod` - Set minimum node readmit period + When a node fails to respond or encounters an error while processing a request, the SDK will temporarily remove that node from the pool of available nodes. This is done to prevent the SDK from repeatedly sending requests to a node that is experiencing issues, which could further exacerbate the problem. + The `setNodeMinReadmitPeriod` method allows you to configure the minimum amount of time that a node must wait before it can be readmitted to the pool of available nodes. During this period, the SDK will not send any requests to that node, giving it time to recover or resolve any issues it may be experiencing. + +- `setNodeMaxReadmitPeriod` - Set maximum node readmit period. + +The setNodeMaxReadmitPeriod method allows you to configure the maximum amount of time that a node can be excluded from the pool of available nodes. After this period has elapsed, the SDK will automatically readmit the node to the pool, regardless of whether it has recovered or not. + +- `setNodeWaitTime` - The setNodeWaitTime method in the Hedera JavaScript SDK is used to set the minimum amount of time (in milliseconds) that the SDK will wait before attempting to send a request to a node that has recently failed or encountered an error. + +``` +const client = Client.forNetwork(); +client.setNodeWaitTime(5000); // Set node wait time to 5 seconds (5000 milliseconds) +``` + +### Network Update Settings + +- `setNetworkUpdatePeriod` - The setNetworkUpdatePeriod method in the Hedera JavaScript SDK is used to configure the frequency at which the SDK updates its internal representation of the Hedera network topology. + The Hedera network is a distributed ledger system that consists of multiple nodes spread across different geographic locations. These nodes can join or leave the network at any time, and their availability and performance can vary depending on various factors such as network conditions, hardware issues, or software updates. + To ensure that the SDK has an up-to-date view of the network topology, it periodically retrieves information about the available nodes and their respective performance metrics. This information is used to determine which nodes to send requests to and to adjust the load balancing and failover strategies accordingly. +- `setAutoValidateChecksums` - Configure automatic checksum validation + +### Logging + +- `setLogger` - Configure client logger. Setting a logger can give you additional information for debugging processes. This is an example of how you can use this fucntionality. + +``` + const infoLogger = new Logger(LogLevel.Info); + client.setLogger(infoLogger); +``` + +There are different LogLevels. They may show only errors, warnings, or infos depending on the loglevel you have set. From a74f41b07ecd6a24e40d998dbb69faa9c2c60808 Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Sun, 8 Dec 2024 18:24:04 +0200 Subject: [PATCH 03/16] docs: update Signed-off-by: Ivaylo Nikolov --- CONFIGURATION.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index ac809465b..7b2184a38 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -173,7 +173,8 @@ When you call client.setSignOnDemand(true), it instructs the SDK to defer the si There's a time the SDK waits for after every failed attempt. A lower minBackoff value will result in more frequent retries initially, which can be useful for faster recovery from transient failures. This time increases exponentially. The default values provided by the SDK are generally reasonable for most use cases, but you may want to adjust them based on your specific requirements. - `setMaxBackoff` - Set maximum backoff time for retries Same as above but this sets on the maximum amount of seconds the backoff time may go. -- `setRequestTimeout` - This method in the Hedera JavaScript SDK is used to set the maximum amount of time (in milliseconds) that the SDK will wait for a response from a node before considering the request as timed out +- `setRequestTimeout` - This timeout is the maximum allowed time for the entire transaction/query, including all retries. +- `setMaxExecutionTime` - this timeout applies to each single gRPC request within the transaction/query. It’s used for the edge cases where 10 seconds are not enough for the execution of a single gRPC request and the user can pass more. ``` const client = Client.forNetwork(); From fc3339214b35743c40e06408b613514f4c083f96 Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Sun, 8 Dec 2024 21:14:04 +0200 Subject: [PATCH 04/16] docs: update table Signed-off-by: Ivaylo Nikolov --- CONFIGURATION.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 7b2184a38..bdbd8fd4b 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -6,10 +6,11 @@ The packages of the JS SDK support loading of configuration from an .env file or ### Required -|------|-------|---------| -| OPERATOR_ID | Account ID of the operator account used to pay for transactions and queries | 0.0.12345 | -| OPERATOR_KEY | Private key of the operator account | 302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10 | -| HEDERA_NETWORK | Network to connect to: mainnet, testnet, previewnet, or localhost | testnet | +| Name | Value | Example | +| -------------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | +| OPERATOR_ID | Account ID of the operator account used to pay for transactions and queries | 302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10 | +| OPERATOR_KEY | ED25519 private key of the operator account | 0.0.12345 | +| HEDERA_NETWORK | Network to connect to: mainnet, testnet, previewnet, or localhost | localhost | ## ED25519 or ECDSA key From 5dd0ca50b3183df3b270112b0eb324bc394c80c4 Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Sun, 8 Dec 2024 21:40:31 +0200 Subject: [PATCH 05/16] wip: update Signed-off-by: Ivaylo Nikolov --- CONFIGURATION.md | 90 +++++++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index bdbd8fd4b..6d920fa7b 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -1,7 +1,18 @@ -# Configuration +# Introduction The packages of the JS SDK support loading of configuration from an .env file or via the environment. +# Table of contents + +1. Introduction .................................................. +2. Configuration Options ......................................... + 2.1 Network Configuration ..................................... + 2.2 Operator Settings .......................................... 4 + 2.3 Transaction Settings ....................................... 5 +3. Error Handling ................................................ +4. Examples ...................................................... +5. Conclusion .................................................... + ## Environment Variables ### Required @@ -112,33 +123,39 @@ client.setMirrorNode(["https://testnet.mirrornode.hedera.com"]); - `setNetworkFromAddressBook` - Set network using address book response from the AddressBookQuery execution. - ```javascript - const result = await new AddressBookQuery() - .setFileId(FileId.ADDRESS_BOOK) - .execute(client); +```javascript +const result = await new AddressBookQuery() + .setFileId(FileId.ADDRESS_BOOK) + .execute(client); - client = client.setNetworkFromAddressBook(result); - ``` +client = client.setNetworkFromAddressBook(result); +``` - `setLedgerId` - Set the network ledger ID (mainnet/testnet/previewnet) -``` +```javascript let client = Client.forNetwork().setLedgerId(LedgerId.PREVIEWNET); ``` or -``` +```javascript let client = Client.forNetwork().setLedgerId("previewnet"); ``` -- `setTransportSecurity` - Configure transport security settings +- `setTransportSecurity` - The `setTransportSecurity` method in the Hedera JavaScript SDK is used to enable or disable transport security for the communication between the SDK and the Hedera network nodes. Transport security refers to the mechanisms used to secure the communication channel, typically involving encryption and authentication protocols. + When transport security is enabled, the SDK will establish a secure connection with the Hedera network nodes using protocols like Transport Layer Security (TLS) or its predecessor, Secure Sockets Layer (SSL). This ensures that the data transmitted between the SDK and the nodes is encrypted, protecting it from eavesdropping and tampering. It also provides authentication mechanisms to verify the identity of the nodes and prevent man-in-the-middle attacks. + +```javascript +const client = Client.forNetwork(); +client.setTransportSecurity(true); +``` ### Operator Settings -- `setOperator` - Set the operator account and private key. This operator is the account that will pay for the transactions you execute. +- `setOperator` - Set the operator account and private key. The operator is the account that will pay for the transactions the user executes. -``` +```javascript const operatorId = AccountId.fromString("..."); const operatorKey = PrivateKey.generateED25519(); let client = Client.forNetwork().setOperator(operatorId, operatorKey); @@ -146,16 +163,24 @@ let client = Client.forNetwork().setOperator(operatorId, operatorKey); - `setOperatorWith` - Set the operator id and key and also provide a custom transaction signer function instead of using the default one. -``` +```javascript tx.setOperatorWith(accountId, key.publicKey, (message) => - Promise.resolve(key.sign(message)), - ); + Promise.resolve(key.sign(message)), +); ``` ### Transaction Settings - `setDefaultMaxTransactionFee` - Set maximum transaction fee user is willing to pay. + +```javascript +const client = Client.forTestnet({ + scheduleNetworkUpdate: false, +}).setDefaultMaxTransactionFee(Hbar.fromTinybars(1)); +``` + - `setDefaultRegenerateTransactionId` - Configure transaction ID regeneration. This function accepts a boolean type of value. When set to true it will regenerate the transaction ID when a `TRANSACTION_EXPIRED` status is returned. + - `setSignOnDemand` - Configure on-demand transaction signing The setSignOnDemand method in the Hedera JavaScript SDK allows you to configure how transactions are signed before being submitted to the Hedera network. By default, transactions are signed immediately after being constructed. However, in some cases, you may want to delay the signing process until just before the transaction is submitted. This can be useful in scenarios where you need to perform additional operations or validations on the transaction before signing it. @@ -164,7 +189,7 @@ When you call client.setSignOnDemand(true), it instructs the SDK to defer the si ### Query Settings -- `setDefaultMaxQueryPayment` - Set maximum query payment. +- `setDefaultMaxQueryPayment` - Same as `setDefaultMaxTransactionFee` but for queries. ### Retry and Timeout Settings @@ -177,7 +202,7 @@ When you call client.setSignOnDemand(true), it instructs the SDK to defer the si - `setRequestTimeout` - This timeout is the maximum allowed time for the entire transaction/query, including all retries. - `setMaxExecutionTime` - this timeout applies to each single gRPC request within the transaction/query. It’s used for the edge cases where 10 seconds are not enough for the execution of a single gRPC request and the user can pass more. -``` +```javascript const client = Client.forNetwork(); client.setRequestTimeout(10000); // Set the request timeout to 10 seconds (10000 milliseconds) ``` @@ -186,33 +211,28 @@ client.setRequestTimeout(10000); // Set the request timeout to 10 seconds (10000 - `setMaxNodesPerTransaction` - Set maximum nodes per transaction This sets the maximum amount of nodes that the transaction will try to execute to.Setting a higher value for setMaxNodesPerTransaction can improve the reliability of transaction execution, but it also increases the network load and the overall cost of the transaction (since you'll be paying transaction fees for each node that executes the transaction). -- `setNodeMinBackoff` - Set minimum node backoff time - -The setNodeMinBackoff method in the Hedera JavaScript SDK is used to set the minimum backoff time (in milliseconds) for retrying operations on a specific node. -When you send a request to a node in the Hedera network, and the node fails to respond or encounters an error, the SDK will attempt to retry the request on the same node after a certain amount of time. This time is known as the backoff time, and it starts at a minimum value (set by setNodeMinBackoff) and increases exponentially with each subsequent retry attempt, up to a maximum value (set by setNodeMaxBackoff). -The backoff mechanism is designed to prevent overwhelming the nodes with too many retries in a short period of time, while still allowing the SDK to recover from transient failures or network issues. -Here's an example of how you can set the minimum node backoff time using the setNodeMinBackoff method: +- `setNodeMinBackoff` - The `setNodeMinBackoff` method is SDK is used to set the minimum backoff time (in milliseconds) for retrying operations on a specific node. + When you send a request to a node in the Hedera network, and the node fails to respond or encounters an error, the SDK will attempt to retry the request on the same node after a certain amount of time. This time is known as the backoff time, and it starts at a minimum value (set by setNodeMinBackoff) and increases exponentially with each subsequent retry attempt, up to a maximum value (set by setNodeMaxBackoff). + The backoff mechanism is designed to prevent overwhelming the nodes with too many retries in a short period of time, while still allowing the SDK to recover from transient failures or network issues. + Here's an example of how you can set the minimum node backoff time using the setNodeMinBackoff method: -``` +```javascript const client = Client.forNetwork(); client.setNodeMinBackoff(500); // Set minimum node backoff to 500 milliseconds (0.5 seconds) ``` -- `setNodeMaxBackoff` - Set maximum node backoff time - -Same as above but it sets the maximum seconds allowed for a node backoff. +- `setNodeMaxBackoff` - It sets the maximum seconds allowed for the node backoff explained in the previous setting. - `setNodeMinReadmitPeriod` - Set minimum node readmit period When a node fails to respond or encounters an error while processing a request, the SDK will temporarily remove that node from the pool of available nodes. This is done to prevent the SDK from repeatedly sending requests to a node that is experiencing issues, which could further exacerbate the problem. The `setNodeMinReadmitPeriod` method allows you to configure the minimum amount of time that a node must wait before it can be readmitted to the pool of available nodes. During this period, the SDK will not send any requests to that node, giving it time to recover or resolve any issues it may be experiencing. - `setNodeMaxReadmitPeriod` - Set maximum node readmit period. + The setNodeMaxReadmitPeriod method allows you to configure the maximum amount of time that a node can be excluded from the pool of available nodes. After this period has elapsed, the SDK will automatically readmit the node to the pool, regardless of whether it has recovered or not. -The setNodeMaxReadmitPeriod method allows you to configure the maximum amount of time that a node can be excluded from the pool of available nodes. After this period has elapsed, the SDK will automatically readmit the node to the pool, regardless of whether it has recovered or not. - -- `setNodeWaitTime` - The setNodeWaitTime method in the Hedera JavaScript SDK is used to set the minimum amount of time (in milliseconds) that the SDK will wait before attempting to send a request to a node that has recently failed or encountered an error. +- `setNodeWaitTime` - The `setNodeWaitTime` method in the Hedera JavaScript SDK is used to set the minimum amount of time (in milliseconds) that the SDK will wait before attempting to send a request to a node that has recently failed or encountered an error. -``` +```javascript const client = Client.forNetwork(); client.setNodeWaitTime(5000); // Set node wait time to 5 seconds (5000 milliseconds) ``` @@ -228,9 +248,9 @@ client.setNodeWaitTime(5000); // Set node wait time to 5 seconds (5000 milliseco - `setLogger` - Configure client logger. Setting a logger can give you additional information for debugging processes. This is an example of how you can use this fucntionality. -``` - const infoLogger = new Logger(LogLevel.Info); - client.setLogger(infoLogger); +```javascript +const infoLogger = new Logger(LogLevel.Info); +client.setLogger(infoLogger); ``` -There are different LogLevels. They may show only errors, warnings, or infos depending on the loglevel you have set. +There are different LogLevels: `LogLevel.Info`, ``LogLevel.Silent`, `LogLeve.Trace`, `LogLevel.Debug`, `LogLevel.Warn`, `LogLevel.Error`, `LogLevel.Fatal`. From 6ceb8536e98309ddeaec6c5eb6d5ed5c0bc71cf5 Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Sun, 8 Dec 2024 21:41:26 +0200 Subject: [PATCH 06/16] wip: formatting Signed-off-by: Ivaylo Nikolov --- CONFIGURATION.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 6d920fa7b..d5e1d7edb 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -7,8 +7,8 @@ The packages of the JS SDK support loading of configuration from an .env file or 1. Introduction .................................................. 2. Configuration Options ......................................... 2.1 Network Configuration ..................................... - 2.2 Operator Settings .......................................... 4 - 2.3 Transaction Settings ....................................... 5 + 2.2 Operator Settings .......................................... + 2.3 Transaction Settings ....................................... 3. Error Handling ................................................ 4. Examples ...................................................... 5. Conclusion .................................................... From a8dd4f782f633e7888ccc033d0a559332f8310ad Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Sun, 8 Dec 2024 22:24:07 +0200 Subject: [PATCH 07/16] docs: add toc Signed-off-by: Ivaylo Nikolov --- CONFIGURATION.md | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index d5e1d7edb..91a4745bd 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -1,17 +1,31 @@ # Introduction -The packages of the JS SDK support loading of configuration from an .env file or via the environment. - -# Table of contents - -1. Introduction .................................................. -2. Configuration Options ......................................... - 2.1 Network Configuration ..................................... - 2.2 Operator Settings .......................................... - 2.3 Transaction Settings ....................................... -3. Error Handling ................................................ -4. Examples ...................................................... -5. Conclusion .................................................... +The packages of the JS SDK support loading of configuration from an .env file or via the environment. You can also configure the JS by changing the configuration of the client. This document will explain the settings for all of these settings. + +- [Environment Variables](#environment-variables) + - [Required](#required) +- [ED25519 or ECDSA key](#ed25519-or-ecdsa-key) + - [Integration tests](#integration-tests) + - [Examples](#examples) + - [`fromStringDer`](#-fromstringder-) + - [Optional Parameters](#optional-parameters) + - [React Native Example](#react-native-example) + - [Simple REST Signature Provider](#simple-rest-signature-provider) +- [Which network to use?](#which-network-to-use-) +- [How to get my account keys and IDs?](#how-to-get-my-account-keys-and-ids-) + - [Local network](#local-network) + - [Testnet and previewnet](#testnet-and-previewnet) +- [Possible configuration issues](#possible-configuration-issues) +- [Should I have multiple .env files like .env.local, .env.production, .envdevelopment etc?](#should-i-have-multiple-env-files-like-envlocal--envproduction--envdevelopment-etc-) +- [Client Configuration](#client-configuration) + - [Network Configuration](#network-configuration) + - [Operator Settings](#operator-settings) + - [Transaction Settings](#transaction-settings) + - [Query Settings](#query-settings) + - [Retry and Timeout Settings](#retry-and-timeout-settings) + - [Node Management](#node-management) + - [Network Update Settings](#network-update-settings) + - [Logging](#logging) ## Environment Variables From 5ea40802dd0c9baf3a6b055465714bf15156a93c Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Sun, 8 Dec 2024 22:26:59 +0200 Subject: [PATCH 08/16] change headings Signed-off-by: Ivaylo Nikolov --- CONFIGURATION.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 91a4745bd..3a680e927 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -2,6 +2,8 @@ The packages of the JS SDK support loading of configuration from an .env file or via the environment. You can also configure the JS by changing the configuration of the client. This document will explain the settings for all of these settings. +# Table of content + - [Environment Variables](#environment-variables) - [Required](#required) - [ED25519 or ECDSA key](#ed25519-or-ecdsa-key) @@ -27,9 +29,9 @@ The packages of the JS SDK support loading of configuration from an .env file or - [Network Update Settings](#network-update-settings) - [Logging](#logging) -## Environment Variables +# Environment Variables -### Required +## Required | Name | Value | Example | | -------------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | @@ -113,9 +115,9 @@ To run the examples on the testnet, you can obtain your account keys and IDs fro [Owner of dotenv says - no.](https://github.com/motdotla/dotenv#should-i-have-multiple-env-files) -## Client Configuration +# Client Configuration -### Network Configuration +## Network Configuration - `setNetwork` - The setNetwork method configures the network nodes that your client will communicate with on the Hedera network. It's a fundamental configuration step that determines which nodes will process your transactions and queries. @@ -165,7 +167,7 @@ const client = Client.forNetwork(); client.setTransportSecurity(true); ``` -### Operator Settings +## Operator Settings - `setOperator` - Set the operator account and private key. The operator is the account that will pay for the transactions the user executes. @@ -183,7 +185,7 @@ tx.setOperatorWith(accountId, key.publicKey, (message) => ); ``` -### Transaction Settings +## Transaction Settings - `setDefaultMaxTransactionFee` - Set maximum transaction fee user is willing to pay. @@ -201,11 +203,11 @@ The setSignOnDemand method in the Hedera JavaScript SDK allows you to configure When you call client.setSignOnDemand(true), it instructs the SDK to defer the signing of transactions until the transaction.sign() method is explicitly called. This means that when you create a transaction using the SDK, it will not be signed automatically. Instead, you will need to call transaction.sign() manually before submitting the transaction to the network. -### Query Settings +## Query Settings - `setDefaultMaxQueryPayment` - Same as `setDefaultMaxTransactionFee` but for queries. -### Retry and Timeout Settings +## Retry and Timeout Settings - `setMaxAttempts` - Sets maximum retry attempts before an error is thrown. - `setMaxNodeAttempts` - Set maximum node retry attempts From 48aa3a0dcb2c7887e3bb8ead1eb865f4677fd422 Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Sun, 8 Dec 2024 22:28:09 +0200 Subject: [PATCH 09/16] docs: wording Signed-off-by: Ivaylo Nikolov --- CONFIGURATION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 3a680e927..da6279e9d 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -78,7 +78,7 @@ This example uses `fromString`, which internally calls `fromStringED25519`. ### Simple REST Signature Provider -This behaves the same as the React Native example. +This example behaves the same as the React Native example. ## Which network to use? From 98a33eb6a10c556f84a55eb6412844913382b600 Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Sun, 8 Dec 2024 22:29:57 +0200 Subject: [PATCH 10/16] docs: wording Signed-off-by: Ivaylo Nikolov --- CONFIGURATION.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index da6279e9d..336f48a1e 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -105,11 +105,11 @@ To run the examples on the testnet, you can obtain your account keys and IDs fro ## Possible configuration issues -- Most common problem is that users use ED25519 key when the code asks for ECDSA key or vice versa. Please double check if you sue the correct key. -- You might have ran the unit tests while running local-node. This will break multiple tests. -- Doesn't happen often but on rare ocassions some of the tests will break but rerunning them will give the expected result. -- If you hadn't used `local-node` for a long time sometimes it goes in sleep mode and you need to restart it to rerun the tests. This is not an issue with the SDK itself but still a very common problem. -- Please use the command `task install` and do not install the packages manually using `npm` or `yarn`. This might create some configuration issues. +- The most common issue occurs when users mistakenly use an ED25519 key instead of an ECDSA key, or vice versa. Please verify that you are using the correct key type. +- Running unit tests while the local-node is active can disrupt multiple tests. Ensure the node is not running when executing tests. +- Occasionally, some tests may fail unexpectedly. However, rerunning them usually resolves the issue. +- If local-node has been inactive for a while, it might enter sleep mode. Restarting it is often necessary to rerun tests. This is not an SDK-related issue but is a frequently encountered scenario. +- Always use the task install command to install dependencies. Avoid manual installation with npm or yarn, as it can lead to configuration problems. ## Should I have multiple .env files like .env.local, .env.production, .envdevelopment etc? From 2acc567bf4ce47686d86e8c4c9fcb2d183044971 Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Sun, 8 Dec 2024 22:42:46 +0200 Subject: [PATCH 11/16] docs: update readme.md Signed-off-by: Ivaylo Nikolov --- CONFIGURATION.md | 68 +++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 336f48a1e..6f4431de7 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -1,33 +1,33 @@ # Introduction -The packages of the JS SDK support loading of configuration from an .env file or via the environment. You can also configure the JS by changing the configuration of the client. This document will explain the settings for all of these settings. +The packages of the JS SDK support loading of configuration from an .env file or via the environment. You can also configure the client. This document will explain the settings for both of these configuration. # Table of content - [Environment Variables](#environment-variables) - [Required](#required) -- [ED25519 or ECDSA key](#ed25519-or-ecdsa-key) - - [Integration tests](#integration-tests) - - [Examples](#examples) - - [`fromStringDer`](#-fromstringder-) - - [Optional Parameters](#optional-parameters) - - [React Native Example](#react-native-example) - - [Simple REST Signature Provider](#simple-rest-signature-provider) -- [Which network to use?](#which-network-to-use-) -- [How to get my account keys and IDs?](#how-to-get-my-account-keys-and-ids-) - - [Local network](#local-network) - - [Testnet and previewnet](#testnet-and-previewnet) -- [Possible configuration issues](#possible-configuration-issues) -- [Should I have multiple .env files like .env.local, .env.production, .envdevelopment etc?](#should-i-have-multiple-env-files-like-envlocal--envproduction--envdevelopment-etc-) + - [ED25519 or ECDSA key](#ed25519-or-ecdsa-key) + - [Integration tests](#integration-tests) + - [Examples](#examples) + - [`fromStringDer`](#-fromstringder-) + - [Optional Parameters](#optional-parameters) + - [React Native Example](#react-native-example) + - [Simple REST Signature Provider](#simple-rest-signature-provider) + - [Which network to use?](#which-network-to-use-) + - [How to get my account keys and IDs?](#how-to-get-my-account-keys-and-ids-) + - [Local network](#local-network) + - [Testnet and previewnet](#testnet-and-previewnet) + - [Possible configuration issues](#possible-configuration-issues) + - [Should I have multiple .env files like .env.local, .env.production, .envdevelopment etc?](#should-i-have-multiple-env-files-like-envlocal--envproduction--envdevelopment-etc-) - [Client Configuration](#client-configuration) - [Network Configuration](#network-configuration) - [Operator Settings](#operator-settings) - [Transaction Settings](#transaction-settings) - [Query Settings](#query-settings) - [Retry and Timeout Settings](#retry-and-timeout-settings) - - [Node Management](#node-management) - - [Network Update Settings](#network-update-settings) - - [Logging](#logging) + - [Node Management](#node-management) + - [Network Update Settings](#network-update-settings) + - [Logging](#logging) # Environment Variables @@ -82,8 +82,8 @@ This example behaves the same as the React Native example. ## Which network to use? -- The maintainers of this repository use `hedera-local-node` when running integration tests. Running integration tests on testnet costs far too much HBARs. -- When running examples you can use any network you want. The examples are used for us to demonstrate to the community how a features is supposed to work so they optimized to work on any network you want. +- The maintainers of this repository use `hedera-local-node` when running integration tests. Running integration tests on testnet costs far too much HBARs making it unsustainable. +- When running the examples, you can use any network of your choice. These examples are designed to demonstrate how a feature is intended to work and are optimized to function on any network you prefer. - Unit tests do not require environment variables. ## How to get my account keys and IDs? @@ -119,7 +119,7 @@ To run the examples on the testnet, you can obtain your account keys and IDs fro ## Network Configuration -- `setNetwork` - The setNetwork method configures the network nodes that your client will communicate with on the Hedera network. It's a fundamental configuration step that determines which nodes will process your transactions and queries. +- `setNetwork` - The method configures the network nodes that your client will communicate with on the Hedera network. It's a fundamental configuration step that determines which nodes will process your transactions and queries. Example: @@ -190,19 +190,30 @@ tx.setOperatorWith(accountId, key.publicKey, (message) => - `setDefaultMaxTransactionFee` - Set maximum transaction fee user is willing to pay. ```javascript -const client = Client.forTestnet({ - scheduleNetworkUpdate: false, -}).setDefaultMaxTransactionFee(Hbar.fromTinybars(1)); +const client = Client.forTestnet().setDefaultMaxTransactionFee( + Hbar.fromTinybars(1), +); +// the network used here doesn't matter ``` - `setDefaultRegenerateTransactionId` - Configure transaction ID regeneration. This function accepts a boolean type of value. When set to true it will regenerate the transaction ID when a `TRANSACTION_EXPIRED` status is returned. +```javascript +const client = Client.forTestnet(); +client.setDefaultRegenerateTransactionId(true); +``` + - `setSignOnDemand` - Configure on-demand transaction signing The setSignOnDemand method in the Hedera JavaScript SDK allows you to configure how transactions are signed before being submitted to the Hedera network. By default, transactions are signed immediately after being constructed. However, in some cases, you may want to delay the signing process until just before the transaction is submitted. This can be useful in scenarios where you need to perform additional operations or validations on the transaction before signing it. When you call client.setSignOnDemand(true), it instructs the SDK to defer the signing of transactions until the transaction.sign() method is explicitly called. This means that when you create a transaction using the SDK, it will not be signed automatically. Instead, you will need to call transaction.sign() manually before submitting the transaction to the network. +```javascript +const client = Client.forTestnet(); +client.setSignOnDemand(true); +``` + ## Query Settings - `setDefaultMaxQueryPayment` - Same as `setDefaultMaxTransactionFee` but for queries. @@ -216,11 +227,20 @@ When you call client.setSignOnDemand(true), it instructs the SDK to defer the si - `setMaxBackoff` - Set maximum backoff time for retries Same as above but this sets on the maximum amount of seconds the backoff time may go. - `setRequestTimeout` - This timeout is the maximum allowed time for the entire transaction/query, including all retries. + +```javascript +let client = Client.forTestnet(); +client.setOperator(operatorAccountId, operatorPrivateKey); +client.setRequestTimeout(30000); +// Network doesn't matter here. +``` + - `setMaxExecutionTime` - this timeout applies to each single gRPC request within the transaction/query. It’s used for the edge cases where 10 seconds are not enough for the execution of a single gRPC request and the user can pass more. ```javascript const client = Client.forNetwork(); -client.setRequestTimeout(10000); // Set the request timeout to 10 seconds (10000 milliseconds) +const timeInMs = 10000; +client.setMaxExecutionTime(10000); // Set the request timeout to 10 seconds (10000 milliseconds) ``` ### Node Management From 2cb086e161b4fe37beecee010d4f196ee927be44 Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Sun, 8 Dec 2024 22:44:26 +0200 Subject: [PATCH 12/16] docs: update readme.md table Signed-off-by: Ivaylo Nikolov --- CONFIGURATION.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 6f4431de7..606587e4f 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -35,8 +35,8 @@ The packages of the JS SDK support loading of configuration from an .env file or | Name | Value | Example | | -------------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | -| OPERATOR_ID | Account ID of the operator account used to pay for transactions and queries | 302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10 | -| OPERATOR_KEY | ED25519 private key of the operator account | 0.0.12345 | +| OPERATOR_ID | Account ID of the operator account used to pay for transactions and queries | 0.0.12345 | +| OPERATOR_KEY | ED25519 private key of the operator account | 302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10 | | HEDERA_NETWORK | Network to connect to: mainnet, testnet, previewnet, or localhost | localhost | ## ED25519 or ECDSA key From 763b42537e795c4a37e9ccba69f7a3e21ce025d1 Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Sun, 8 Dec 2024 23:27:44 +0200 Subject: [PATCH 13/16] docs: wording, added links and notes Signed-off-by: Ivaylo Nikolov --- CONFIGURATION.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 606587e4f..57523c6bd 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -1,6 +1,6 @@ # Introduction -The packages of the JS SDK support loading of configuration from an .env file or via the environment. You can also configure the client. This document will explain the settings for both of these configuration. +The JS SDK package supports loading of configuration from an .env file or via the environment. You can use these environmental variables to configure the client. This document will explain the environmental variables needed and the client configuration. # Table of content @@ -43,19 +43,21 @@ The packages of the JS SDK support loading of configuration from an .env file or ### Integration tests -When you run integration tests you should use an Ed25519 private key. This is set up [here](test/integration/BaseIntegrationTestEnv.js:95). If you have an ECDSA key you should change the line to: +For integration tests, an Ed25519 private key should be used. This is configured here. If you are using an ECDSA key, update the line as follows: ```javascript const operatorKey = PrivateKey.fromStringECDSA(options.env.OPERATOR_KEY); ``` +It's recomended to use ED25519 due to it's better speed and performance. + ### Examples The examples use both ED25519 and ECDSA keys. These examples come with a pre-filled .env file, so you generally don’t need to make changes. However, if you modify the .env file, ensure the correct type of private key is used. To verify which type of key is required, check the example code for the initialization method in the client/wallet. Look for either `fromStringED25519` or `fromStringECDSA`. -_Note that some examples are designed to work only with ECDSA private keys._ +_Note that some examples (like the ones that interact with the relay) are designed to work only with ECDSA private keys. _ #### `fromStringDer` @@ -74,7 +76,7 @@ Certain examples simulate different actors in the network, such as Alice, Bob, o ### React Native Example -This example uses `fromString`, which internally calls `fromStringED25519`. +This example uses `fromString`, which internally will try to execute the example with `fromStringED25519`. ### Simple REST Signature Provider @@ -109,7 +111,7 @@ To run the examples on the testnet, you can obtain your account keys and IDs fro - Running unit tests while the local-node is active can disrupt multiple tests. Ensure the node is not running when executing tests. - Occasionally, some tests may fail unexpectedly. However, rerunning them usually resolves the issue. - If local-node has been inactive for a while, it might enter sleep mode. Restarting it is often necessary to rerun tests. This is not an SDK-related issue but is a frequently encountered scenario. -- Always use the task install command to install dependencies. Avoid manual installation with npm or yarn, as it can lead to configuration problems. +- Always use the `task install` command to install dependencies. Avoid manual installation with npm or yarn, as it can lead to configuration problems. ## Should I have multiple .env files like .env.local, .env.production, .envdevelopment etc? @@ -130,6 +132,8 @@ client.setNetwork({ }); ``` +You can find the nodes addresses and their `AccountIds` here - `[mainnet](https://docs.hedera.com/hedera/networks/mainnet/mainnet-nodes), [testnet](https://docs.hedera.com/hedera/networks/testnet/testnet-nodes), [previewnet](https://docs.hedera.com/hedera/networks/testnet/testnet-nodes#preview-testnet-nodes). + - `setMirrorNetwork` - Configure the mirror nodes ```javascript From 7c13db7b121f9523e39be7aa6316bcdbeec3ee2e Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Sun, 8 Dec 2024 23:37:49 +0200 Subject: [PATCH 14/16] docs: add table for default values Signed-off-by: Ivaylo Nikolov --- CONFIGURATION.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 57523c6bd..af5ba6895 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -202,6 +202,8 @@ const client = Client.forTestnet().setDefaultMaxTransactionFee( - `setDefaultRegenerateTransactionId` - Configure transaction ID regeneration. This function accepts a boolean type of value. When set to true it will regenerate the transaction ID when a `TRANSACTION_EXPIRED` status is returned. +Default value: true; + ```javascript const client = Client.forTestnet(); client.setDefaultRegenerateTransactionId(true); @@ -213,6 +215,8 @@ The setSignOnDemand method in the Hedera JavaScript SDK allows you to configure When you call client.setSignOnDemand(true), it instructs the SDK to defer the signing of transactions until the transaction.sign() method is explicitly called. This means that when you create a transaction using the SDK, it will not be signed automatically. Instead, you will need to call transaction.sign() manually before submitting the transaction to the network. +Default value: `false`. + ```javascript const client = Client.forTestnet(); client.setSignOnDemand(true); @@ -222,14 +226,22 @@ client.setSignOnDemand(true); - `setDefaultMaxQueryPayment` - Same as `setDefaultMaxTransactionFee` but for queries. +Default value: 1 Hbar + ## Retry and Timeout Settings - `setMaxAttempts` - Sets maximum retry attempts before an error is thrown. - `setMaxNodeAttempts` - Set maximum node retry attempts - `setMinBackoff` - Set minimum backoff time for retries. There's a time the SDK waits for after every failed attempt. A lower minBackoff value will result in more frequent retries initially, which can be useful for faster recovery from transient failures. This time increases exponentially. The default values provided by the SDK are generally reasonable for most use cases, but you may want to adjust them based on your specific requirements. + + Default value: 250 + - `setMaxBackoff` - Set maximum backoff time for retries Same as above but this sets on the maximum amount of seconds the backoff time may go. + + Default value: 8000 + - `setRequestTimeout` - This timeout is the maximum allowed time for the entire transaction/query, including all retries. ```javascript @@ -282,8 +294,13 @@ client.setNodeWaitTime(5000); // Set node wait time to 5 seconds (5000 milliseco - `setNetworkUpdatePeriod` - The setNetworkUpdatePeriod method in the Hedera JavaScript SDK is used to configure the frequency at which the SDK updates its internal representation of the Hedera network topology. The Hedera network is a distributed ledger system that consists of multiple nodes spread across different geographic locations. These nodes can join or leave the network at any time, and their availability and performance can vary depending on various factors such as network conditions, hardware issues, or software updates. To ensure that the SDK has an up-to-date view of the network topology, it periodically retrieves information about the available nodes and their respective performance metrics. This information is used to determine which nodes to send requests to and to adjust the load balancing and failover strategies accordingly. + + Default value: `24 * 60 * 60 * 1000` + - `setAutoValidateChecksums` - Configure automatic checksum validation +Default value: `false` + ### Logging - `setLogger` - Configure client logger. Setting a logger can give you additional information for debugging processes. This is an example of how you can use this fucntionality. @@ -294,3 +311,15 @@ client.setLogger(infoLogger); ``` There are different LogLevels: `LogLevel.Info`, ``LogLevel.Silent`, `LogLeve.Trace`, `LogLevel.Debug`, `LogLevel.Warn`, `LogLevel.Error`, `LogLevel.Fatal`. + +### Default values: + +| Key Name | Default Value | +| --------------------------------- | ---------------------------- | +| setDefaultRegenerateTransactionId | true | +| setSignOnDemand | false | +| setDefaultMaxQueryPayment | 1 Hbar | +| setMinBackoff | 250 (milliseconds) | +| setMaxBackoff | 8000 (milliseconds) | +| setNetworkUpdatePeriod | 24 60 60 1000 (milliseconds) | +| setAutoValidateChecksums | false | From 50dea5f98f9ebd9fb7966db5a9ed21d7f762c6b5 Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Sun, 8 Dec 2024 23:39:27 +0200 Subject: [PATCH 15/16] docs: remove default value text Signed-off-by: Ivaylo Nikolov --- CONFIGURATION.md | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index af5ba6895..409f71fd1 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -202,8 +202,6 @@ const client = Client.forTestnet().setDefaultMaxTransactionFee( - `setDefaultRegenerateTransactionId` - Configure transaction ID regeneration. This function accepts a boolean type of value. When set to true it will regenerate the transaction ID when a `TRANSACTION_EXPIRED` status is returned. -Default value: true; - ```javascript const client = Client.forTestnet(); client.setDefaultRegenerateTransactionId(true); @@ -215,8 +213,6 @@ The setSignOnDemand method in the Hedera JavaScript SDK allows you to configure When you call client.setSignOnDemand(true), it instructs the SDK to defer the signing of transactions until the transaction.sign() method is explicitly called. This means that when you create a transaction using the SDK, it will not be signed automatically. Instead, you will need to call transaction.sign() manually before submitting the transaction to the network. -Default value: `false`. - ```javascript const client = Client.forTestnet(); client.setSignOnDemand(true); @@ -226,8 +222,6 @@ client.setSignOnDemand(true); - `setDefaultMaxQueryPayment` - Same as `setDefaultMaxTransactionFee` but for queries. -Default value: 1 Hbar - ## Retry and Timeout Settings - `setMaxAttempts` - Sets maximum retry attempts before an error is thrown. @@ -235,13 +229,9 @@ Default value: 1 Hbar - `setMinBackoff` - Set minimum backoff time for retries. There's a time the SDK waits for after every failed attempt. A lower minBackoff value will result in more frequent retries initially, which can be useful for faster recovery from transient failures. This time increases exponentially. The default values provided by the SDK are generally reasonable for most use cases, but you may want to adjust them based on your specific requirements. - Default value: 250 - - `setMaxBackoff` - Set maximum backoff time for retries Same as above but this sets on the maximum amount of seconds the backoff time may go. - Default value: 8000 - - `setRequestTimeout` - This timeout is the maximum allowed time for the entire transaction/query, including all retries. ```javascript @@ -295,12 +285,8 @@ client.setNodeWaitTime(5000); // Set node wait time to 5 seconds (5000 milliseco The Hedera network is a distributed ledger system that consists of multiple nodes spread across different geographic locations. These nodes can join or leave the network at any time, and their availability and performance can vary depending on various factors such as network conditions, hardware issues, or software updates. To ensure that the SDK has an up-to-date view of the network topology, it periodically retrieves information about the available nodes and their respective performance metrics. This information is used to determine which nodes to send requests to and to adjust the load balancing and failover strategies accordingly. - Default value: `24 * 60 * 60 * 1000` - - `setAutoValidateChecksums` - Configure automatic checksum validation -Default value: `false` - ### Logging - `setLogger` - Configure client logger. Setting a logger can give you additional information for debugging processes. This is an example of how you can use this fucntionality. From 886050302b5adcf4c54e9f4e21d6a2fa92886527 Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Sun, 8 Dec 2024 23:42:30 +0200 Subject: [PATCH 16/16] docs: add to readme.md Signed-off-by: Ivaylo Nikolov --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index d9fa1c9a6..501b56ded 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,10 @@ See [examples](./examples). Every example can be executed using the following command from the root directory: `node examples/[name-of-example].js` +## Configuration + +For detailed information on configuring the SDK, including environment variables and client settings, please refer to the [CONFIGURATION.md](CONFIGURATION.md) file. + ## Start tests * To start the integration tests follow the next steps: