You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:
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.
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 following methods accept an optional `blockNumber` parameter, the `defaultBlock` option is used for these methods if no `blockNumber` parameter is provided.
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".
#### All available choices for defaultBlock:
```ts
import { Web3, FMT_NUMBER, FMT_BYTES } from 'web3';
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 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.
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.
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.
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.
```ts
import { Web3 } from 'web3';
const web3 = new Web3('http://127.0.0.1:7545');
web3.transactionPollingInterval = 1000; // 1000 ms = 1 s
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).
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`.
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).
The `transactionConfirmationPollingInterval` option is deprecated. Please use [`transactionReceiptPollingInterval`](/guides/web3_config/#transactionreceiptpollinginterval) or [`transactionPollingInterval`](/guides/web3_config/#transactionpollinginterval) instead.
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.
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`.
#### All available choices for contractDataInputFill:
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`.
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 `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`.
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`.
```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,
},
mmyyrroonn marked this conversation as resolved.
Show resolvedHide resolved
};
console.log(web3.getContextObject().config);
```
:::info
The `defaultReturnFormat` can be configured both globally and at the package level:
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`.
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.
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 { Web3Eth, FMT_NUMBER, FMT_BYTES } from 'web3-eth';
import { Web3, FMT_NUMBER, FMT_BYTES } from 'web3';
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(docs): Expand web3 config guide #7131
feat(docs): Expand web3 config guide #7131
Changes from all commits
a993700
46dc323
6d9fcf8
6c0f38c
38ac6ed
0fb431a
5744e79
382ee1d
58445a9
b23bb96
a0adf0b
973d9bb
c50492b
56c6152
fbab925
6787e8b
8297909
098a245
c8d5ea0
1e3794c
77931c9
c618a81
040cbbb
86dbc63
2f512dc
05a845b
7d0f2f0
aeff438
634751e
4f13cfd
1413f42
9e901a6
8d79edf
b5c2a1d
ca704f5
168111c
66772d5
788ef32
2324306
4f19cc5
dee663a
34dffab
5ef8737
ed4d040
ac08d70
1b98de7
75594a1
7a56f4b
5da96a8
632a750
d16b843
91d52cf
cc97e2a
4a5a47d
b2d8639
b5655d2
80e10db
e2a2547
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing