From a993700b78c4d454e68f9dcbef7d315b989fd586 Mon Sep 17 00:00:00 2001 From: myron Date: Mon, 24 Jun 2024 17:32:36 +0800 Subject: [PATCH 01/48] add doc for `handleRevert` --- docs/docs/guides/web3_config/index.md | 44 ++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index f6d041b6b15..da3adea9f37 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -9,7 +9,7 @@ sidebar_label: 'Web3 Config Guide' There is list of configuration params that can be set for modifying behavior of different functions in web3.js packages. Following is list of configuration options with details: -- [handleRevert]( /api/web3-core/class/Web3Config#handleRevert) +- [handleRevert](/api/web3-core/class/Web3Config#handleRevert) - [defaultAccount](/api/web3-core/class/Web3Config#defaultAccount) - [defaultBlock](/api/web3-core/class/Web3Config#defaultBlock) - [transactionBlockTimeout](/api/web3-core/class/Web3Config#transactionBlockTimeout) @@ -201,6 +201,48 @@ console.log(web3.getContextObject().config) */ ``` +### handleRevert +When `handleRevert` is set to True, the following methods will retrieve specific error types and error messages: +```ts +- web3.eth.sendTransaction() +- web3.eth.call() +- myContract.methods.myMethod().call() +- myContract.methods.myMethod().send() +``` + +The error types will be one of the following: +```ts +- InvalidResponseError +- ContractExecutionError +- TransactionRevertWithCustomError +- TransactionRevertedWithoutReasonError +- TransactionRevertInstructionError +- TransactionPollingTimeoutError +``` + +For example, the error message could be `TransactionRevertInstructionError('Returned error: invalid argument 0: json: cannot unmarshal invalid hex string into Go struct field TransactionArgs.data of type hexutil.Bytes')`. The default value is `false`, and handleRevert is only supported for `sendTransaction` and not for `sendSignedTransaction` at this time. + +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.handleRevert = true; + +console.log(web3.getContextObject().config) +``` +:::info +The `handleRevert` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.handleRevert = true; + +console.log(web3.eth.getContextObject().config) +``` +::: ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From 46dc3239107a6597fbf3c52f2bc69e0f1161aeea Mon Sep 17 00:00:00 2001 From: myron Date: Mon, 24 Jun 2024 18:00:04 +0800 Subject: [PATCH 02/48] add doc for defaultAccount --- docs/docs/guides/web3_config/index.md | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index da3adea9f37..8b9cf8d6c8d 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -244,6 +244,39 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### defaultAccount +This `defaultAccount` is used as the default `from` property, if no `from` property is specified in for the following methods: +```ts +- web3.eth.sendTransaction() +- web3.eth.call() +- myContract.methods.myMethod().call() +- myContract.methods.myMethod().send() +``` + +The default value for `defaultAccount` is `undefined`. It is worth noting that the `defaultAccount` here can be any string, as there is no validation during the config phase. + +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultAccount = "0x0000000000000000000000000000000000000000"; + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultAccount` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultAccount = "0x0000000000000000000000000000000000000000"; + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From 6d9fcf8765b762c966be0a804b895c1793961083 Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 15:44:15 +0800 Subject: [PATCH 03/48] add doc for `defaultBlock` --- docs/docs/guides/web3_config/index.md | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 8b9cf8d6c8d..f4a1bfd845c 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -277,6 +277,52 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### defaultBlock +The following methods require a `blockNumber` parameter during its execution process, the `defaultBlock` is used for these methods. +```ts +- web3.eth.getBalance() +- web3.eth.getCode() +- web3.eth.getTransactionCount() +- web3.eth.getStorageAt() +- web3.eth.call() +- myContract.methods.myMethod().call() +``` + +You can override it by passing in the defaultBlock as last parameter. The default value is "latest". + +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultBlock = 20167235; + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultBlock` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultBlock = "earliest"; + +console.log(web3.eth.getContextObject().config) +``` +::: + +#### All available choices for defaultBlock: +```ts +web3.defaultBlock = 20167235; // A block number +web3.defaultBlock = "earliest"; // The genesis block +web3.defaultBlock = "latest"; // The latest block (current head of the blockchain) +web3.defaultBlock = "pending"; // The currently mined block (including pending transactions) +web3.defaultBlock = "finalized"; // (For POS networks) The finalized block is one which has been accepted as canonical by greater than 2/3 of validators +web3.defaultBlock = "safe"; // (For POS networks) The safe head block is one which under normal network conditions, is expected to be included in the canonical chain. Under normal network conditions the safe head and the actual tip of the chain will be equivalent (with safe head trailing only by a few seconds). Safe heads will be less likely to be reorged than the proof of work network`s latest blocks. +``` + + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From 6c0f38cb2470b5fd995f3ffda18315de7898e2b9 Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 15:57:48 +0800 Subject: [PATCH 04/48] add doc for transactionBlockTimeout --- docs/docs/guides/web3_config/index.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index f4a1bfd845c..fa163630989 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -322,6 +322,31 @@ web3.defaultBlock = "finalized"; // (For POS networks) The finalized block is on web3.defaultBlock = "safe"; // (For POS networks) The safe head block is one which under normal network conditions, is expected to be included in the canonical chain. Under normal network conditions the safe head and the actual tip of the chain will be equivalent (with safe head trailing only by a few seconds). Safe heads will be less likely to be reorged than the proof of work network`s latest blocks. ``` +### transactionBlockTimeout +The `transactionBlockTimeout` is used over socket-based connections. This option defines the amount of new blocks it should wait until the **first confirmation** happens, otherwise the PromiEvent rejects with a timeout error. The default value is 50. + +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.transactionBlockTimeout = 60; + +console.log(web3.getContextObject().config) +``` +:::info +The `transactionBlockTimeout` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.transactionBlockTimeout = 60; + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From 38ac6edf1ac10555042e703ccce16facf09a83af Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 16:06:26 +0800 Subject: [PATCH 05/48] add doc for transactionConfirmationBlocks --- docs/docs/guides/web3_config/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index fa163630989..df3c7d837d0 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -347,6 +347,30 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### transactionConfirmationBlocks +This defines the number of blocks it requires until a transaction is considered confirmed. Different chains have varying security considerations and requirements for confirmation block numbers. The default value is 24. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.transactionConfirmationBlocks = 60; + +console.log(web3.getContextObject().config) +``` +:::info +The `transactionConfirmationBlocks` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.transactionConfirmationBlocks = 60; + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From 0fb431ae9a141c0d0d67b099e05a4b39c3b93670 Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 16:11:50 +0800 Subject: [PATCH 06/48] add doc for transactionPollingInterval --- docs/docs/guides/web3_config/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index df3c7d837d0..db937c90530 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -372,6 +372,30 @@ console.log(web3.eth.getContextObject().config) ::: +### transactionPollingInterval +The `transactionPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Modifying this value can reduce the wait time for confirmations or decrease the number of network requests. Default is 1000 ms. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.transactionPollingInterval = 2000; // 2000 ms = 2 s + +console.log(web3.getContextObject().config) +``` +:::info +The `transactionPollingInterval` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.transactionPollingInterval = 2000; // 2000 ms = 2 s + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From 5744e790d01d92704d0e5adc0bcbcd656bfbe58e Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 16:21:16 +0800 Subject: [PATCH 07/48] add doc for transactionPollingTimeout --- docs/docs/guides/web3_config/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index db937c90530..345a42b90df 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -396,6 +396,30 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### transactionPollingTimeout +The `transactionPollingTimeout` is used over HTTP connections. This option defines the number of seconds Web3 will wait for a receipt which confirms that a transaction was mined by the network. It can be set based on the average transaction confirmation time on the network. Note: If this method times out, the transaction may still be pending. Default is 750 seconds (12.5 minutes). +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.transactionPollingTimeout = 600000; // 600000 ms = 600 s = 10 min + +console.log(web3.getContextObject().config) +``` +:::info +The `transactionPollingTimeout` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.transactionPollingTimeout = 600000; // 600000 ms = 600 s = 10 min + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From 382ee1d3316da0269536563e593c5282ede75f9b Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 16:46:17 +0800 Subject: [PATCH 08/48] add doc for transactionReceiptPollingInterval and improve doc for transactionPollingInterval --- docs/docs/guides/web3_config/index.md | 45 ++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 345a42b90df..f445524b3fa 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -373,7 +373,7 @@ console.log(web3.eth.getContextObject().config) ### transactionPollingInterval -The `transactionPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Modifying this value can reduce the wait time for confirmations or decrease the number of network requests. Default is 1000 ms. +The `transactionPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Modifying this value can reduce the wait time for confirmations or decrease the number of network requests. Setting the `transactionPollingInterval` would also set `transactionReceiptPollingInterval` and `transactionConfirmationPollingInterval` to the same value. Default is 1000 ms. ```ts import { Web3 } from 'web3'; @@ -382,6 +382,15 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.transactionPollingInterval = 2000; // 2000 ms = 2 s console.log(web3.getContextObject().config) +/* ↳ + ... + transactionPollingInterval: 2000, + transactionPollingTimeout: 750000, + transactionReceiptPollingInterval: 2000, + transactionSendTimeout: 750000, + transactionConfirmationPollingInterval: 2000, + ... +*/ ``` :::info The `transactionPollingInterval` can be configured both globally and at the package level: @@ -393,6 +402,15 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.transactionPollingInterval = 2000; // 2000 ms = 2 s console.log(web3.eth.getContextObject().config) +/* ↳ + ... + transactionPollingInterval: 2000, + transactionPollingTimeout: 750000, + transactionReceiptPollingInterval: 2000, + transactionSendTimeout: 750000, + transactionConfirmationPollingInterval: 2000, + ... +*/ ``` ::: @@ -420,6 +438,31 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### transactionReceiptPollingInterval +The `transactionReceiptPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Compared to `transactionPollingInterval`, it takes higher precedence. When this value is set, it will be read first. Default is `undefined`. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.transactionReceiptPollingInterval = 2000; // 2000 ms = 2 s + +console.log(web3.getContextObject().config) +``` +:::info +The `transactionReceiptPollingInterval` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.transactionReceiptPollingInterval = undefined; + +console.log(web3.eth.getContextObject().config) +``` +::: + + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From 58445a9ab2cbdd6baee814a4fbb902191a166dad Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 17:00:53 +0800 Subject: [PATCH 09/48] add doc for transactionSendTimeout --- docs/docs/guides/web3_config/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index f445524b3fa..e77cc4df068 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -462,6 +462,30 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### transactionSendTimeout +The `transactionSendTimeout` is used to wait for Ethereum Node to return the sent transaction result. Note: If the RPC call stuck at the Node and therefor timed-out, the transaction may still be pending or even mined by the Network. We recommend checking the pending transactions in such a case. Default is 750 seconds (12.5 minutes). +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.transactionSendTimeout = 600000; // 600000 ms = 600 s = 10 min + +console.log(web3.getContextObject().config) +``` +:::info +The `transactionSendTimeout` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.transactionSendTimeout = 600000; // 600000 ms = 600 s = 10 min + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From b23bb96808960246c57048f8eada6e31a3b2097b Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 17:20:39 +0800 Subject: [PATCH 10/48] add doc for transactionConfirmationPollingInterval --- docs/docs/guides/web3_config/index.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index e77cc4df068..cf67c68e4b9 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -18,7 +18,7 @@ There is list of configuration params that can be set for modifying behavior of - [transactionPollingTimeout](/api/web3-core/class/Web3Config#transactionPollingTimeout) - [transactionReceiptPollingInterval](/api/web3-core/class/Web3Config#transactionReceiptPollingInterval) - [transactionSendTimeout](/api/web3-core/class/Web3Config#transactionSendTimeout) -- [transactionConfirmationPollingInterval](/api/web3-core/class/Web3Config#transactionConfirmationPollingInterval) +- [Deprecated][transactionConfirmationPollingInterval](/api/web3-core/class/Web3Config#transactionConfirmationPollingInterval) - [blockHeaderTimeout](/api/web3-core/class/Web3Config#blockHeaderTimeout) - [maxListenersWarningThreshold](/api/web3-core/class/Web3Config#maxListenersWarningThreshold) - [contractDataInputFill](/api/web3-core/class/Web3Config#contractDataInputFill) @@ -486,6 +486,9 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### transactionConfirmationPollingInterval +The `transactionConfirmationPollingInterval` is deprecated. Please use `transactionReceiptPollingInterval` or `transactionPollingInterval` instead. + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From a0adf0b7cde0288ce966180d8fb2452ddb4d2f8c Mon Sep 17 00:00:00 2001 From: myron Date: Wed, 26 Jun 2024 15:02:36 +0800 Subject: [PATCH 11/48] add doc for blockHeaderTimeout --- docs/docs/guides/web3_config/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index cf67c68e4b9..ec1ba49c17c 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -489,6 +489,30 @@ console.log(web3.eth.getContextObject().config) ### transactionConfirmationPollingInterval The `transactionConfirmationPollingInterval` is deprecated. Please use `transactionReceiptPollingInterval` or `transactionPollingInterval` instead. +### blockHeaderTimeout +The `blockHeaderTimeout` is used over socket-based connections. After sending a transaction, it will listen for the appearance of new blocks and proceed with subsequent operations based on the transaction results within them. This option defines the amount seconds it should wait for 'newBlockHeaders' event before falling back to polling to fetch transaction receipt. Default is 10 seconds. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.blockHeaderTimeout = 20; // 20 s + +console.log(web3.getContextObject().config) +``` +:::info +The `blockHeaderTimeout` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.blockHeaderTimeout = 20; // 20 s + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From 973d9bb9f0348f696c3cbb8b5fef32f3beafacdf Mon Sep 17 00:00:00 2001 From: myron Date: Wed, 26 Jun 2024 15:31:38 +0800 Subject: [PATCH 12/48] add doc for maxListenersWarningThreshold --- docs/docs/guides/web3_config/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index ec1ba49c17c..bccbaf1a35b 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -513,6 +513,30 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### maxListenersWarningThreshold +The `maxListenersWarningThreshold` is used to set the `maxListeners` property in `EventEmitter`. Default is 100. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.maxListenersWarningThreshold = 200; + +console.log(web3.getContextObject().config) +``` +:::info +The `maxListenersWarningThreshold` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.maxListenersWarningThreshold = 200; + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From c50492bf155b35582952cbbab3b606a5c4457783 Mon Sep 17 00:00:00 2001 From: myron Date: Wed, 26 Jun 2024 15:48:37 +0800 Subject: [PATCH 13/48] add doc for contractDataInputFill --- docs/docs/guides/web3_config/index.md | 28 +++++++++++++++++++++++++++ packages/web3-core/src/web3_config.ts | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index bccbaf1a35b..60c74a59b60 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -537,6 +537,34 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### contractDataInputFill +The `contractDataInputFill` will allow you to set the hash of the method signature and encoded parameters to the property either `data`, `input` or `both` within your contract. This will affect the contracts send, call and estimateGas methods. Default is `data`. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.contractDataInputFill = 'input'; + +console.log(web3.getContextObject().config) +``` +:::info +The `contractDataInputFill` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.contractDataInputFill = 'both'; + +console.log(web3.eth.getContextObject().config) +``` +::: + +#### All available choices for contractDataInputFill: +```ts +contractDataInputFill: 'data' | 'input' | 'both'; +``` ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. diff --git a/packages/web3-core/src/web3_config.ts b/packages/web3-core/src/web3_config.ts index 3c335292c4a..1f84970e2b7 100644 --- a/packages/web3-core/src/web3_config.ts +++ b/packages/web3-core/src/web3_config.ts @@ -144,7 +144,7 @@ export abstract class Web3Config * The `contractDataInputFill` options property will allow you to set the hash of the method signature and encoded parameters to the property * either `data`, `input` or both within your contract. * This will affect the contracts send, call and estimateGas methods - * Default is `input`. + * Default is `data`. */ public get contractDataInputFill() { return this.config.contractDataInputFill; From 56c61524282a429d7a97ef1fad86965a5a6387fc Mon Sep 17 00:00:00 2001 From: myron Date: Wed, 26 Jun 2024 16:08:21 +0800 Subject: [PATCH 14/48] add doc for defaultNetworkId --- docs/docs/guides/web3_config/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 60c74a59b60..22ec2e99244 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -566,6 +566,30 @@ console.log(web3.eth.getContextObject().config) contractDataInputFill: 'data' | 'input' | 'both'; ``` +### defaultNetworkId +Each network has its own network ID. The defaultNetwork allows you to set the default network ID to increase code readability. If this parameter is not set, it will fetch the network ID from the connected RPC request. Default is `undefined`. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultNetworkId = 56; + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultNetworkId` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultNetworkId = '0x1'; + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From fbab925211958d441b3777979e9a81865971bd53 Mon Sep 17 00:00:00 2001 From: myron Date: Wed, 26 Jun 2024 17:00:39 +0800 Subject: [PATCH 15/48] add doc for defaultHardfork, defaultChain and defaultCommon --- docs/docs/guides/web3_config/index.md | 132 ++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 22ec2e99244..efbe2bcfd8a 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -590,6 +590,138 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### defaultChain +The `defaultChain` is used for building the `baseChain` property of the tx options in a transaction. If the `defaultCommon.basechain` is set, the`defaultChain` should be consistent with it. Default is `mainnet`. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultChain = 'ropsten'; + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultChain` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultChain = 'ropsten'; + +console.log(web3.eth.getContextObject().config) +``` +::: +#### All available choices for defaultChain: +```ts +'goerli' | 'kovan' | 'mainnet' | 'rinkeby' | 'ropsten' | 'sepolia' +``` + + +### defaultHardfork +The `defaultHardfork` is used for building the `defaultHardfork` property of the tx options in a transaction. If the `defaultCommon.defaultHardfork` is set, the`defaultHardfork` should be consistent with it. Default is `london`. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultHardfork = 'berlin'; + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultHardfork` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultHardfork = 'istanbul'; + +console.log(web3.eth.getContextObject().config) +``` +::: +#### All available choices for contractDataInputFill: +```ts +'chainstart' +'frontier' +'homestead' +'dao' +'tangerineWhistle' +'spuriousDragon' +'byzantium' +'constantinople' +'petersburg' +'istanbul' +'muirGlacier' +'berlin' +'london' +'altair' +'arrowGlacier' +'grayGlacier' +'bellatrix' +'merge' +'capella' +'sharding' +``` + +### defaultCommon +The `defaultCommon` is used for building the `common` property of the tx options in a transaction. It should be consistent with the `defaultHardfork` and `defaultChain`. The `defaultCommon` property does contain the following Common object: +``` +- customChain - Object: The custom chain properties + - name - string: (optional) The name of the chain + - networkId - number: Network ID of the custom chain + - chainId - number: Chain ID of the custom chain +- baseChain - string: (optional) 'goerli', 'kovan', 'mainnet', 'rinkeby', 'ropsten' or 'sepolia' +- hardfork - string: (optional) chainstart, homestead, dao, tangerineWhistle, spuriousDragon, byzantium, constantinople, petersburg, istanbul, berlin, or london +``` + +The default value of `defaultCommon` is `undefined`. + +```ts +import { Web3, Hardfork } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultHardfork = 'berlin' +web3.defaultChain = 'goerli' + +web3.defaultCommon = { + baseChain: 'goerli', + hardfork: 'berlin' as Hardfork, + customChain: { + networkId: 1, + chainId: 1, + }, +}; + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultCommon` can be configured both globally and at the package level: +```ts +import { Web3, Hardfork } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultHardfork = 'berlin' +web3.eth.defaultChain = 'goerli' + +web3.eth.defaultCommon = { + baseChain: 'goerli', + hardfork: 'berlin' as Hardfork, + customChain: { + networkId: 1, + chainId: 1, + }, +}; + +console.log(web3.eth.getContextObject().config) +``` +::: + + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From 6787e8ba37c075b865f84b54c7bc4e5e9a70165f Mon Sep 17 00:00:00 2001 From: blackmoshui Date: Wed, 26 Jun 2024 17:54:40 +0800 Subject: [PATCH 16/48] add doc for defaultTransactionType --- docs/docs/guides/web3_config/index.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index efbe2bcfd8a..2c9cdd0ef29 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -721,6 +721,29 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### defaultTransactionType +The `defaultTransactionType` is used set the transaction type. Transactions with type 0x0 are legacy transactions that use the transaction format existing before typed transactions were introduced in EIP-2718. Transactions with type 0x1 are transactions introduced in EIP-2930. Transactions with type 0x2 are transactions introduced in EIP-1559, included in Ethereum's London fork. Default is `0x02`. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultTransactionType = 0x0; + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultTransactionType` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultTransactionType = 0x0; + +console.log(web3.eth.getContextObject().config) +``` +::: ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From 8297909e3286ed85baabe69a3d7f765f69e20b6d Mon Sep 17 00:00:00 2001 From: blackmoshui Date: Wed, 26 Jun 2024 18:05:39 +0800 Subject: [PATCH 17/48] add doc for defaultMaxPriorityFeePerGas --- docs/docs/guides/web3_config/index.md | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 2c9cdd0ef29..f1366079eab 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -26,7 +26,8 @@ There is list of configuration params that can be set for modifying behavior of - [defaultChain](/api/web3-core/class/Web3Config#defaultChain) - [defaultHardfork](/api/web3-core/class/Web3Config#defaultHardfork) - [defaultCommon](/api/web3-core/class/Web3Config#defaultCommon) -- [defaultTransactionType](/api/web3-core/class/Web3Config#defaultTransactionType) +- [defaultTransactionType](/api/web3-core/class/Web3Config#defaultTransactionType) +- [defaultMaxPriorityFeePerGas](/api/web3-core/class/Web3Config#defaultMaxPriorityFeePerGas) - [defaultReturnFormat](/api/web3-core/class/Web3Config#defaultReturnFormat) ## Global level Config @@ -745,6 +746,32 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### defaultMaxPriorityFeePerGas +The `defaultMaxPriorityFeePerGas` is used to send transactions with the maximum priority gas fee. The default value is 2500000000 (2.5gwei) in hexstring format. +```ts +import { Web3 } from 'web3'; +import { numberToHex } from 'web3-utils' + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultMaxPriorityFeePerGas = numberToHex(2100000000); // 2.1gwei + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultMaxPriorityFeePerGas` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; +import { numberToHex } from 'web3-utils' + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultMaxPriorityFeePerGas = numberToHex(2100000000); // 2.1gwei + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From 098a245fbd6a0f4b6f181840d52442b995070ffb Mon Sep 17 00:00:00 2001 From: myron Date: Thu, 27 Jun 2024 09:17:07 +0800 Subject: [PATCH 18/48] refine --- docs/docs/guides/web3_config/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index f1366079eab..bb6bba25cc2 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -221,7 +221,7 @@ The error types will be one of the following: - TransactionPollingTimeoutError ``` -For example, the error message could be `TransactionRevertInstructionError('Returned error: invalid argument 0: json: cannot unmarshal invalid hex string into Go struct field TransactionArgs.data of type hexutil.Bytes')`. The default value is `false`, and handleRevert is only supported for `sendTransaction` and not for `sendSignedTransaction` at this time. +For example, the error message could be `TransactionRevertInstructionError('Returned error: invalid argument 0: json: cannot unmarshal invalid hex string into Go struct field TransactionArgs.data of type hexutil.Bytes')`. The default value is `false`, and handleRevert is only supported for `sendTransaction` and not for `sendSignedTransaction` for now. ```ts import { Web3 } from 'web3'; @@ -254,7 +254,7 @@ This `defaultAccount` is used as the default `from` property, if no `from` prope - myContract.methods.myMethod().send() ``` -The default value for `defaultAccount` is `undefined`. It is worth noting that the `defaultAccount` here can be any string, as there is no validation during the config phase. +The default value for `defaultAccount` is `undefined`. ```ts import { Web3 } from 'web3'; @@ -574,7 +574,7 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.defaultNetworkId = 56; +web3.defaultNetworkId = 1; console.log(web3.getContextObject().config) ``` From c8d5ea0387d58328832f6b3546ded425a3abe63b Mon Sep 17 00:00:00 2001 From: myron Date: Mon, 24 Jun 2024 17:32:36 +0800 Subject: [PATCH 19/48] add doc for `handleRevert` --- docs/docs/guides/web3_config/index.md | 44 ++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index f6d041b6b15..da3adea9f37 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -9,7 +9,7 @@ sidebar_label: 'Web3 Config Guide' There is list of configuration params that can be set for modifying behavior of different functions in web3.js packages. Following is list of configuration options with details: -- [handleRevert]( /api/web3-core/class/Web3Config#handleRevert) +- [handleRevert](/api/web3-core/class/Web3Config#handleRevert) - [defaultAccount](/api/web3-core/class/Web3Config#defaultAccount) - [defaultBlock](/api/web3-core/class/Web3Config#defaultBlock) - [transactionBlockTimeout](/api/web3-core/class/Web3Config#transactionBlockTimeout) @@ -201,6 +201,48 @@ console.log(web3.getContextObject().config) */ ``` +### handleRevert +When `handleRevert` is set to True, the following methods will retrieve specific error types and error messages: +```ts +- web3.eth.sendTransaction() +- web3.eth.call() +- myContract.methods.myMethod().call() +- myContract.methods.myMethod().send() +``` + +The error types will be one of the following: +```ts +- InvalidResponseError +- ContractExecutionError +- TransactionRevertWithCustomError +- TransactionRevertedWithoutReasonError +- TransactionRevertInstructionError +- TransactionPollingTimeoutError +``` + +For example, the error message could be `TransactionRevertInstructionError('Returned error: invalid argument 0: json: cannot unmarshal invalid hex string into Go struct field TransactionArgs.data of type hexutil.Bytes')`. The default value is `false`, and handleRevert is only supported for `sendTransaction` and not for `sendSignedTransaction` at this time. + +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.handleRevert = true; + +console.log(web3.getContextObject().config) +``` +:::info +The `handleRevert` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.handleRevert = true; + +console.log(web3.eth.getContextObject().config) +``` +::: ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From 1e3794c051fe3b07bc337e9b6cefae0329842f3b Mon Sep 17 00:00:00 2001 From: myron Date: Mon, 24 Jun 2024 18:00:04 +0800 Subject: [PATCH 20/48] add doc for defaultAccount --- docs/docs/guides/web3_config/index.md | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index da3adea9f37..8b9cf8d6c8d 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -244,6 +244,39 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### defaultAccount +This `defaultAccount` is used as the default `from` property, if no `from` property is specified in for the following methods: +```ts +- web3.eth.sendTransaction() +- web3.eth.call() +- myContract.methods.myMethod().call() +- myContract.methods.myMethod().send() +``` + +The default value for `defaultAccount` is `undefined`. It is worth noting that the `defaultAccount` here can be any string, as there is no validation during the config phase. + +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultAccount = "0x0000000000000000000000000000000000000000"; + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultAccount` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultAccount = "0x0000000000000000000000000000000000000000"; + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From 77931c95637a5c70719b60ae8573e4b26f2fd86d Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 15:44:15 +0800 Subject: [PATCH 21/48] add doc for `defaultBlock` --- docs/docs/guides/web3_config/index.md | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 8b9cf8d6c8d..f4a1bfd845c 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -277,6 +277,52 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### defaultBlock +The following methods require a `blockNumber` parameter during its execution process, the `defaultBlock` is used for these methods. +```ts +- web3.eth.getBalance() +- web3.eth.getCode() +- web3.eth.getTransactionCount() +- web3.eth.getStorageAt() +- web3.eth.call() +- myContract.methods.myMethod().call() +``` + +You can override it by passing in the defaultBlock as last parameter. The default value is "latest". + +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultBlock = 20167235; + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultBlock` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultBlock = "earliest"; + +console.log(web3.eth.getContextObject().config) +``` +::: + +#### All available choices for defaultBlock: +```ts +web3.defaultBlock = 20167235; // A block number +web3.defaultBlock = "earliest"; // The genesis block +web3.defaultBlock = "latest"; // The latest block (current head of the blockchain) +web3.defaultBlock = "pending"; // The currently mined block (including pending transactions) +web3.defaultBlock = "finalized"; // (For POS networks) The finalized block is one which has been accepted as canonical by greater than 2/3 of validators +web3.defaultBlock = "safe"; // (For POS networks) The safe head block is one which under normal network conditions, is expected to be included in the canonical chain. Under normal network conditions the safe head and the actual tip of the chain will be equivalent (with safe head trailing only by a few seconds). Safe heads will be less likely to be reorged than the proof of work network`s latest blocks. +``` + + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From c618a8154dbddf54f7eb2c5bcd427258182763e1 Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 15:57:48 +0800 Subject: [PATCH 22/48] add doc for transactionBlockTimeout --- docs/docs/guides/web3_config/index.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index f4a1bfd845c..fa163630989 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -322,6 +322,31 @@ web3.defaultBlock = "finalized"; // (For POS networks) The finalized block is on web3.defaultBlock = "safe"; // (For POS networks) The safe head block is one which under normal network conditions, is expected to be included in the canonical chain. Under normal network conditions the safe head and the actual tip of the chain will be equivalent (with safe head trailing only by a few seconds). Safe heads will be less likely to be reorged than the proof of work network`s latest blocks. ``` +### transactionBlockTimeout +The `transactionBlockTimeout` is used over socket-based connections. This option defines the amount of new blocks it should wait until the **first confirmation** happens, otherwise the PromiEvent rejects with a timeout error. The default value is 50. + +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.transactionBlockTimeout = 60; + +console.log(web3.getContextObject().config) +``` +:::info +The `transactionBlockTimeout` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.transactionBlockTimeout = 60; + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From 040cbbb0f4065eb64e05731df61d8d729fa0fd8e Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 16:06:26 +0800 Subject: [PATCH 23/48] add doc for transactionConfirmationBlocks --- docs/docs/guides/web3_config/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index fa163630989..df3c7d837d0 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -347,6 +347,30 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### transactionConfirmationBlocks +This defines the number of blocks it requires until a transaction is considered confirmed. Different chains have varying security considerations and requirements for confirmation block numbers. The default value is 24. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.transactionConfirmationBlocks = 60; + +console.log(web3.getContextObject().config) +``` +:::info +The `transactionConfirmationBlocks` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.transactionConfirmationBlocks = 60; + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From 86dbc63dd0552a44aacf21c4d207b1b829b26a9b Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 16:11:50 +0800 Subject: [PATCH 24/48] add doc for transactionPollingInterval --- docs/docs/guides/web3_config/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index df3c7d837d0..db937c90530 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -372,6 +372,30 @@ console.log(web3.eth.getContextObject().config) ::: +### transactionPollingInterval +The `transactionPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Modifying this value can reduce the wait time for confirmations or decrease the number of network requests. Default is 1000 ms. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.transactionPollingInterval = 2000; // 2000 ms = 2 s + +console.log(web3.getContextObject().config) +``` +:::info +The `transactionPollingInterval` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.transactionPollingInterval = 2000; // 2000 ms = 2 s + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From 2f512dca96f020b9aabd0c46113ba160ef4ce432 Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 16:21:16 +0800 Subject: [PATCH 25/48] add doc for transactionPollingTimeout --- docs/docs/guides/web3_config/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index db937c90530..345a42b90df 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -396,6 +396,30 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### transactionPollingTimeout +The `transactionPollingTimeout` is used over HTTP connections. This option defines the number of seconds Web3 will wait for a receipt which confirms that a transaction was mined by the network. It can be set based on the average transaction confirmation time on the network. Note: If this method times out, the transaction may still be pending. Default is 750 seconds (12.5 minutes). +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.transactionPollingTimeout = 600000; // 600000 ms = 600 s = 10 min + +console.log(web3.getContextObject().config) +``` +:::info +The `transactionPollingTimeout` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.transactionPollingTimeout = 600000; // 600000 ms = 600 s = 10 min + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From 05a845b768a5211f8258ca72bce716f4a6a33586 Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 16:46:17 +0800 Subject: [PATCH 26/48] add doc for transactionReceiptPollingInterval and improve doc for transactionPollingInterval --- docs/docs/guides/web3_config/index.md | 45 ++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 345a42b90df..f445524b3fa 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -373,7 +373,7 @@ console.log(web3.eth.getContextObject().config) ### transactionPollingInterval -The `transactionPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Modifying this value can reduce the wait time for confirmations or decrease the number of network requests. Default is 1000 ms. +The `transactionPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Modifying this value can reduce the wait time for confirmations or decrease the number of network requests. Setting the `transactionPollingInterval` would also set `transactionReceiptPollingInterval` and `transactionConfirmationPollingInterval` to the same value. Default is 1000 ms. ```ts import { Web3 } from 'web3'; @@ -382,6 +382,15 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.transactionPollingInterval = 2000; // 2000 ms = 2 s console.log(web3.getContextObject().config) +/* ↳ + ... + transactionPollingInterval: 2000, + transactionPollingTimeout: 750000, + transactionReceiptPollingInterval: 2000, + transactionSendTimeout: 750000, + transactionConfirmationPollingInterval: 2000, + ... +*/ ``` :::info The `transactionPollingInterval` can be configured both globally and at the package level: @@ -393,6 +402,15 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.transactionPollingInterval = 2000; // 2000 ms = 2 s console.log(web3.eth.getContextObject().config) +/* ↳ + ... + transactionPollingInterval: 2000, + transactionPollingTimeout: 750000, + transactionReceiptPollingInterval: 2000, + transactionSendTimeout: 750000, + transactionConfirmationPollingInterval: 2000, + ... +*/ ``` ::: @@ -420,6 +438,31 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### transactionReceiptPollingInterval +The `transactionReceiptPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Compared to `transactionPollingInterval`, it takes higher precedence. When this value is set, it will be read first. Default is `undefined`. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.transactionReceiptPollingInterval = 2000; // 2000 ms = 2 s + +console.log(web3.getContextObject().config) +``` +:::info +The `transactionReceiptPollingInterval` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.transactionReceiptPollingInterval = undefined; + +console.log(web3.eth.getContextObject().config) +``` +::: + + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From 7d0f2f00e03232d47dad00c9abc1764199ae18c9 Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 17:00:53 +0800 Subject: [PATCH 27/48] add doc for transactionSendTimeout --- docs/docs/guides/web3_config/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index f445524b3fa..e77cc4df068 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -462,6 +462,30 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### transactionSendTimeout +The `transactionSendTimeout` is used to wait for Ethereum Node to return the sent transaction result. Note: If the RPC call stuck at the Node and therefor timed-out, the transaction may still be pending or even mined by the Network. We recommend checking the pending transactions in such a case. Default is 750 seconds (12.5 minutes). +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.transactionSendTimeout = 600000; // 600000 ms = 600 s = 10 min + +console.log(web3.getContextObject().config) +``` +:::info +The `transactionSendTimeout` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.transactionSendTimeout = 600000; // 600000 ms = 600 s = 10 min + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From aeff438fe2189e26aff500d20c8b0f67f54227ed Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 25 Jun 2024 17:20:39 +0800 Subject: [PATCH 28/48] add doc for transactionConfirmationPollingInterval --- docs/docs/guides/web3_config/index.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index e77cc4df068..cf67c68e4b9 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -18,7 +18,7 @@ There is list of configuration params that can be set for modifying behavior of - [transactionPollingTimeout](/api/web3-core/class/Web3Config#transactionPollingTimeout) - [transactionReceiptPollingInterval](/api/web3-core/class/Web3Config#transactionReceiptPollingInterval) - [transactionSendTimeout](/api/web3-core/class/Web3Config#transactionSendTimeout) -- [transactionConfirmationPollingInterval](/api/web3-core/class/Web3Config#transactionConfirmationPollingInterval) +- [Deprecated][transactionConfirmationPollingInterval](/api/web3-core/class/Web3Config#transactionConfirmationPollingInterval) - [blockHeaderTimeout](/api/web3-core/class/Web3Config#blockHeaderTimeout) - [maxListenersWarningThreshold](/api/web3-core/class/Web3Config#maxListenersWarningThreshold) - [contractDataInputFill](/api/web3-core/class/Web3Config#contractDataInputFill) @@ -486,6 +486,9 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### transactionConfirmationPollingInterval +The `transactionConfirmationPollingInterval` is deprecated. Please use `transactionReceiptPollingInterval` or `transactionPollingInterval` instead. + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From 634751e581b2f4e12af7549685a84b1df324815a Mon Sep 17 00:00:00 2001 From: myron Date: Wed, 26 Jun 2024 15:02:36 +0800 Subject: [PATCH 29/48] add doc for blockHeaderTimeout --- docs/docs/guides/web3_config/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index cf67c68e4b9..ec1ba49c17c 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -489,6 +489,30 @@ console.log(web3.eth.getContextObject().config) ### transactionConfirmationPollingInterval The `transactionConfirmationPollingInterval` is deprecated. Please use `transactionReceiptPollingInterval` or `transactionPollingInterval` instead. +### blockHeaderTimeout +The `blockHeaderTimeout` is used over socket-based connections. After sending a transaction, it will listen for the appearance of new blocks and proceed with subsequent operations based on the transaction results within them. This option defines the amount seconds it should wait for 'newBlockHeaders' event before falling back to polling to fetch transaction receipt. Default is 10 seconds. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.blockHeaderTimeout = 20; // 20 s + +console.log(web3.getContextObject().config) +``` +:::info +The `blockHeaderTimeout` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.blockHeaderTimeout = 20; // 20 s + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From 4f13cfd2d05c647552d70dc52e2cac1f9311c21a Mon Sep 17 00:00:00 2001 From: myron Date: Wed, 26 Jun 2024 15:31:38 +0800 Subject: [PATCH 30/48] add doc for maxListenersWarningThreshold --- docs/docs/guides/web3_config/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index ec1ba49c17c..bccbaf1a35b 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -513,6 +513,30 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### maxListenersWarningThreshold +The `maxListenersWarningThreshold` is used to set the `maxListeners` property in `EventEmitter`. Default is 100. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.maxListenersWarningThreshold = 200; + +console.log(web3.getContextObject().config) +``` +:::info +The `maxListenersWarningThreshold` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.maxListenersWarningThreshold = 200; + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From 1413f421249023b1f49ed0f7fc749081bb2f4d58 Mon Sep 17 00:00:00 2001 From: myron Date: Wed, 26 Jun 2024 15:48:37 +0800 Subject: [PATCH 31/48] add doc for contractDataInputFill --- docs/docs/guides/web3_config/index.md | 28 +++++++++++++++++++++++++++ packages/web3-core/src/web3_config.ts | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index bccbaf1a35b..60c74a59b60 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -537,6 +537,34 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### contractDataInputFill +The `contractDataInputFill` will allow you to set the hash of the method signature and encoded parameters to the property either `data`, `input` or `both` within your contract. This will affect the contracts send, call and estimateGas methods. Default is `data`. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.contractDataInputFill = 'input'; + +console.log(web3.getContextObject().config) +``` +:::info +The `contractDataInputFill` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.contractDataInputFill = 'both'; + +console.log(web3.eth.getContextObject().config) +``` +::: + +#### All available choices for contractDataInputFill: +```ts +contractDataInputFill: 'data' | 'input' | 'both'; +``` ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. diff --git a/packages/web3-core/src/web3_config.ts b/packages/web3-core/src/web3_config.ts index 3c335292c4a..1f84970e2b7 100644 --- a/packages/web3-core/src/web3_config.ts +++ b/packages/web3-core/src/web3_config.ts @@ -144,7 +144,7 @@ export abstract class Web3Config * The `contractDataInputFill` options property will allow you to set the hash of the method signature and encoded parameters to the property * either `data`, `input` or both within your contract. * This will affect the contracts send, call and estimateGas methods - * Default is `input`. + * Default is `data`. */ public get contractDataInputFill() { return this.config.contractDataInputFill; From 9e901a6bc394ce97ba63d382be5196652130f43d Mon Sep 17 00:00:00 2001 From: myron Date: Wed, 26 Jun 2024 16:08:21 +0800 Subject: [PATCH 32/48] add doc for defaultNetworkId --- docs/docs/guides/web3_config/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 60c74a59b60..22ec2e99244 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -566,6 +566,30 @@ console.log(web3.eth.getContextObject().config) contractDataInputFill: 'data' | 'input' | 'both'; ``` +### defaultNetworkId +Each network has its own network ID. The defaultNetwork allows you to set the default network ID to increase code readability. If this parameter is not set, it will fetch the network ID from the connected RPC request. Default is `undefined`. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultNetworkId = 56; + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultNetworkId` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultNetworkId = '0x1'; + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From 8d79edffd5f70b9dde6073fdc89140bfefb7ee53 Mon Sep 17 00:00:00 2001 From: myron Date: Wed, 26 Jun 2024 17:00:39 +0800 Subject: [PATCH 33/48] add doc for defaultHardfork, defaultChain and defaultCommon --- docs/docs/guides/web3_config/index.md | 132 ++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 22ec2e99244..efbe2bcfd8a 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -590,6 +590,138 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### defaultChain +The `defaultChain` is used for building the `baseChain` property of the tx options in a transaction. If the `defaultCommon.basechain` is set, the`defaultChain` should be consistent with it. Default is `mainnet`. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultChain = 'ropsten'; + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultChain` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultChain = 'ropsten'; + +console.log(web3.eth.getContextObject().config) +``` +::: +#### All available choices for defaultChain: +```ts +'goerli' | 'kovan' | 'mainnet' | 'rinkeby' | 'ropsten' | 'sepolia' +``` + + +### defaultHardfork +The `defaultHardfork` is used for building the `defaultHardfork` property of the tx options in a transaction. If the `defaultCommon.defaultHardfork` is set, the`defaultHardfork` should be consistent with it. Default is `london`. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultHardfork = 'berlin'; + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultHardfork` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultHardfork = 'istanbul'; + +console.log(web3.eth.getContextObject().config) +``` +::: +#### All available choices for contractDataInputFill: +```ts +'chainstart' +'frontier' +'homestead' +'dao' +'tangerineWhistle' +'spuriousDragon' +'byzantium' +'constantinople' +'petersburg' +'istanbul' +'muirGlacier' +'berlin' +'london' +'altair' +'arrowGlacier' +'grayGlacier' +'bellatrix' +'merge' +'capella' +'sharding' +``` + +### defaultCommon +The `defaultCommon` is used for building the `common` property of the tx options in a transaction. It should be consistent with the `defaultHardfork` and `defaultChain`. The `defaultCommon` property does contain the following Common object: +``` +- customChain - Object: The custom chain properties + - name - string: (optional) The name of the chain + - networkId - number: Network ID of the custom chain + - chainId - number: Chain ID of the custom chain +- baseChain - string: (optional) 'goerli', 'kovan', 'mainnet', 'rinkeby', 'ropsten' or 'sepolia' +- hardfork - string: (optional) chainstart, homestead, dao, tangerineWhistle, spuriousDragon, byzantium, constantinople, petersburg, istanbul, berlin, or london +``` + +The default value of `defaultCommon` is `undefined`. + +```ts +import { Web3, Hardfork } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultHardfork = 'berlin' +web3.defaultChain = 'goerli' + +web3.defaultCommon = { + baseChain: 'goerli', + hardfork: 'berlin' as Hardfork, + customChain: { + networkId: 1, + chainId: 1, + }, +}; + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultCommon` can be configured both globally and at the package level: +```ts +import { Web3, Hardfork } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultHardfork = 'berlin' +web3.eth.defaultChain = 'goerli' + +web3.eth.defaultCommon = { + baseChain: 'goerli', + hardfork: 'berlin' as Hardfork, + customChain: { + networkId: 1, + chainId: 1, + }, +}; + +console.log(web3.eth.getContextObject().config) +``` +::: + + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From b5c2a1dc6d8a6d7f33baa50bf694c2fd4855a767 Mon Sep 17 00:00:00 2001 From: blackmoshui Date: Wed, 26 Jun 2024 17:54:40 +0800 Subject: [PATCH 34/48] add doc for defaultTransactionType --- docs/docs/guides/web3_config/index.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index efbe2bcfd8a..2c9cdd0ef29 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -721,6 +721,29 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### defaultTransactionType +The `defaultTransactionType` is used set the transaction type. Transactions with type 0x0 are legacy transactions that use the transaction format existing before typed transactions were introduced in EIP-2718. Transactions with type 0x1 are transactions introduced in EIP-2930. Transactions with type 0x2 are transactions introduced in EIP-1559, included in Ethereum's London fork. Default is `0x02`. +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultTransactionType = 0x0; + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultTransactionType` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultTransactionType = 0x0; + +console.log(web3.eth.getContextObject().config) +``` +::: ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From ca704f5f0d98e027b7929554c7aad81a890e7a39 Mon Sep 17 00:00:00 2001 From: blackmoshui Date: Wed, 26 Jun 2024 18:05:39 +0800 Subject: [PATCH 35/48] add doc for defaultMaxPriorityFeePerGas --- docs/docs/guides/web3_config/index.md | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 2c9cdd0ef29..f1366079eab 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -26,7 +26,8 @@ There is list of configuration params that can be set for modifying behavior of - [defaultChain](/api/web3-core/class/Web3Config#defaultChain) - [defaultHardfork](/api/web3-core/class/Web3Config#defaultHardfork) - [defaultCommon](/api/web3-core/class/Web3Config#defaultCommon) -- [defaultTransactionType](/api/web3-core/class/Web3Config#defaultTransactionType) +- [defaultTransactionType](/api/web3-core/class/Web3Config#defaultTransactionType) +- [defaultMaxPriorityFeePerGas](/api/web3-core/class/Web3Config#defaultMaxPriorityFeePerGas) - [defaultReturnFormat](/api/web3-core/class/Web3Config#defaultReturnFormat) ## Global level Config @@ -745,6 +746,32 @@ console.log(web3.eth.getContextObject().config) ``` ::: +### defaultMaxPriorityFeePerGas +The `defaultMaxPriorityFeePerGas` is used to send transactions with the maximum priority gas fee. The default value is 2500000000 (2.5gwei) in hexstring format. +```ts +import { Web3 } from 'web3'; +import { numberToHex } from 'web3-utils' + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.defaultMaxPriorityFeePerGas = numberToHex(2100000000); // 2.1gwei + +console.log(web3.getContextObject().config) +``` +:::info +The `defaultMaxPriorityFeePerGas` can be configured both globally and at the package level: +```ts +import { Web3 } from 'web3'; +import { numberToHex } from 'web3-utils' + +const web3 = new Web3('http://127.0.0.1:7545'); + +web3.eth.defaultMaxPriorityFeePerGas = numberToHex(2100000000); // 2.1gwei + +console.log(web3.eth.getContextObject().config) +``` +::: + ### defaultReturnFormat The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts From 168111cc08566e56339d2aa03637f698d5f02311 Mon Sep 17 00:00:00 2001 From: myron Date: Thu, 27 Jun 2024 09:17:07 +0800 Subject: [PATCH 36/48] refine --- docs/docs/guides/web3_config/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index f1366079eab..bb6bba25cc2 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -221,7 +221,7 @@ The error types will be one of the following: - TransactionPollingTimeoutError ``` -For example, the error message could be `TransactionRevertInstructionError('Returned error: invalid argument 0: json: cannot unmarshal invalid hex string into Go struct field TransactionArgs.data of type hexutil.Bytes')`. The default value is `false`, and handleRevert is only supported for `sendTransaction` and not for `sendSignedTransaction` at this time. +For example, the error message could be `TransactionRevertInstructionError('Returned error: invalid argument 0: json: cannot unmarshal invalid hex string into Go struct field TransactionArgs.data of type hexutil.Bytes')`. The default value is `false`, and handleRevert is only supported for `sendTransaction` and not for `sendSignedTransaction` for now. ```ts import { Web3 } from 'web3'; @@ -254,7 +254,7 @@ This `defaultAccount` is used as the default `from` property, if no `from` prope - myContract.methods.myMethod().send() ``` -The default value for `defaultAccount` is `undefined`. It is worth noting that the `defaultAccount` here can be any string, as there is no validation during the config phase. +The default value for `defaultAccount` is `undefined`. ```ts import { Web3 } from 'web3'; @@ -574,7 +574,7 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.defaultNetworkId = 56; +web3.defaultNetworkId = 1; console.log(web3.getContextObject().config) ``` From dee663ac5495b2bbc775b845241c9058fbc473c9 Mon Sep 17 00:00:00 2001 From: myron Date: Thu, 18 Jul 2024 15:29:38 +0800 Subject: [PATCH 37/48] fix semi colons --- docs/docs/guides/web3_config/index.md | 104 +++++++++++++------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index bb6bba25cc2..4403e8307a1 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -205,10 +205,10 @@ console.log(web3.getContextObject().config) ### handleRevert When `handleRevert` is set to True, the following methods will retrieve specific error types and error messages: ```ts -- web3.eth.sendTransaction() -- web3.eth.call() -- myContract.methods.myMethod().call() -- myContract.methods.myMethod().send() +- web3.eth.sendTransaction(); +- web3.eth.call(); +- myContract.methods.myMethod().call(); +- myContract.methods.myMethod().send(); ``` The error types will be one of the following: @@ -230,7 +230,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.handleRevert = true; -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `handleRevert` can be configured both globally and at the package level: @@ -241,17 +241,17 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.handleRevert = true; -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: ### defaultAccount This `defaultAccount` is used as the default `from` property, if no `from` property is specified in for the following methods: ```ts -- web3.eth.sendTransaction() -- web3.eth.call() -- myContract.methods.myMethod().call() -- myContract.methods.myMethod().send() +- web3.eth.sendTransaction(); +- web3.eth.call(); +- myContract.methods.myMethod().call(); +- myContract.methods.myMethod().send(); ``` The default value for `defaultAccount` is `undefined`. @@ -263,7 +263,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.defaultAccount = "0x0000000000000000000000000000000000000000"; -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `defaultAccount` can be configured both globally and at the package level: @@ -274,19 +274,19 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.defaultAccount = "0x0000000000000000000000000000000000000000"; -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: ### defaultBlock The following methods require a `blockNumber` parameter during its execution process, the `defaultBlock` is used for these methods. ```ts -- web3.eth.getBalance() -- web3.eth.getCode() -- web3.eth.getTransactionCount() -- web3.eth.getStorageAt() -- web3.eth.call() -- myContract.methods.myMethod().call() +- web3.eth.getBalance(); +- web3.eth.getCode(); +- web3.eth.getTransactionCount(); +- web3.eth.getStorageAt(); +- web3.eth.call(); +- myContract.methods.myMethod().call(); ``` You can override it by passing in the defaultBlock as last parameter. The default value is "latest". @@ -298,7 +298,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.defaultBlock = 20167235; -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `defaultBlock` can be configured both globally and at the package level: @@ -309,7 +309,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.defaultBlock = "earliest"; -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: @@ -333,7 +333,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.transactionBlockTimeout = 60; -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `transactionBlockTimeout` can be configured both globally and at the package level: @@ -344,7 +344,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.transactionBlockTimeout = 60; -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: @@ -357,7 +357,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.transactionConfirmationBlocks = 60; -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `transactionConfirmationBlocks` can be configured both globally and at the package level: @@ -368,7 +368,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.transactionConfirmationBlocks = 60; -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: @@ -382,7 +382,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.transactionPollingInterval = 2000; // 2000 ms = 2 s -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); /* ↳ ... transactionPollingInterval: 2000, @@ -402,7 +402,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.transactionPollingInterval = 2000; // 2000 ms = 2 s -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); /* ↳ ... transactionPollingInterval: 2000, @@ -424,7 +424,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.transactionPollingTimeout = 600000; // 600000 ms = 600 s = 10 min -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `transactionPollingTimeout` can be configured both globally and at the package level: @@ -435,7 +435,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.transactionPollingTimeout = 600000; // 600000 ms = 600 s = 10 min -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: @@ -448,7 +448,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.transactionReceiptPollingInterval = 2000; // 2000 ms = 2 s -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `transactionReceiptPollingInterval` can be configured both globally and at the package level: @@ -459,7 +459,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.transactionReceiptPollingInterval = undefined; -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: @@ -472,7 +472,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.transactionSendTimeout = 600000; // 600000 ms = 600 s = 10 min -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `transactionSendTimeout` can be configured both globally and at the package level: @@ -483,7 +483,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.transactionSendTimeout = 600000; // 600000 ms = 600 s = 10 min -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: @@ -499,7 +499,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.blockHeaderTimeout = 20; // 20 s -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `blockHeaderTimeout` can be configured both globally and at the package level: @@ -510,7 +510,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.blockHeaderTimeout = 20; // 20 s -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: @@ -523,7 +523,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.maxListenersWarningThreshold = 200; -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `maxListenersWarningThreshold` can be configured both globally and at the package level: @@ -534,7 +534,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.maxListenersWarningThreshold = 200; -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: @@ -547,7 +547,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.contractDataInputFill = 'input'; -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `contractDataInputFill` can be configured both globally and at the package level: @@ -558,7 +558,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.contractDataInputFill = 'both'; -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: @@ -576,7 +576,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.defaultNetworkId = 1; -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `defaultNetworkId` can be configured both globally and at the package level: @@ -587,7 +587,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.defaultNetworkId = '0x1'; -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: @@ -600,7 +600,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.defaultChain = 'ropsten'; -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `defaultChain` can be configured both globally and at the package level: @@ -611,7 +611,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.defaultChain = 'ropsten'; -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: #### All available choices for defaultChain: @@ -629,7 +629,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.defaultHardfork = 'berlin'; -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `defaultHardfork` can be configured both globally and at the package level: @@ -640,7 +640,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.defaultHardfork = 'istanbul'; -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: #### All available choices for contractDataInputFill: @@ -697,7 +697,7 @@ web3.defaultCommon = { }, }; -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `defaultCommon` can be configured both globally and at the package level: @@ -718,7 +718,7 @@ web3.eth.defaultCommon = { }, }; -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: @@ -731,7 +731,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.defaultTransactionType = 0x0; -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `defaultTransactionType` can be configured both globally and at the package level: @@ -742,7 +742,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.defaultTransactionType = 0x0; -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: @@ -756,7 +756,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.defaultMaxPriorityFeePerGas = numberToHex(2100000000); // 2.1gwei -console.log(web3.getContextObject().config) +console.log(web3.getContextObject().config); ``` :::info The `defaultMaxPriorityFeePerGas` can be configured both globally and at the package level: @@ -768,7 +768,7 @@ const web3 = new Web3('http://127.0.0.1:7545'); web3.eth.defaultMaxPriorityFeePerGas = numberToHex(2100000000); // 2.1gwei -console.log(web3.eth.getContextObject().config) +console.log(web3.eth.getContextObject().config); ``` ::: @@ -803,12 +803,12 @@ export enum FMT_NUMBER { HEX = 'NUMBER_HEX', STR = 'NUMBER_STR', BIGINT = 'NUMBER_BIGINT', -} +}; ``` #### All available choices for bytes data: ```ts export enum FMT_BYTES { HEX = 'BYTES_HEX', UINT8ARRAY = 'BYTES_UINT8ARRAY', -} +}; ``` From 34dffabad00aba1e9e8a3cb85279e2b5e75e7dd3 Mon Sep 17 00:00:00 2001 From: myron Date: Fri, 19 Jul 2024 15:18:37 +0800 Subject: [PATCH 38/48] emphasize the default value and use the original default value in the code snippet --- docs/docs/guides/web3_config/index.md | 149 ++++++++++++++++---------- 1 file changed, 92 insertions(+), 57 deletions(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 4403e8307a1..0bd7ef96250 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -203,7 +203,7 @@ console.log(web3.getContextObject().config) ``` ### handleRevert -When `handleRevert` is set to True, the following methods will retrieve specific error types and error messages: +The following methods will retrieve specific error types and error messages when `handleRevert` is set to `true`: ```ts - web3.eth.sendTransaction(); - web3.eth.call(); @@ -221,14 +221,16 @@ The error types will be one of the following: - TransactionPollingTimeoutError ``` -For example, the error message could be `TransactionRevertInstructionError('Returned error: invalid argument 0: json: cannot unmarshal invalid hex string into Go struct field TransactionArgs.data of type hexutil.Bytes')`. The default value is `false`, and handleRevert is only supported for `sendTransaction` and not for `sendSignedTransaction` for now. +For example, the error message could be `TransactionRevertInstructionError('Returned error: invalid argument 0: json: cannot unmarshal invalid hex string into Go struct field TransactionArgs.data of type hexutil.Bytes')`. The `handleRevert` is only supported for `sendTransaction` and not for `sendSignedTransaction` for now. + +The default value of `handleRevert` is `false`. ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.handleRevert = true; +web3.handleRevert = false; console.log(web3.getContextObject().config); ``` @@ -239,7 +241,7 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.handleRevert = true; +web3.eth.handleRevert = false; console.log(web3.eth.getContextObject().config); ``` @@ -254,14 +256,14 @@ This `defaultAccount` is used as the default `from` property, if no `from` prope - myContract.methods.myMethod().send(); ``` -The default value for `defaultAccount` is `undefined`. +The default value of `defaultAccount` is `undefined`. ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.defaultAccount = "0x0000000000000000000000000000000000000000"; +web3.defaultAccount = undefined; console.log(web3.getContextObject().config); ``` @@ -272,7 +274,7 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.defaultAccount = "0x0000000000000000000000000000000000000000"; +web3.eth.defaultAccount = undefined; console.log(web3.eth.getContextObject().config); ``` @@ -289,14 +291,16 @@ The following methods require a `blockNumber` parameter during its execution pro - myContract.methods.myMethod().call(); ``` -You can override it by passing in the defaultBlock as last parameter. The default value is "latest". +You can override it by passing in the defaultBlock as last parameter. + +The default value of `defaultBlock` is "latest". ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.defaultBlock = 20167235; +web3.defaultBlock = "latest"; console.log(web3.getContextObject().config); ``` @@ -307,7 +311,7 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.defaultBlock = "earliest"; +web3.eth.defaultBlock = "latest"; console.log(web3.eth.getContextObject().config); ``` @@ -324,14 +328,16 @@ web3.defaultBlock = "safe"; // (For POS networks) The safe head block is one whi ``` ### transactionBlockTimeout -The `transactionBlockTimeout` is used over socket-based connections. This option defines the amount of new blocks it should wait until the **first confirmation** happens, otherwise the PromiEvent rejects with a timeout error. The default value is 50. +The `transactionBlockTimeout` is used over socket-based connections. This option defines the amount of new blocks it should wait until the **first confirmation** happens, otherwise the PromiEvent rejects with a timeout error. + +The default value of `transactionBlockTimeout` is 50. ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.transactionBlockTimeout = 60; +web3.transactionBlockTimeout = 50; console.log(web3.getContextObject().config); ``` @@ -342,20 +348,23 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.transactionBlockTimeout = 60; +web3.eth.transactionBlockTimeout = 50; console.log(web3.eth.getContextObject().config); ``` ::: ### transactionConfirmationBlocks -This defines the number of blocks it requires until a transaction is considered confirmed. Different chains have varying security considerations and requirements for confirmation block numbers. The default value is 24. +This defines the number of blocks it requires until a transaction is considered confirmed. Different chains have varying security considerations and requirements for confirmation block numbers. + +The default value of `transactionConfirmationBlocks` is 24. + ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.transactionConfirmationBlocks = 60; +web3.transactionConfirmationBlocks = 24; console.log(web3.getContextObject().config); ``` @@ -366,7 +375,7 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.transactionConfirmationBlocks = 60; +web3.eth.transactionConfirmationBlocks = 24; console.log(web3.eth.getContextObject().config); ``` @@ -374,22 +383,25 @@ console.log(web3.eth.getContextObject().config); ### transactionPollingInterval -The `transactionPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Modifying this value can reduce the wait time for confirmations or decrease the number of network requests. Setting the `transactionPollingInterval` would also set `transactionReceiptPollingInterval` and `transactionConfirmationPollingInterval` to the same value. Default is 1000 ms. +The `transactionPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Modifying this value can reduce the wait time for confirmations or decrease the number of network requests. Setting the `transactionPollingInterval` would also set `transactionReceiptPollingInterval` and `transactionConfirmationPollingInterval` to the same value. + +The default value of `transactionPollingInterval` is 1000 ms. + ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.transactionPollingInterval = 2000; // 2000 ms = 2 s +web3.transactionPollingInterval = 1000; // 1000 ms = 1 s console.log(web3.getContextObject().config); /* ↳ ... - transactionPollingInterval: 2000, + transactionPollingInterval: 1000, transactionPollingTimeout: 750000, - transactionReceiptPollingInterval: 2000, + transactionReceiptPollingInterval: 1000, transactionSendTimeout: 750000, - transactionConfirmationPollingInterval: 2000, + transactionConfirmationPollingInterval: 1000, ... */ ``` @@ -400,29 +412,31 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.transactionPollingInterval = 2000; // 2000 ms = 2 s +web3.eth.transactionPollingInterval = 1000; // 1000 ms = 1 s console.log(web3.eth.getContextObject().config); /* ↳ ... - transactionPollingInterval: 2000, + transactionPollingInterval: 1000, transactionPollingTimeout: 750000, - transactionReceiptPollingInterval: 2000, + transactionReceiptPollingInterval: 1000, transactionSendTimeout: 750000, - transactionConfirmationPollingInterval: 2000, + transactionConfirmationPollingInterval: 1000, ... */ ``` ::: ### transactionPollingTimeout -The `transactionPollingTimeout` is used over HTTP connections. This option defines the number of seconds Web3 will wait for a receipt which confirms that a transaction was mined by the network. It can be set based on the average transaction confirmation time on the network. Note: If this method times out, the transaction may still be pending. Default is 750 seconds (12.5 minutes). +The `transactionPollingTimeout` is used over HTTP connections. This option defines the number of seconds Web3 will wait for a receipt which confirms that a transaction was mined by the network. It can be set based on the average transaction confirmation time on the network. Note: If this method times out, the transaction may still be pending. + +The default value of `transactionPollingTimeout` is 750 seconds (12.5 minutes). ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.transactionPollingTimeout = 600000; // 600000 ms = 600 s = 10 min +web3.transactionPollingTimeout = 750000; // 750000 ms = 750 s console.log(web3.getContextObject().config); ``` @@ -433,20 +447,22 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.transactionPollingTimeout = 600000; // 600000 ms = 600 s = 10 min +web3.eth.transactionPollingTimeout = 750000; // 750000 ms = 750 s console.log(web3.eth.getContextObject().config); ``` ::: ### transactionReceiptPollingInterval -The `transactionReceiptPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Compared to `transactionPollingInterval`, it takes higher precedence. When this value is set, it will be read first. Default is `undefined`. +The `transactionReceiptPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Compared to `transactionPollingInterval`, it takes higher precedence. When this value is set, it will be read first. + +The default value of `transactionReceiptPollingInterval` is `undefined`. ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.transactionReceiptPollingInterval = 2000; // 2000 ms = 2 s +web3.transactionReceiptPollingInterval = undefined; console.log(web3.getContextObject().config); ``` @@ -464,13 +480,15 @@ console.log(web3.eth.getContextObject().config); ::: ### transactionSendTimeout -The `transactionSendTimeout` is used to wait for Ethereum Node to return the sent transaction result. Note: If the RPC call stuck at the Node and therefor timed-out, the transaction may still be pending or even mined by the Network. We recommend checking the pending transactions in such a case. Default is 750 seconds (12.5 minutes). +The `transactionSendTimeout` is used to wait for Ethereum Node to return the sent transaction result. Note: If the RPC call stuck at the Node and therefor timed-out, the transaction may still be pending or even mined by the Network. We recommend checking the pending transactions in such a case. + +The default value of `transactionSendTimeout` is 750 seconds (12.5 minutes). ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.transactionSendTimeout = 600000; // 600000 ms = 600 s = 10 min +web3.transactionSendTimeout = 750000; // 750000 ms = 750 s console.log(web3.getContextObject().config); ``` @@ -481,7 +499,7 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.transactionSendTimeout = 600000; // 600000 ms = 600 s = 10 min +web3.eth.transactionSendTimeout = 750000; // 750000 ms = 750 s console.log(web3.eth.getContextObject().config); ``` @@ -491,13 +509,16 @@ console.log(web3.eth.getContextObject().config); The `transactionConfirmationPollingInterval` is deprecated. Please use `transactionReceiptPollingInterval` or `transactionPollingInterval` instead. ### blockHeaderTimeout -The `blockHeaderTimeout` is used over socket-based connections. After sending a transaction, it will listen for the appearance of new blocks and proceed with subsequent operations based on the transaction results within them. This option defines the amount seconds it should wait for 'newBlockHeaders' event before falling back to polling to fetch transaction receipt. Default is 10 seconds. +The `blockHeaderTimeout` is used over socket-based connections. After sending a transaction, it will listen for the appearance of new blocks and proceed with subsequent operations based on the transaction results within them. This option defines the amount seconds it should wait for 'newBlockHeaders' event before falling back to polling to fetch transaction receipt. + +The default value of `blockHeaderTimeout` is 10 seconds. + ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.blockHeaderTimeout = 20; // 20 s +web3.blockHeaderTimeout = 10; // 10 s console.log(web3.getContextObject().config); ``` @@ -508,20 +529,22 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.blockHeaderTimeout = 20; // 20 s +web3.eth.blockHeaderTimeout = 10; // 10 s console.log(web3.eth.getContextObject().config); ``` ::: ### maxListenersWarningThreshold -The `maxListenersWarningThreshold` is used to set the `maxListeners` property in `EventEmitter`. Default is 100. +The `maxListenersWarningThreshold` is used to set the `maxListeners` property in `EventEmitter`. + +The default value of `maxListenersWarningThreshold` is 100. ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.maxListenersWarningThreshold = 200; +web3.maxListenersWarningThreshold = 100; console.log(web3.getContextObject().config); ``` @@ -532,20 +555,22 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.maxListenersWarningThreshold = 200; +web3.eth.maxListenersWarningThreshold = 100; console.log(web3.eth.getContextObject().config); ``` ::: ### contractDataInputFill -The `contractDataInputFill` will allow you to set the hash of the method signature and encoded parameters to the property either `data`, `input` or `both` within your contract. This will affect the contracts send, call and estimateGas methods. Default is `data`. +The `contractDataInputFill` will allow you to set the hash of the method signature and encoded parameters to the property either `data`, `input` or `both` within your contract. This will affect the contracts send, call and estimateGas methods. + +The default value of `contractDataInputFill` is `data`. ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.contractDataInputFill = 'input'; +web3.contractDataInputFill = 'data'; console.log(web3.getContextObject().config); ``` @@ -556,7 +581,7 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.contractDataInputFill = 'both'; +web3.eth.contractDataInputFill = 'data'; console.log(web3.eth.getContextObject().config); ``` @@ -568,13 +593,15 @@ contractDataInputFill: 'data' | 'input' | 'both'; ``` ### defaultNetworkId -Each network has its own network ID. The defaultNetwork allows you to set the default network ID to increase code readability. If this parameter is not set, it will fetch the network ID from the connected RPC request. Default is `undefined`. +Each network has its own network ID. The defaultNetwork allows you to set the default network ID to increase code readability. If this parameter is not set, it will fetch the network ID from the connected RPC request. + +The default value of `defaultNetworkId` is `undefined`. ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.defaultNetworkId = 1; +web3.defaultNetworkId = undefined; console.log(web3.getContextObject().config); ``` @@ -585,20 +612,22 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.defaultNetworkId = '0x1'; +web3.eth.defaultNetworkId = undefined; console.log(web3.eth.getContextObject().config); ``` ::: ### defaultChain -The `defaultChain` is used for building the `baseChain` property of the tx options in a transaction. If the `defaultCommon.basechain` is set, the`defaultChain` should be consistent with it. Default is `mainnet`. +The `defaultChain` is used for building the `baseChain` property of the tx options in a transaction. If the `defaultCommon.basechain` is set, the`defaultChain` should be consistent with it. + +The default value of `defaultChain` is `mainnet`. ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.defaultChain = 'ropsten'; +web3.defaultChain = 'mainnet'; console.log(web3.getContextObject().config); ``` @@ -609,7 +638,7 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.defaultChain = 'ropsten'; +web3.eth.defaultChain = 'mainnet'; console.log(web3.eth.getContextObject().config); ``` @@ -621,13 +650,15 @@ console.log(web3.eth.getContextObject().config); ### defaultHardfork -The `defaultHardfork` is used for building the `defaultHardfork` property of the tx options in a transaction. If the `defaultCommon.defaultHardfork` is set, the`defaultHardfork` should be consistent with it. Default is `london`. +The `defaultHardfork` is used for building the `defaultHardfork` property of the tx options in a transaction. If the `defaultCommon.defaultHardfork` is set, the`defaultHardfork` should be consistent with it. + +The default value of `defaultHardfork` is `london`. ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.defaultHardfork = 'berlin'; +web3.defaultHardfork = 'london'; console.log(web3.getContextObject().config); ``` @@ -638,7 +669,7 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.defaultHardfork = 'istanbul'; +web3.eth.defaultHardfork = 'london'; console.log(web3.eth.getContextObject().config); ``` @@ -723,13 +754,15 @@ console.log(web3.eth.getContextObject().config); ::: ### defaultTransactionType -The `defaultTransactionType` is used set the transaction type. Transactions with type 0x0 are legacy transactions that use the transaction format existing before typed transactions were introduced in EIP-2718. Transactions with type 0x1 are transactions introduced in EIP-2930. Transactions with type 0x2 are transactions introduced in EIP-1559, included in Ethereum's London fork. Default is `0x02`. +The `defaultTransactionType` is used set the transaction type. Transactions with type 0x0 are legacy transactions that use the transaction format existing before typed transactions were introduced in EIP-2718. Transactions with type 0x1 are transactions introduced in EIP-2930. Transactions with type 0x2 are transactions introduced in EIP-1559, included in Ethereum's London fork. + +The default value of `defaultTransactionType` is `0x02`. ```ts import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.defaultTransactionType = 0x0; +web3.defaultTransactionType = 0x02; console.log(web3.getContextObject().config); ``` @@ -740,21 +773,23 @@ import { Web3 } from 'web3'; const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.defaultTransactionType = 0x0; +web3.eth.defaultTransactionType = 0x02; console.log(web3.eth.getContextObject().config); ``` ::: ### defaultMaxPriorityFeePerGas -The `defaultMaxPriorityFeePerGas` is used to send transactions with the maximum priority gas fee. The default value is 2500000000 (2.5gwei) in hexstring format. +The `defaultMaxPriorityFeePerGas` is used to send transactions with the maximum priority gas fee. + +The default value of `defaultMaxPriorityFeePerGas` is 2500000000 (2.5gwei) in hexstring format. ```ts import { Web3 } from 'web3'; import { numberToHex } from 'web3-utils' const web3 = new Web3('http://127.0.0.1:7545'); -web3.defaultMaxPriorityFeePerGas = numberToHex(2100000000); // 2.1gwei +web3.defaultMaxPriorityFeePerGas = numberToHex(2500000000); // 2.5gwei console.log(web3.getContextObject().config); ``` @@ -766,7 +801,7 @@ import { numberToHex } from 'web3-utils' const web3 = new Web3('http://127.0.0.1:7545'); -web3.eth.defaultMaxPriorityFeePerGas = numberToHex(2100000000); // 2.1gwei +web3.eth.defaultMaxPriorityFeePerGas = numberToHex(2500000000); // 2.5gwei console.log(web3.eth.getContextObject().config); ``` From 5ef87375d88aad2d8b547cef5ffd18da55653c25 Mon Sep 17 00:00:00 2001 From: luu-alex <98a.lexluu@gmail.com> Date: Fri, 19 Jul 2024 15:58:26 -0400 Subject: [PATCH 39/48] run deploy --- packages/web3/test/e2e/fixtures/sepolia.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/web3/test/e2e/fixtures/sepolia.ts b/packages/web3/test/e2e/fixtures/sepolia.ts index 9ab06b665db..dbbfdb56bbb 100644 --- a/packages/web3/test/e2e/fixtures/sepolia.ts +++ b/packages/web3/test/e2e/fixtures/sepolia.ts @@ -640,6 +640,7 @@ export const sepoliaBlockHydrated = { uncles: [], }; + export const sepoliaBlock = { difficulty: '0x0', extraData: '0x496c6c756d696e61746520446d6f63726174697a6520447374726962757465', From ed4d040b7a207346927bc0f868a17e4f295f2aa2 Mon Sep 17 00:00:00 2001 From: luu-alex <98a.lexluu@gmail.com> Date: Fri, 19 Jul 2024 16:10:47 -0400 Subject: [PATCH 40/48] revert --- packages/web3/test/e2e/fixtures/sepolia.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/web3/test/e2e/fixtures/sepolia.ts b/packages/web3/test/e2e/fixtures/sepolia.ts index dbbfdb56bbb..9ab06b665db 100644 --- a/packages/web3/test/e2e/fixtures/sepolia.ts +++ b/packages/web3/test/e2e/fixtures/sepolia.ts @@ -640,7 +640,6 @@ export const sepoliaBlockHydrated = { uncles: [], }; - export const sepoliaBlock = { difficulty: '0x0', extraData: '0x496c6c756d696e61746520446d6f63726174697a6520447374726962757465', From ac08d706dbcd3e33fc1da980c0a1cabe515cec42 Mon Sep 17 00:00:00 2001 From: myron Date: Mon, 22 Jul 2024 11:35:22 +0800 Subject: [PATCH 41/48] add link, fix pr comments --- docs/docs/guides/web3_config/index.md | 177 +++++++++++++------------- 1 file changed, 85 insertions(+), 92 deletions(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 0bd7ef96250..65868ae6db2 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -9,26 +9,26 @@ sidebar_label: 'Web3 Config Guide' There is list of configuration params that can be set for modifying behavior of different functions in web3.js packages. Following is list of configuration options with details: -- [handleRevert](/api/web3-core/class/Web3Config#handleRevert) -- [defaultAccount](/api/web3-core/class/Web3Config#defaultAccount) -- [defaultBlock](/api/web3-core/class/Web3Config#defaultBlock) -- [transactionBlockTimeout](/api/web3-core/class/Web3Config#transactionBlockTimeout) -- [transactionConfirmationBlocks](/api/web3-core/class/Web3Config#transactionConfirmationBlocks) -- [transactionPollingInterval](/api/web3-core/class/Web3Config#transactionPollingInterval) -- [transactionPollingTimeout](/api/web3-core/class/Web3Config#transactionPollingTimeout) -- [transactionReceiptPollingInterval](/api/web3-core/class/Web3Config#transactionReceiptPollingInterval) -- [transactionSendTimeout](/api/web3-core/class/Web3Config#transactionSendTimeout) -- [Deprecated][transactionConfirmationPollingInterval](/api/web3-core/class/Web3Config#transactionConfirmationPollingInterval) -- [blockHeaderTimeout](/api/web3-core/class/Web3Config#blockHeaderTimeout) -- [maxListenersWarningThreshold](/api/web3-core/class/Web3Config#maxListenersWarningThreshold) -- [contractDataInputFill](/api/web3-core/class/Web3Config#contractDataInputFill) -- [defaultNetworkId](/api/web3-core/class/Web3Config#defaultNetworkId) -- [defaultChain](/api/web3-core/class/Web3Config#defaultChain) -- [defaultHardfork](/api/web3-core/class/Web3Config#defaultHardfork) -- [defaultCommon](/api/web3-core/class/Web3Config#defaultCommon) -- [defaultTransactionType](/api/web3-core/class/Web3Config#defaultTransactionType) -- [defaultMaxPriorityFeePerGas](/api/web3-core/class/Web3Config#defaultMaxPriorityFeePerGas) -- [defaultReturnFormat](/api/web3-core/class/Web3Config#defaultReturnFormat) +- [handleRevert](/guides/web3_config/#handlerevert) +- [defaultAccount](/guides/web3_config/#defaultaccount) +- [defaultBlock](/guides/web3_config/#defaultblock) +- [transactionBlockTimeout](/guides/web3_config/#transactionblocktimeout) +- [transactionConfirmationBlocks](/guides/web3_config/#transactionconfirmationblocks) +- [transactionPollingInterval](/guides/web3_config/#transactionpollinginterval) +- [transactionPollingTimeout](/guides/web3_config/#transactionpollingtimeout) +- [transactionReceiptPollingInterval](/guides/web3_config/#transactionreceiptpollinginterval) +- [transactionSendTimeout](/guides/web3_config/#transactionsendtimeout) +- [[Deprecated] transactionConfirmationPollingInterval](/guides/web3_config/#transactionconfirmationpollinginterval) +- [blockHeaderTimeout](/guides/web3_config/#blockheadertimeout) +- [maxListenersWarningThreshold](/guides/web3_config/#maxlistenerswarningthreshold) +- [contractDataInputFill](/guides/web3_config/#contractdatainputfill) +- [defaultNetworkId](/guides/web3_config/#defaultnetworkid) +- [defaultChain](/guides/web3_config/#defaultchain) +- [defaultHardfork](/guides/web3_config/#defaulthardfork) +- [defaultCommon](/guides/web3_config/#defaultcommon) +- [defaultTransactionType](/guides/web3_config/#defaulttransactiontype) +- [defaultMaxPriorityFeePerGas](/guides/web3_config/#defaultmaxpriorityfeepergas) +- [defaultReturnFormat](/guides/web3_config/#defaultreturnformat) ## Global level Config @@ -202,26 +202,24 @@ console.log(web3.getContextObject().config) */ ``` -### handleRevert +## Explanation of Configuration Parameters + +### [handleRevert](/api/web3-core/class/Web3Config#handleRevert) The following methods will retrieve specific error types and error messages when `handleRevert` is set to `true`: -```ts -- web3.eth.sendTransaction(); -- web3.eth.call(); -- myContract.methods.myMethod().call(); -- myContract.methods.myMethod().send(); -``` +- [`web3.eth.sendTransaction()`](/api/web3-eth/function/sendTransaction); +- [`web3.eth.call()`](/api/web3-eth/function/call); +- [`myContract.methods.myMethod().call()`](/libdocs/Contract#call); +- [`myContract.methods.myMethod().send()`](/libdocs/Contract#send); The error types will be one of the following: -```ts -- InvalidResponseError -- ContractExecutionError -- TransactionRevertWithCustomError -- TransactionRevertedWithoutReasonError -- TransactionRevertInstructionError -- TransactionPollingTimeoutError -``` +- [InvalidResponseError](/api/web3-errors/class/InvalidResponseError) +- [ContractExecutionError](/api/web3-errors/class/ContractExecutionError) +- [TransactionRevertWithCustomError](/api/web3-errors/class/TransactionRevertWithCustomError) +- [TransactionRevertedWithoutReasonError](/api/web3-errors/class/TransactionRevertedWithoutReasonError) +- [TransactionRevertInstructionError](/api/web3-errors/class/TransactionRevertInstructionError) +- [TransactionPollingTimeoutError](/api/web3-errors/class/TransactionPollingTimeoutError) -For example, the error message could be `TransactionRevertInstructionError('Returned error: invalid argument 0: json: cannot unmarshal invalid hex string into Go struct field TransactionArgs.data of type hexutil.Bytes')`. The `handleRevert` is only supported for `sendTransaction` and not for `sendSignedTransaction` for now. +For example, the error message could be `TransactionRevertInstructionError('Returned error: invalid argument 0: json: cannot unmarshal invalid hex string into Go struct field TransactionArgs.data of type hexutil.Bytes')`. The `handleRevert` is only supported for [`sendTransaction`](/api/web3-eth/function/sendTransaction) and not for [`sendSignedTransaction`](/api/web3-eth/function/sendSignedTransaction) for now. The default value of `handleRevert` is `false`. @@ -247,14 +245,12 @@ console.log(web3.eth.getContextObject().config); ``` ::: -### defaultAccount +### [defaultAccount](/api/web3-core/class/Web3Config#defaultAccount) This `defaultAccount` is used as the default `from` property, if no `from` property is specified in for the following methods: -```ts -- web3.eth.sendTransaction(); -- web3.eth.call(); -- myContract.methods.myMethod().call(); -- myContract.methods.myMethod().send(); -``` +- [`web3.eth.sendTransaction()`](/api/web3-eth/function/sendTransaction); +- [`web3.eth.call()`](/api/web3-eth/function/call); +- [`myContract.methods.myMethod().call()`](/libdocs/Contract#call); +- [`myContract.methods.myMethod().send()`](/libdocs/Contract#send); The default value of `defaultAccount` is `undefined`. @@ -280,16 +276,14 @@ console.log(web3.eth.getContextObject().config); ``` ::: -### defaultBlock +### [defaultBlock](/api/web3-core/class/Web3Config#defaultBlock) The following methods require a `blockNumber` parameter during its execution process, the `defaultBlock` is used for these methods. -```ts -- web3.eth.getBalance(); -- web3.eth.getCode(); -- web3.eth.getTransactionCount(); -- web3.eth.getStorageAt(); -- web3.eth.call(); -- myContract.methods.myMethod().call(); -``` +- [`web3.eth.getBalance()`](/api/web3-eth/function/getBalance); +- [`web3.eth.getCode()`](/api/web3-eth/function/getCode); +- [`web3.eth.getTransactionCount()`](/api/web3-eth/function/getTransactionCount); +- [`web3.eth.getStorageAt()`](/api/web3-eth/function/getStorageAt); +- [`web3.eth.call()`](/api/web3-eth/function/call); +- [`myContract.methods.myMethod().call()`](/libdocs/Contract#call); You can override it by passing in the defaultBlock as last parameter. @@ -327,8 +321,8 @@ web3.defaultBlock = "finalized"; // (For POS networks) The finalized block is on web3.defaultBlock = "safe"; // (For POS networks) The safe head block is one which under normal network conditions, is expected to be included in the canonical chain. Under normal network conditions the safe head and the actual tip of the chain will be equivalent (with safe head trailing only by a few seconds). Safe heads will be less likely to be reorged than the proof of work network`s latest blocks. ``` -### transactionBlockTimeout -The `transactionBlockTimeout` is used over socket-based connections. This option defines the amount of new blocks it should wait until the **first confirmation** happens, otherwise the PromiEvent rejects with a timeout error. +### [transactionBlockTimeout](/api/web3-core/class/Web3Config#transactionBlockTimeout) +The `transactionBlockTimeout` is used over socket-based connections. This option defines the number of new blocks to wait for the **first confirmation**, otherwise the PromiEvent rejects with a timeout error. The default value of `transactionBlockTimeout` is 50. @@ -354,8 +348,8 @@ console.log(web3.eth.getContextObject().config); ``` ::: -### transactionConfirmationBlocks -This defines the number of blocks it requires until a transaction is considered confirmed. Different chains have varying security considerations and requirements for confirmation block numbers. +### [transactionConfirmationBlocks](/api/web3-core/class/Web3Config#transactionConfirmationBlocks) +This defines the number of blocks required for a transaction to be considered confirmed. Different chains have varying security considerations and requirements for confirmation block numbers. The default value of `transactionConfirmationBlocks` is 24. @@ -382,8 +376,8 @@ console.log(web3.eth.getContextObject().config); ::: -### transactionPollingInterval -The `transactionPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Modifying this value can reduce the wait time for confirmations or decrease the number of network requests. Setting the `transactionPollingInterval` would also set `transactionReceiptPollingInterval` and `transactionConfirmationPollingInterval` to the same value. +### [transactionPollingInterval](/api/web3-core/class/Web3Config#transactionPollingInterval) +The `transactionPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Modifying this value can reduce the wait time for confirmations or decrease the number of network requests. Setting the `transactionPollingInterval` would also set [`transactionReceiptPollingInterval`](/guides/web3_config/#transactionreceiptpollinginterval) and [`transactionConfirmationPollingInterval`](/guides/web3_config/#transactionconfirmationpollinginterval) to the same value. The default value of `transactionPollingInterval` is 1000 ms. @@ -427,8 +421,8 @@ console.log(web3.eth.getContextObject().config); ``` ::: -### transactionPollingTimeout -The `transactionPollingTimeout` is used over HTTP connections. This option defines the number of seconds Web3 will wait for a receipt which confirms that a transaction was mined by the network. It can be set based on the average transaction confirmation time on the network. Note: If this method times out, the transaction may still be pending. +### [transactionPollingTimeout](/api/web3-core/class/Web3Config#transactionPollingTimeout) +The `transactionPollingTimeout` is used over HTTP connections. This option defines the number of seconds Web3 will wait for a receipt which confirms that a transaction was mined by the network. It can be set based on the average transaction confirmation time on the network. Note: If the `transactionPollingTimeout` is exceeded, the transaction may still be pending. The default value of `transactionPollingTimeout` is 750 seconds (12.5 minutes). ```ts @@ -453,8 +447,8 @@ console.log(web3.eth.getContextObject().config); ``` ::: -### transactionReceiptPollingInterval -The `transactionReceiptPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Compared to `transactionPollingInterval`, it takes higher precedence. When this value is set, it will be read first. +### [transactionReceiptPollingInterval](/api/web3-core/class/Web3Config#transactionReceiptPollingInterval) +The `transactionReceiptPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Compared to [`transactionPollingInterval`](/guides/web3_config/#transactionpollinginterval), it takes higher precedence. When this value is set, it will be read first. The default value of `transactionReceiptPollingInterval` is `undefined`. ```ts @@ -479,8 +473,8 @@ console.log(web3.eth.getContextObject().config); ``` ::: -### transactionSendTimeout -The `transactionSendTimeout` is used to wait for Ethereum Node to return the sent transaction result. Note: If the RPC call stuck at the Node and therefor timed-out, the transaction may still be pending or even mined by the Network. We recommend checking the pending transactions in such a case. +### [transactionSendTimeout](/api/web3-core/class/Web3Config#transactionSendTimeout) +The `transactionSendTimeout` option is used to specify how long to wait for the network to return the sent transaction result. Note: If the RPC call times out, the transaction may still be pending or even mined by the network. We recommend checking the pending transactions in such a case. The default value of `transactionSendTimeout` is 750 seconds (12.5 minutes). ```ts @@ -505,10 +499,10 @@ console.log(web3.eth.getContextObject().config); ``` ::: -### transactionConfirmationPollingInterval -The `transactionConfirmationPollingInterval` is deprecated. Please use `transactionReceiptPollingInterval` or `transactionPollingInterval` instead. +### [transactionConfirmationPollingInterval](/api/web3-core/class/Web3Config#transactionConfirmationPollingInterval) +The `transactionConfirmationPollingInterval` option is deprecated. Please use [`transactionReceiptPollingInterval`](/guides/web3_config/#transactionreceiptpollinginterval) or [`transactionPollingInterval`](/guides/web3_config/#transactionpollinginterval) instead. -### blockHeaderTimeout +### [blockHeaderTimeout](/api/web3-core/class/Web3Config#blockHeaderTimeout) The `blockHeaderTimeout` is used over socket-based connections. After sending a transaction, it will listen for the appearance of new blocks and proceed with subsequent operations based on the transaction results within them. This option defines the amount seconds it should wait for 'newBlockHeaders' event before falling back to polling to fetch transaction receipt. The default value of `blockHeaderTimeout` is 10 seconds. @@ -535,7 +529,7 @@ console.log(web3.eth.getContextObject().config); ``` ::: -### maxListenersWarningThreshold +### [maxListenersWarningThreshold](/api/web3-core/class/Web3Config#maxListenersWarningThreshold) The `maxListenersWarningThreshold` is used to set the `maxListeners` property in `EventEmitter`. The default value of `maxListenersWarningThreshold` is 100. @@ -561,8 +555,8 @@ console.log(web3.eth.getContextObject().config); ``` ::: -### contractDataInputFill -The `contractDataInputFill` will allow you to set the hash of the method signature and encoded parameters to the property either `data`, `input` or `both` within your contract. This will affect the contracts send, call and estimateGas methods. +### [contractDataInputFill](/api/web3-core/class/Web3Config#contractDataInputFill) +The `contractDataInputFill` will allow you to set the hash of the method signature and encoded parameters to the property either `data`, `input` or `both` within your contract. This will affect the contracts [`send`](/libdocs/Contract#send), [`call`](/libdocs/Contract#call) and [`estimateGas`](/libdocs/Contract#estimategas) methods. The default value of `contractDataInputFill` is `data`. ```ts @@ -589,10 +583,12 @@ console.log(web3.eth.getContextObject().config); #### All available choices for contractDataInputFill: ```ts -contractDataInputFill: 'data' | 'input' | 'both'; +'data' +'input' +'both' ``` -### defaultNetworkId +### [defaultNetworkId](/api/web3-core/class/Web3Config#defaultNetworkId) Each network has its own network ID. The defaultNetwork allows you to set the default network ID to increase code readability. If this parameter is not set, it will fetch the network ID from the connected RPC request. The default value of `defaultNetworkId` is `undefined`. @@ -618,8 +614,8 @@ console.log(web3.eth.getContextObject().config); ``` ::: -### defaultChain -The `defaultChain` is used for building the `baseChain` property of the tx options in a transaction. If the `defaultCommon.basechain` is set, the`defaultChain` should be consistent with it. +### [defaultChain](/api/web3-core/class/Web3Config#defaultChain) +The `defaultChain` is used for building the [`baseChain`](/api/web3-types/interface/Common#baseChain) property of the tx options in a transaction. If the `defaultCommon.basechain` is set, the `defaultChain` should be consistent with it. The default value of `defaultChain` is `mainnet`. ```ts @@ -645,12 +641,17 @@ console.log(web3.eth.getContextObject().config); ::: #### All available choices for defaultChain: ```ts -'goerli' | 'kovan' | 'mainnet' | 'rinkeby' | 'ropsten' | 'sepolia' +'goerli' +'kovan' +'mainnet' +'rinkeby' +'ropsten' +'sepolia' ``` -### defaultHardfork -The `defaultHardfork` is used for building the `defaultHardfork` property of the tx options in a transaction. If the `defaultCommon.defaultHardfork` is set, the`defaultHardfork` should be consistent with it. +### [defaultHardfork](/api/web3-core/class/Web3Config#defaultHardfork) +The `defaultHardfork` is used for building the `defaultHardfork` property of the tx options in a transaction. If the `defaultCommon.defaultHardfork` is set, the `defaultHardfork` should be consistent with it. The default value of `defaultHardfork` is `london`. ```ts @@ -674,7 +675,7 @@ web3.eth.defaultHardfork = 'london'; console.log(web3.eth.getContextObject().config); ``` ::: -#### All available choices for contractDataInputFill: +#### All available choices for defaultHardFork: ```ts 'chainstart' 'frontier' @@ -698,16 +699,8 @@ console.log(web3.eth.getContextObject().config); 'sharding' ``` -### defaultCommon -The `defaultCommon` is used for building the `common` property of the tx options in a transaction. It should be consistent with the `defaultHardfork` and `defaultChain`. The `defaultCommon` property does contain the following Common object: -``` -- customChain - Object: The custom chain properties - - name - string: (optional) The name of the chain - - networkId - number: Network ID of the custom chain - - chainId - number: Chain ID of the custom chain -- baseChain - string: (optional) 'goerli', 'kovan', 'mainnet', 'rinkeby', 'ropsten' or 'sepolia' -- hardfork - string: (optional) chainstart, homestead, dao, tangerineWhistle, spuriousDragon, byzantium, constantinople, petersburg, istanbul, berlin, or london -``` +### [defaultCommon](/api/web3-core/class/Web3Config#defaultCommon) +The `defaultCommon` is used for building the `common` property of the tx options in a transaction. It should be consistent with the [`defaultHardfork`](/guides/web3_config/#defaulthardfork) and [`defaultChain`](/guides/web3_config/#defaultchain). Please check the `defaultCommon` property [here](/libdocs/Contract/#defaultcommon) The default value of `defaultCommon` is `undefined`. @@ -753,8 +746,8 @@ console.log(web3.eth.getContextObject().config); ``` ::: -### defaultTransactionType -The `defaultTransactionType` is used set the transaction type. Transactions with type 0x0 are legacy transactions that use the transaction format existing before typed transactions were introduced in EIP-2718. Transactions with type 0x1 are transactions introduced in EIP-2930. Transactions with type 0x2 are transactions introduced in EIP-1559, included in Ethereum's London fork. +### [defaultTransactionType](/api/web3-core/class/Web3Config#defaultTransactionType) +The `defaultTransactionType` is used set the transaction type. Transactions with type 0x0 are legacy transactions that use the transaction format existing before typed transactions were introduced in [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718). Transactions with type 0x1 are transactions introduced in [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930). Transactions with type 0x2 are transactions introduced in [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559), included in Ethereum's London fork. The default value of `defaultTransactionType` is `0x02`. ```ts @@ -779,7 +772,7 @@ console.log(web3.eth.getContextObject().config); ``` ::: -### defaultMaxPriorityFeePerGas +### [defaultMaxPriorityFeePerGas](/api/web3-core/class/Web3Config#defaultMaxPriorityFeePerGas) The `defaultMaxPriorityFeePerGas` is used to send transactions with the maximum priority gas fee. The default value of `defaultMaxPriorityFeePerGas` is 2500000000 (2.5gwei) in hexstring format. @@ -807,7 +800,7 @@ console.log(web3.eth.getContextObject().config); ``` ::: -### defaultReturnFormat +### [defaultReturnFormat](/api/web3-core/class/Web3Config#defaultReturnFormat) The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts import { Web3, FMT_NUMBER, FMT_BYTES } from 'web3'; From 1b98de76860a305dce9713710c4d36a6d514053e Mon Sep 17 00:00:00 2001 From: myron Date: Mon, 22 Jul 2024 11:42:19 +0800 Subject: [PATCH 42/48] remove redundant global config example --- docs/docs/guides/web3_config/index.md | 247 -------------------------- 1 file changed, 247 deletions(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 65868ae6db2..938b959a8ea 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -232,18 +232,6 @@ web3.handleRevert = false; console.log(web3.getContextObject().config); ``` -:::info -The `handleRevert` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.handleRevert = false; - -console.log(web3.eth.getContextObject().config); -``` -::: ### [defaultAccount](/api/web3-core/class/Web3Config#defaultAccount) This `defaultAccount` is used as the default `from` property, if no `from` property is specified in for the following methods: @@ -263,18 +251,6 @@ web3.defaultAccount = undefined; console.log(web3.getContextObject().config); ``` -:::info -The `defaultAccount` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.defaultAccount = undefined; - -console.log(web3.eth.getContextObject().config); -``` -::: ### [defaultBlock](/api/web3-core/class/Web3Config#defaultBlock) The following methods require a `blockNumber` parameter during its execution process, the `defaultBlock` is used for these methods. @@ -298,18 +274,6 @@ web3.defaultBlock = "latest"; console.log(web3.getContextObject().config); ``` -:::info -The `defaultBlock` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.defaultBlock = "latest"; - -console.log(web3.eth.getContextObject().config); -``` -::: #### All available choices for defaultBlock: ```ts @@ -335,18 +299,6 @@ web3.transactionBlockTimeout = 50; console.log(web3.getContextObject().config); ``` -:::info -The `transactionBlockTimeout` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.transactionBlockTimeout = 50; - -console.log(web3.eth.getContextObject().config); -``` -::: ### [transactionConfirmationBlocks](/api/web3-core/class/Web3Config#transactionConfirmationBlocks) This defines the number of blocks required for a transaction to be considered confirmed. Different chains have varying security considerations and requirements for confirmation block numbers. @@ -362,19 +314,6 @@ web3.transactionConfirmationBlocks = 24; console.log(web3.getContextObject().config); ``` -:::info -The `transactionConfirmationBlocks` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.transactionConfirmationBlocks = 24; - -console.log(web3.eth.getContextObject().config); -``` -::: - ### [transactionPollingInterval](/api/web3-core/class/Web3Config#transactionPollingInterval) The `transactionPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Modifying this value can reduce the wait time for confirmations or decrease the number of network requests. Setting the `transactionPollingInterval` would also set [`transactionReceiptPollingInterval`](/guides/web3_config/#transactionreceiptpollinginterval) and [`transactionConfirmationPollingInterval`](/guides/web3_config/#transactionconfirmationpollinginterval) to the same value. @@ -399,27 +338,6 @@ console.log(web3.getContextObject().config); ... */ ``` -:::info -The `transactionPollingInterval` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.transactionPollingInterval = 1000; // 1000 ms = 1 s - -console.log(web3.eth.getContextObject().config); -/* ↳ - ... - transactionPollingInterval: 1000, - transactionPollingTimeout: 750000, - transactionReceiptPollingInterval: 1000, - transactionSendTimeout: 750000, - transactionConfirmationPollingInterval: 1000, - ... -*/ -``` -::: ### [transactionPollingTimeout](/api/web3-core/class/Web3Config#transactionPollingTimeout) The `transactionPollingTimeout` is used over HTTP connections. This option defines the number of seconds Web3 will wait for a receipt which confirms that a transaction was mined by the network. It can be set based on the average transaction confirmation time on the network. Note: If the `transactionPollingTimeout` is exceeded, the transaction may still be pending. @@ -434,18 +352,6 @@ web3.transactionPollingTimeout = 750000; // 750000 ms = 750 s console.log(web3.getContextObject().config); ``` -:::info -The `transactionPollingTimeout` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.transactionPollingTimeout = 750000; // 750000 ms = 750 s - -console.log(web3.eth.getContextObject().config); -``` -::: ### [transactionReceiptPollingInterval](/api/web3-core/class/Web3Config#transactionReceiptPollingInterval) The `transactionReceiptPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Compared to [`transactionPollingInterval`](/guides/web3_config/#transactionpollinginterval), it takes higher precedence. When this value is set, it will be read first. @@ -460,18 +366,6 @@ web3.transactionReceiptPollingInterval = undefined; console.log(web3.getContextObject().config); ``` -:::info -The `transactionReceiptPollingInterval` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.transactionReceiptPollingInterval = undefined; - -console.log(web3.eth.getContextObject().config); -``` -::: ### [transactionSendTimeout](/api/web3-core/class/Web3Config#transactionSendTimeout) The `transactionSendTimeout` option is used to specify how long to wait for the network to return the sent transaction result. Note: If the RPC call times out, the transaction may still be pending or even mined by the network. We recommend checking the pending transactions in such a case. @@ -486,18 +380,6 @@ web3.transactionSendTimeout = 750000; // 750000 ms = 750 s console.log(web3.getContextObject().config); ``` -:::info -The `transactionSendTimeout` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.transactionSendTimeout = 750000; // 750000 ms = 750 s - -console.log(web3.eth.getContextObject().config); -``` -::: ### [transactionConfirmationPollingInterval](/api/web3-core/class/Web3Config#transactionConfirmationPollingInterval) The `transactionConfirmationPollingInterval` option is deprecated. Please use [`transactionReceiptPollingInterval`](/guides/web3_config/#transactionreceiptpollinginterval) or [`transactionPollingInterval`](/guides/web3_config/#transactionpollinginterval) instead. @@ -516,18 +398,6 @@ web3.blockHeaderTimeout = 10; // 10 s console.log(web3.getContextObject().config); ``` -:::info -The `blockHeaderTimeout` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.blockHeaderTimeout = 10; // 10 s - -console.log(web3.eth.getContextObject().config); -``` -::: ### [maxListenersWarningThreshold](/api/web3-core/class/Web3Config#maxListenersWarningThreshold) The `maxListenersWarningThreshold` is used to set the `maxListeners` property in `EventEmitter`. @@ -542,18 +412,6 @@ web3.maxListenersWarningThreshold = 100; console.log(web3.getContextObject().config); ``` -:::info -The `maxListenersWarningThreshold` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.maxListenersWarningThreshold = 100; - -console.log(web3.eth.getContextObject().config); -``` -::: ### [contractDataInputFill](/api/web3-core/class/Web3Config#contractDataInputFill) The `contractDataInputFill` will allow you to set the hash of the method signature and encoded parameters to the property either `data`, `input` or `both` within your contract. This will affect the contracts [`send`](/libdocs/Contract#send), [`call`](/libdocs/Contract#call) and [`estimateGas`](/libdocs/Contract#estimategas) methods. @@ -568,18 +426,6 @@ web3.contractDataInputFill = 'data'; console.log(web3.getContextObject().config); ``` -:::info -The `contractDataInputFill` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.contractDataInputFill = 'data'; - -console.log(web3.eth.getContextObject().config); -``` -::: #### All available choices for contractDataInputFill: ```ts @@ -601,18 +447,6 @@ web3.defaultNetworkId = undefined; console.log(web3.getContextObject().config); ``` -:::info -The `defaultNetworkId` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.defaultNetworkId = undefined; - -console.log(web3.eth.getContextObject().config); -``` -::: ### [defaultChain](/api/web3-core/class/Web3Config#defaultChain) The `defaultChain` is used for building the [`baseChain`](/api/web3-types/interface/Common#baseChain) property of the tx options in a transaction. If the `defaultCommon.basechain` is set, the `defaultChain` should be consistent with it. @@ -627,18 +461,7 @@ web3.defaultChain = 'mainnet'; console.log(web3.getContextObject().config); ``` -:::info -The `defaultChain` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.defaultChain = 'mainnet'; - -console.log(web3.eth.getContextObject().config); -``` -::: #### All available choices for defaultChain: ```ts 'goerli' @@ -663,18 +486,7 @@ web3.defaultHardfork = 'london'; console.log(web3.getContextObject().config); ``` -:::info -The `defaultHardfork` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.defaultHardfork = 'london'; -console.log(web3.eth.getContextObject().config); -``` -::: #### All available choices for defaultHardFork: ```ts 'chainstart' @@ -723,28 +535,6 @@ web3.defaultCommon = { console.log(web3.getContextObject().config); ``` -:::info -The `defaultCommon` can be configured both globally and at the package level: -```ts -import { Web3, Hardfork } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.defaultHardfork = 'berlin' -web3.eth.defaultChain = 'goerli' - -web3.eth.defaultCommon = { - baseChain: 'goerli', - hardfork: 'berlin' as Hardfork, - customChain: { - networkId: 1, - chainId: 1, - }, -}; - -console.log(web3.eth.getContextObject().config); -``` -::: ### [defaultTransactionType](/api/web3-core/class/Web3Config#defaultTransactionType) The `defaultTransactionType` is used set the transaction type. Transactions with type 0x0 are legacy transactions that use the transaction format existing before typed transactions were introduced in [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718). Transactions with type 0x1 are transactions introduced in [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930). Transactions with type 0x2 are transactions introduced in [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559), included in Ethereum's London fork. @@ -759,18 +549,6 @@ web3.defaultTransactionType = 0x02; console.log(web3.getContextObject().config); ``` -:::info -The `defaultTransactionType` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.defaultTransactionType = 0x02; - -console.log(web3.eth.getContextObject().config); -``` -::: ### [defaultMaxPriorityFeePerGas](/api/web3-core/class/Web3Config#defaultMaxPriorityFeePerGas) The `defaultMaxPriorityFeePerGas` is used to send transactions with the maximum priority gas fee. @@ -786,19 +564,6 @@ web3.defaultMaxPriorityFeePerGas = numberToHex(2500000000); // 2.5gwei console.log(web3.getContextObject().config); ``` -:::info -The `defaultMaxPriorityFeePerGas` can be configured both globally and at the package level: -```ts -import { Web3 } from 'web3'; -import { numberToHex } from 'web3-utils' - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.eth.defaultMaxPriorityFeePerGas = numberToHex(2500000000); // 2.5gwei - -console.log(web3.eth.getContextObject().config); -``` -::: ### [defaultReturnFormat](/api/web3-core/class/Web3Config#defaultReturnFormat) The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. @@ -811,19 +576,7 @@ web3.defaultReturnFormat = { }; ``` -:::info -The `defaultReturnFormat` can be configured both globally and at the package level: -```ts -import { Web3Eth, FMT_NUMBER, FMT_BYTES } from 'web3-eth'; -const eth = new Web3Eth() -eth.defaultReturnFormat = { - number: FMT_NUMBER.BIGINT, - bytes: FMT_BYTES.HEX, -}; - -``` -::: #### All available choices for numeric data: ```ts export enum FMT_NUMBER { From 632a75069abb40c7b4eff80855a656da5504a190 Mon Sep 17 00:00:00 2001 From: Myron <49134743+mmyyrroonn@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:13:27 +0800 Subject: [PATCH 43/48] Apply suggestions from code review Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com> --- docs/docs/guides/web3_config/index.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 938b959a8ea..4a771f352b4 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -207,8 +207,6 @@ console.log(web3.getContextObject().config) ### [handleRevert](/api/web3-core/class/Web3Config#handleRevert) The following methods will retrieve specific error types and error messages when `handleRevert` is set to `true`: - [`web3.eth.sendTransaction()`](/api/web3-eth/function/sendTransaction); -- [`web3.eth.call()`](/api/web3-eth/function/call); -- [`myContract.methods.myMethod().call()`](/libdocs/Contract#call); - [`myContract.methods.myMethod().send()`](/libdocs/Contract#send); The error types will be one of the following: @@ -280,13 +278,13 @@ console.log(web3.getContextObject().config); web3.defaultBlock = 20167235; // A block number web3.defaultBlock = "earliest"; // The genesis block web3.defaultBlock = "latest"; // The latest block (current head of the blockchain) -web3.defaultBlock = "pending"; // The currently mined block (including pending transactions) +web3.defaultBlock = "pending"; // The block pending to be mined (including pending transactions) web3.defaultBlock = "finalized"; // (For POS networks) The finalized block is one which has been accepted as canonical by greater than 2/3 of validators web3.defaultBlock = "safe"; // (For POS networks) The safe head block is one which under normal network conditions, is expected to be included in the canonical chain. Under normal network conditions the safe head and the actual tip of the chain will be equivalent (with safe head trailing only by a few seconds). Safe heads will be less likely to be reorged than the proof of work network`s latest blocks. ``` ### [transactionBlockTimeout](/api/web3-core/class/Web3Config#transactionBlockTimeout) -The `transactionBlockTimeout` is used over socket-based connections. This option defines the number of new blocks to wait for the **first confirmation**, otherwise the PromiEvent rejects with a timeout error. + This option defines the number of new blocks to wait for the **first confirmation**, otherwise the PromiEvent rejects with a timeout error. The default value of `transactionBlockTimeout` is 50. From d16b8438b25613b986767ba9e67944ed586560ca Mon Sep 17 00:00:00 2001 From: myron Date: Mon, 29 Jul 2024 10:23:00 +0800 Subject: [PATCH 44/48] resolve review comments --- docs/docs/guides/web3_config/index.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 4a771f352b4..7da0113b7f4 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -314,7 +314,7 @@ console.log(web3.getContextObject().config); ``` ### [transactionPollingInterval](/api/web3-core/class/Web3Config#transactionPollingInterval) -The `transactionPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Modifying this value can reduce the wait time for confirmations or decrease the number of network requests. Setting the `transactionPollingInterval` would also set [`transactionReceiptPollingInterval`](/guides/web3_config/#transactionreceiptpollinginterval) and [`transactionConfirmationPollingInterval`](/guides/web3_config/#transactionconfirmationpollinginterval) to the same value. +This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Modifying this value can reduce the wait time for confirmations or decrease the number of network requests. Setting the `transactionPollingInterval` would also set [`transactionReceiptPollingInterval`](/guides/web3_config/#transactionreceiptpollinginterval) and [`transactionConfirmationPollingInterval`](/guides/web3_config/#transactionconfirmationpollinginterval) to the same value. The default value of `transactionPollingInterval` is 1000 ms. @@ -338,7 +338,7 @@ console.log(web3.getContextObject().config); ``` ### [transactionPollingTimeout](/api/web3-core/class/Web3Config#transactionPollingTimeout) -The `transactionPollingTimeout` is used over HTTP connections. This option defines the number of seconds Web3 will wait for a receipt which confirms that a transaction was mined by the network. It can be set based on the average transaction confirmation time on the network. Note: If the `transactionPollingTimeout` is exceeded, the transaction may still be pending. +This option defines the number of seconds Web3 will wait for a receipt which confirms that a transaction was mined by the network. It can be set based on the average transaction confirmation time on the network. Note: If the `transactionPollingTimeout` is exceeded, the transaction may still be pending. The default value of `transactionPollingTimeout` is 750 seconds (12.5 minutes). ```ts @@ -352,7 +352,7 @@ console.log(web3.getContextObject().config); ``` ### [transactionReceiptPollingInterval](/api/web3-core/class/Web3Config#transactionReceiptPollingInterval) -The `transactionReceiptPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Compared to [`transactionPollingInterval`](/guides/web3_config/#transactionpollinginterval), it takes higher precedence. When this value is set, it will be read first. +This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Compared to [`transactionPollingInterval`](/guides/web3_config/#transactionpollinginterval), it takes higher precedence. When this value is set, it will be read first. The default value of `transactionReceiptPollingInterval` is `undefined`. ```ts @@ -383,7 +383,7 @@ console.log(web3.getContextObject().config); The `transactionConfirmationPollingInterval` option is deprecated. Please use [`transactionReceiptPollingInterval`](/guides/web3_config/#transactionreceiptpollinginterval) or [`transactionPollingInterval`](/guides/web3_config/#transactionpollinginterval) instead. ### [blockHeaderTimeout](/api/web3-core/class/Web3Config#blockHeaderTimeout) -The `blockHeaderTimeout` is used over socket-based connections. After sending a transaction, it will listen for the appearance of new blocks and proceed with subsequent operations based on the transaction results within them. This option defines the amount seconds it should wait for 'newBlockHeaders' event before falling back to polling to fetch transaction receipt. +After sending a transaction, it will listen for the appearance of new blocks and proceed with subsequent operations based on the transaction results within them. This option defines the amount seconds it should wait for 'newBlockHeaders' in case if subscription fails it auto reverts to polling for looking blockHeaderTimeout. The default value of `blockHeaderTimeout` is 10 seconds. From b2d8639ce6f4fcede090e79131e4b78cbb664f8e Mon Sep 17 00:00:00 2001 From: Myron <49134743+mmyyrroonn@users.noreply.github.com> Date: Mon, 5 Aug 2024 11:35:36 +0800 Subject: [PATCH 45/48] Apply suggestions from code review Co-authored-by: Dan Forbes --- docs/docs/guides/web3_config/index.md | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 7da0113b7f4..0f0d2758408 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -232,7 +232,7 @@ console.log(web3.getContextObject().config); ``` ### [defaultAccount](/api/web3-core/class/Web3Config#defaultAccount) -This `defaultAccount` is used as the default `from` property, if no `from` property is specified in for the following methods: +The `defaultAccount` option is used as the default `from` property, if no `from` property is specified in for the following methods: - [`web3.eth.sendTransaction()`](/api/web3-eth/function/sendTransaction); - [`web3.eth.call()`](/api/web3-eth/function/call); - [`myContract.methods.myMethod().call()`](/libdocs/Contract#call); @@ -251,7 +251,7 @@ console.log(web3.getContextObject().config); ``` ### [defaultBlock](/api/web3-core/class/Web3Config#defaultBlock) -The following methods require a `blockNumber` parameter during its execution process, the `defaultBlock` is used for these methods. +The following methods require a `blockNumber` parameter during its execution process, the `defaultBlock` option is used for these methods. - [`web3.eth.getBalance()`](/api/web3-eth/function/getBalance); - [`web3.eth.getCode()`](/api/web3-eth/function/getCode); - [`web3.eth.getTransactionCount()`](/api/web3-eth/function/getTransactionCount); @@ -259,7 +259,7 @@ The following methods require a `blockNumber` parameter during its execution pro - [`web3.eth.call()`](/api/web3-eth/function/call); - [`myContract.methods.myMethod().call()`](/libdocs/Contract#call); -You can override it by passing in the defaultBlock as last parameter. +You can override it by passing in the `defaultBlock` as last parameter. The default value of `defaultBlock` is "latest". @@ -284,7 +284,7 @@ web3.defaultBlock = "safe"; // (For POS networks) The safe head block is one whi ``` ### [transactionBlockTimeout](/api/web3-core/class/Web3Config#transactionBlockTimeout) - This option defines the number of new blocks to wait for the **first confirmation**, otherwise the PromiEvent rejects with a timeout error. + This option defines the number of new blocks to wait for the **first confirmation**, otherwise the [`PromiEvent`](/api/web3/class/Web3PromiEvent) rejects with a timeout error. The default value of `transactionBlockTimeout` is 50. @@ -366,7 +366,7 @@ console.log(web3.getContextObject().config); ``` ### [transactionSendTimeout](/api/web3-core/class/Web3Config#transactionSendTimeout) -The `transactionSendTimeout` option is used to specify how long to wait for the network to return the sent transaction result. Note: If the RPC call times out, the transaction may still be pending or even mined by the network. We recommend checking the pending transactions in such a case. +The `transactionSendTimeout` option is used to specify how long to wait for the network to return the sent transaction result. Note: If the RPC call times out, the transaction may still be pending or even mined by the network. It is recommended that the pending transactions be checked in such a case. The default value of `transactionSendTimeout` is 750 seconds (12.5 minutes). ```ts @@ -398,7 +398,7 @@ console.log(web3.getContextObject().config); ``` ### [maxListenersWarningThreshold](/api/web3-core/class/Web3Config#maxListenersWarningThreshold) -The `maxListenersWarningThreshold` is used to set the `maxListeners` property in `EventEmitter`. +The `maxListenersWarningThreshold` is used to set the `maxListeners` property in [`EventEmitter`](/api/web3-utils/class/EventEmitter). The default value of `maxListenersWarningThreshold` is 100. ```ts @@ -412,7 +412,7 @@ console.log(web3.getContextObject().config); ``` ### [contractDataInputFill](/api/web3-core/class/Web3Config#contractDataInputFill) -The `contractDataInputFill` will allow you to set the hash of the method signature and encoded parameters to the property either `data`, `input` or `both` within your contract. This will affect the contracts [`send`](/libdocs/Contract#send), [`call`](/libdocs/Contract#call) and [`estimateGas`](/libdocs/Contract#estimategas) methods. +The `contractDataInputFill` option allows users to specify whether the [`data`](/api/web3/namespace/types#data) or [`input`](/api/web3/namespace/types#input) property (or both properties) should be set to the hash of the method signature and encoded parameters. This will affect the contracts [`send`](/libdocs/Contract#send), [`call`](/libdocs/Contract#call) and [`estimateGas`](/libdocs/Contract#estimategas) methods. The default value of `contractDataInputFill` is `data`. ```ts @@ -433,7 +433,7 @@ console.log(web3.getContextObject().config); ``` ### [defaultNetworkId](/api/web3-core/class/Web3Config#defaultNetworkId) -Each network has its own network ID. The defaultNetwork allows you to set the default network ID to increase code readability. If this parameter is not set, it will fetch the network ID from the connected RPC request. +Each network has its own [network ID](https://docs.goquorum.consensys.io/concepts/network-and-chain-id). The `defaultNetworkId` option allows users to set the default network ID. If this option is not set, Web3 will fetch the network ID with an RPC request. The default value of `defaultNetworkId` is `undefined`. ```ts @@ -447,7 +447,7 @@ console.log(web3.getContextObject().config); ``` ### [defaultChain](/api/web3-core/class/Web3Config#defaultChain) -The `defaultChain` is used for building the [`baseChain`](/api/web3-types/interface/Common#baseChain) property of the tx options in a transaction. If the `defaultCommon.basechain` is set, the `defaultChain` should be consistent with it. +The `defaultChain` option is used to set the [`Common`](/api/web3-eth-contract/class/Contract#defaultCommon) `baseChain` property. The value of this option should be consistent with [`defaultCommon.baseChain`](/guides/web3_config/#defaultcommon) if both options are set. The default value of `defaultChain` is `mainnet`. ```ts @@ -472,7 +472,7 @@ console.log(web3.getContextObject().config); ### [defaultHardfork](/api/web3-core/class/Web3Config#defaultHardfork) -The `defaultHardfork` is used for building the `defaultHardfork` property of the tx options in a transaction. If the `defaultCommon.defaultHardfork` is set, the `defaultHardfork` should be consistent with it. +The `defaultHardfork` option is used to set the [`Common`](/api/web3-eth-contract/class/Contract#defaultCommon) `hardfork` property. The value of this option should be consistent with [`defaultCommon.hardfork`](/guides/web3_config/#defaultcommon) if both options are set. The default value of `defaultHardfork` is `london`. ```ts @@ -510,7 +510,7 @@ console.log(web3.getContextObject().config); ``` ### [defaultCommon](/api/web3-core/class/Web3Config#defaultCommon) -The `defaultCommon` is used for building the `common` property of the tx options in a transaction. It should be consistent with the [`defaultHardfork`](/guides/web3_config/#defaulthardfork) and [`defaultChain`](/guides/web3_config/#defaultchain). Please check the `defaultCommon` property [here](/libdocs/Contract/#defaultcommon) +The `defaultCommon` option is used to set the [`defaultCommon`](/libdocs/Contract#defaultcommon) value for smart contract transactions. It should be consistent with the [`defaultHardfork`](/guides/web3_config/#defaulthardfork) and [`defaultChain`](/guides/web3_config/#defaultchain) options if they are set. The default value of `defaultCommon` is `undefined`. @@ -535,7 +535,7 @@ console.log(web3.getContextObject().config); ``` ### [defaultTransactionType](/api/web3-core/class/Web3Config#defaultTransactionType) -The `defaultTransactionType` is used set the transaction type. Transactions with type 0x0 are legacy transactions that use the transaction format existing before typed transactions were introduced in [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718). Transactions with type 0x1 are transactions introduced in [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930). Transactions with type 0x2 are transactions introduced in [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559), included in Ethereum's London fork. +The `defaultTransactionType` option is used to set the transaction type. Transactions with type 0x0 are legacy transactions that use the transaction format that existed before [typed transactions](https://ethereum.org/en/developers/docs/transactions/#typed-transaction-envelope) were introduced in [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718). Transactions with type 0x1 are transactions introduced in [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930). Transactions with type 0x2 are transactions introduced in [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559), included in Ethereum's London fork. The default value of `defaultTransactionType` is `0x02`. ```ts @@ -549,7 +549,7 @@ console.log(web3.getContextObject().config); ``` ### [defaultMaxPriorityFeePerGas](/api/web3-core/class/Web3Config#defaultMaxPriorityFeePerGas) -The `defaultMaxPriorityFeePerGas` is used to send transactions with the maximum priority gas fee. +The `defaultMaxPriorityFeePerGas` option is used to set the [`defaultMaxPriorityFeePerGas`](/api/web3-eth-contract/class/Contract#defaultMaxPriorityFeePerGas) value for [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) smart contract transactions ([transaction type](#defaulttransactiontype) 0x2). The default value of `defaultMaxPriorityFeePerGas` is 2500000000 (2.5gwei) in hexstring format. ```ts @@ -564,7 +564,7 @@ console.log(web3.getContextObject().config); ``` ### [defaultReturnFormat](/api/web3-core/class/Web3Config#defaultReturnFormat) -The `defaultReturnFormat` allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. +The `defaultReturnFormat` option allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. ```ts import { Web3, FMT_NUMBER, FMT_BYTES } from 'web3'; From b5655d2045e558a8de467c2aba3cd8b68a562fa3 Mon Sep 17 00:00:00 2001 From: myron Date: Mon, 5 Aug 2024 12:00:59 +0800 Subject: [PATCH 46/48] remove all example except for transactionPollingInterval, defaultReturnFormat and defaultCommon --- docs/docs/guides/web3_config/index.md | 152 -------------------------- 1 file changed, 152 deletions(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index 0f0d2758408..e0f4c30597e 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -221,16 +221,6 @@ For example, the error message could be `TransactionRevertInstructionError('Retu The default value of `handleRevert` is `false`. -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.handleRevert = false; - -console.log(web3.getContextObject().config); -``` - ### [defaultAccount](/api/web3-core/class/Web3Config#defaultAccount) The `defaultAccount` option is used as the default `from` property, if no `from` property is specified in for the following methods: - [`web3.eth.sendTransaction()`](/api/web3-eth/function/sendTransaction); @@ -240,16 +230,6 @@ The `defaultAccount` option is used as the default `from` property, if no `from` The default value of `defaultAccount` is `undefined`. -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.defaultAccount = undefined; - -console.log(web3.getContextObject().config); -``` - ### [defaultBlock](/api/web3-core/class/Web3Config#defaultBlock) The following methods require a `blockNumber` parameter during its execution process, the `defaultBlock` option is used for these methods. - [`web3.eth.getBalance()`](/api/web3-eth/function/getBalance); @@ -263,16 +243,6 @@ You can override it by passing in the `defaultBlock` as last parameter. The default value of `defaultBlock` is "latest". -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.defaultBlock = "latest"; - -console.log(web3.getContextObject().config); -``` - #### All available choices for defaultBlock: ```ts web3.defaultBlock = 20167235; // A block number @@ -288,31 +258,11 @@ web3.defaultBlock = "safe"; // (For POS networks) The safe head block is one whi The default value of `transactionBlockTimeout` is 50. -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.transactionBlockTimeout = 50; - -console.log(web3.getContextObject().config); -``` - ### [transactionConfirmationBlocks](/api/web3-core/class/Web3Config#transactionConfirmationBlocks) This defines the number of blocks required for a transaction to be considered confirmed. Different chains have varying security considerations and requirements for confirmation block numbers. The default value of `transactionConfirmationBlocks` is 24. -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.transactionConfirmationBlocks = 24; - -console.log(web3.getContextObject().config); -``` - ### [transactionPollingInterval](/api/web3-core/class/Web3Config#transactionPollingInterval) This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Modifying this value can reduce the wait time for confirmations or decrease the number of network requests. Setting the `transactionPollingInterval` would also set [`transactionReceiptPollingInterval`](/guides/web3_config/#transactionreceiptpollinginterval) and [`transactionConfirmationPollingInterval`](/guides/web3_config/#transactionconfirmationpollinginterval) to the same value. @@ -341,43 +291,16 @@ console.log(web3.getContextObject().config); This option defines the number of seconds Web3 will wait for a receipt which confirms that a transaction was mined by the network. It can be set based on the average transaction confirmation time on the network. Note: If the `transactionPollingTimeout` is exceeded, the transaction may still be pending. The default value of `transactionPollingTimeout` is 750 seconds (12.5 minutes). -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.transactionPollingTimeout = 750000; // 750000 ms = 750 s - -console.log(web3.getContextObject().config); -``` ### [transactionReceiptPollingInterval](/api/web3-core/class/Web3Config#transactionReceiptPollingInterval) This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. Compared to [`transactionPollingInterval`](/guides/web3_config/#transactionpollinginterval), it takes higher precedence. When this value is set, it will be read first. The default value of `transactionReceiptPollingInterval` is `undefined`. -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.transactionReceiptPollingInterval = undefined; - -console.log(web3.getContextObject().config); -``` ### [transactionSendTimeout](/api/web3-core/class/Web3Config#transactionSendTimeout) The `transactionSendTimeout` option is used to specify how long to wait for the network to return the sent transaction result. Note: If the RPC call times out, the transaction may still be pending or even mined by the network. It is recommended that the pending transactions be checked in such a case. The default value of `transactionSendTimeout` is 750 seconds (12.5 minutes). -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.transactionSendTimeout = 750000; // 750000 ms = 750 s - -console.log(web3.getContextObject().config); -``` ### [transactionConfirmationPollingInterval](/api/web3-core/class/Web3Config#transactionConfirmationPollingInterval) The `transactionConfirmationPollingInterval` option is deprecated. Please use [`transactionReceiptPollingInterval`](/guides/web3_config/#transactionreceiptpollinginterval) or [`transactionPollingInterval`](/guides/web3_config/#transactionpollinginterval) instead. @@ -387,43 +310,15 @@ After sending a transaction, it will listen for the appearance of new blocks and The default value of `blockHeaderTimeout` is 10 seconds. -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.blockHeaderTimeout = 10; // 10 s - -console.log(web3.getContextObject().config); -``` - ### [maxListenersWarningThreshold](/api/web3-core/class/Web3Config#maxListenersWarningThreshold) The `maxListenersWarningThreshold` is used to set the `maxListeners` property in [`EventEmitter`](/api/web3-utils/class/EventEmitter). The default value of `maxListenersWarningThreshold` is 100. -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.maxListenersWarningThreshold = 100; - -console.log(web3.getContextObject().config); -``` ### [contractDataInputFill](/api/web3-core/class/Web3Config#contractDataInputFill) The `contractDataInputFill` option allows users to specify whether the [`data`](/api/web3/namespace/types#data) or [`input`](/api/web3/namespace/types#input) property (or both properties) should be set to the hash of the method signature and encoded parameters. This will affect the contracts [`send`](/libdocs/Contract#send), [`call`](/libdocs/Contract#call) and [`estimateGas`](/libdocs/Contract#estimategas) methods. The default value of `contractDataInputFill` is `data`. -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.contractDataInputFill = 'data'; - -console.log(web3.getContextObject().config); -``` #### All available choices for contractDataInputFill: ```ts @@ -436,29 +331,11 @@ console.log(web3.getContextObject().config); Each network has its own [network ID](https://docs.goquorum.consensys.io/concepts/network-and-chain-id). The `defaultNetworkId` option allows users to set the default network ID. If this option is not set, Web3 will fetch the network ID with an RPC request. The default value of `defaultNetworkId` is `undefined`. -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.defaultNetworkId = undefined; - -console.log(web3.getContextObject().config); -``` ### [defaultChain](/api/web3-core/class/Web3Config#defaultChain) The `defaultChain` option is used to set the [`Common`](/api/web3-eth-contract/class/Contract#defaultCommon) `baseChain` property. The value of this option should be consistent with [`defaultCommon.baseChain`](/guides/web3_config/#defaultcommon) if both options are set. The default value of `defaultChain` is `mainnet`. -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.defaultChain = 'mainnet'; - -console.log(web3.getContextObject().config); -``` #### All available choices for defaultChain: ```ts @@ -470,20 +347,10 @@ console.log(web3.getContextObject().config); 'sepolia' ``` - ### [defaultHardfork](/api/web3-core/class/Web3Config#defaultHardfork) The `defaultHardfork` option is used to set the [`Common`](/api/web3-eth-contract/class/Contract#defaultCommon) `hardfork` property. The value of this option should be consistent with [`defaultCommon.hardfork`](/guides/web3_config/#defaultcommon) if both options are set. The default value of `defaultHardfork` is `london`. -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.defaultHardfork = 'london'; - -console.log(web3.getContextObject().config); -``` #### All available choices for defaultHardFork: ```ts @@ -538,30 +405,11 @@ console.log(web3.getContextObject().config); The `defaultTransactionType` option is used to set the transaction type. Transactions with type 0x0 are legacy transactions that use the transaction format that existed before [typed transactions](https://ethereum.org/en/developers/docs/transactions/#typed-transaction-envelope) were introduced in [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718). Transactions with type 0x1 are transactions introduced in [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930). Transactions with type 0x2 are transactions introduced in [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559), included in Ethereum's London fork. The default value of `defaultTransactionType` is `0x02`. -```ts -import { Web3 } from 'web3'; - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.defaultTransactionType = 0x02; - -console.log(web3.getContextObject().config); -``` ### [defaultMaxPriorityFeePerGas](/api/web3-core/class/Web3Config#defaultMaxPriorityFeePerGas) The `defaultMaxPriorityFeePerGas` option is used to set the [`defaultMaxPriorityFeePerGas`](/api/web3-eth-contract/class/Contract#defaultMaxPriorityFeePerGas) value for [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) smart contract transactions ([transaction type](#defaulttransactiontype) 0x2). The default value of `defaultMaxPriorityFeePerGas` is 2500000000 (2.5gwei) in hexstring format. -```ts -import { Web3 } from 'web3'; -import { numberToHex } from 'web3-utils' - -const web3 = new Web3('http://127.0.0.1:7545'); - -web3.defaultMaxPriorityFeePerGas = numberToHex(2500000000); // 2.5gwei - -console.log(web3.getContextObject().config); -``` ### [defaultReturnFormat](/api/web3-core/class/Web3Config#defaultReturnFormat) The `defaultReturnFormat` option allows users to specify the format in which certain types of data should be returned by default. It is a configuration parameter that can be set at the global level and affects how data is returned across the entire library. From 80e10dbede4e5db28dbcd8e6258df8f339774aaa Mon Sep 17 00:00:00 2001 From: Myron <49134743+mmyyrroonn@users.noreply.github.com> Date: Tue, 6 Aug 2024 15:36:00 +0800 Subject: [PATCH 47/48] Apply suggestions from code review Co-authored-by: Dan Forbes --- docs/docs/guides/web3_config/index.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index e0f4c30597e..b4553d313d5 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -209,7 +209,7 @@ The following methods will retrieve specific error types and error messages when - [`web3.eth.sendTransaction()`](/api/web3-eth/function/sendTransaction); - [`myContract.methods.myMethod().send()`](/libdocs/Contract#send); -The error types will be one of the following: +The error type will be one of the following: - [InvalidResponseError](/api/web3-errors/class/InvalidResponseError) - [ContractExecutionError](/api/web3-errors/class/ContractExecutionError) - [TransactionRevertWithCustomError](/api/web3-errors/class/TransactionRevertWithCustomError) @@ -217,12 +217,12 @@ The error types will be one of the following: - [TransactionRevertInstructionError](/api/web3-errors/class/TransactionRevertInstructionError) - [TransactionPollingTimeoutError](/api/web3-errors/class/TransactionPollingTimeoutError) -For example, the error message could be `TransactionRevertInstructionError('Returned error: invalid argument 0: json: cannot unmarshal invalid hex string into Go struct field TransactionArgs.data of type hexutil.Bytes')`. The `handleRevert` is only supported for [`sendTransaction`](/api/web3-eth/function/sendTransaction) and not for [`sendSignedTransaction`](/api/web3-eth/function/sendSignedTransaction) for now. +For example, the error message could be `TransactionRevertInstructionError('Returned error: invalid argument 0: json: cannot unmarshal invalid hex string into Go struct field TransactionArgs.data of type hexutil.Bytes')`. The `handleRevert` option is only supported for [`sendTransaction`](/api/web3-eth/function/sendTransaction) and not for [`sendSignedTransaction`](/api/web3-eth/function/sendSignedTransaction) for now. The default value of `handleRevert` is `false`. ### [defaultAccount](/api/web3-core/class/Web3Config#defaultAccount) -The `defaultAccount` option is used as the default `from` property, if no `from` property is specified in for the following methods: +The `defaultAccount` option is used as the default `from` property, if no `from` property is specified for the following methods: - [`web3.eth.sendTransaction()`](/api/web3-eth/function/sendTransaction); - [`web3.eth.call()`](/api/web3-eth/function/call); - [`myContract.methods.myMethod().call()`](/libdocs/Contract#call); @@ -231,7 +231,7 @@ The `defaultAccount` option is used as the default `from` property, if no `from` The default value of `defaultAccount` is `undefined`. ### [defaultBlock](/api/web3-core/class/Web3Config#defaultBlock) -The following methods require a `blockNumber` parameter during its execution process, the `defaultBlock` option is used for these methods. +The following methods accept an optional `blockNumber` parameter, the `defaultBlock` option is used for these methods if no `blockNumber` parameter is provided. - [`web3.eth.getBalance()`](/api/web3-eth/function/getBalance); - [`web3.eth.getCode()`](/api/web3-eth/function/getCode); - [`web3.eth.getTransactionCount()`](/api/web3-eth/function/getTransactionCount); @@ -239,7 +239,7 @@ The following methods require a `blockNumber` parameter during its execution pro - [`web3.eth.call()`](/api/web3-eth/function/call); - [`myContract.methods.myMethod().call()`](/libdocs/Contract#call); -You can override it by passing in the `defaultBlock` as last parameter. +If a `blockNumber` parameter is provided to one of the above function calls, it will override this option. The default value of `defaultBlock` is "latest". From e2a2547b2eb36b8b3b11cb9d79b9b001a100f4fe Mon Sep 17 00:00:00 2001 From: Dan Forbes Date: Tue, 6 Aug 2024 05:35:55 -0700 Subject: [PATCH 48/48] Update docs/docs/guides/web3_config/index.md --- docs/docs/guides/web3_config/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/guides/web3_config/index.md b/docs/docs/guides/web3_config/index.md index b4553d313d5..42561aedcbc 100644 --- a/docs/docs/guides/web3_config/index.md +++ b/docs/docs/guides/web3_config/index.md @@ -306,7 +306,7 @@ The default value of `transactionSendTimeout` is 750 seconds (12.5 minutes). The `transactionConfirmationPollingInterval` option is deprecated. Please use [`transactionReceiptPollingInterval`](/guides/web3_config/#transactionreceiptpollinginterval) or [`transactionPollingInterval`](/guides/web3_config/#transactionpollinginterval) instead. ### [blockHeaderTimeout](/api/web3-core/class/Web3Config#blockHeaderTimeout) -After sending a transaction, it will listen for the appearance of new blocks and proceed with subsequent operations based on the transaction results within them. This option defines the amount seconds it should wait for 'newBlockHeaders' in case if subscription fails it auto reverts to polling for looking blockHeaderTimeout. +After sending a transaction, Web3 will listen for the appearance of new blocks and proceed with subsequent operations based on the transaction results within them. This option defines the number of seconds Web3 should wait for the appearance of new blocks before reverting to polling to fetch the transaction receipt. The default value of `blockHeaderTimeout` is 10 seconds.