Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 4e732db

Browse files
author
Alex
authored
Merge branch '4.x' into events-guide-6741
2 parents 6e87a0b + 93296c2 commit 4e732db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1333
-352
lines changed

CHANGELOG.md

Lines changed: 87 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,7 +2120,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
21202120
#### web3-eth
21212121

21222122
- Ensure provider.supportsSubscriptions exists before watching by subscription (#6440)
2123-
- Fixed param sent to `checkRevertBeforeSending` in `sendSignedTransaction`
2123+
- Fixed param sent to `checkRevertBeforeSending` in `sendSignedTransaction`
21242124
- Fixed `defaultTransactionBuilder` for value issue (#6509)
21252125

21262126
#### web3-eth-abi
@@ -2129,7 +2129,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
21292129

21302130
#### web3-eth-accounts
21312131

2132-
- Fixed `recover` function, `v` will be normalized to value 0,1 (#6344)
2132+
- Fixed `recover` function, `v` will be normalized to value 0,1 (#6344)
21332133

21342134
#### web3-providers-http
21352135

@@ -2252,27 +2252,26 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
22522252

22532253
#### web3-eth-contract
22542254

2255-
- Will populate `data` for transactions in contract for metamask provider instead of `input` (#6534)
2255+
- Will populate `data` for transactions in contract for metamask provider instead of `input` (#6534)
22562256

22572257
## [4.3.0]
22582258

22592259
### Changed
22602260

22612261
#### web3-core
22622262

2263-
- Web3config `contractDataInputFill` has been defaulted to `data`, instead of `input`. (#6622)
2263+
- Web3config `contractDataInputFill` has been defaulted to `data`, instead of `input`. (#6622)
22642264

22652265
#### web3-eth-contracts
22662266

2267-
- By default, contracts will fill `data` instead of `input` within method calls (#6622)
2267+
- By default, contracts will fill `data` instead of `input` within method calls (#6622)
22682268

22692269
### Added
22702270

2271-
22722271
#### web3-utils
22732272

22742273
- `SocketProvider` now contains public function `getPendingRequestQueueSize`, `getSentRequestsQueueSize` and `clearQueues` (#6479)
2275-
- Added `safeDisconnect` as a `SocketProvider` method to disconnect only when request queue size and send request queue size is 0 (#6479)
2274+
- Added `safeDisconnect` as a `SocketProvider` method to disconnect only when request queue size and send request queue size is 0 (#6479)
22762275
- Add `isContractInitOptions` method (#6555)
22772276

22782277
#### web3
@@ -2305,7 +2304,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
23052304

23062305
#### web3-eth-contract
23072306

2308-
- Allow the `deploy` function to accept parameters, even when no ABI was provided to the `Contract`(#6635)
2307+
- Allow the `deploy` function to accept parameters, even when no ABI was provided to the `Contract`(#6635)
23092308

23102309
#### web3
23112310

@@ -2324,8 +2323,8 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
23242323

23252324
#### web3-eth-contract
23262325

2327-
- Fix and error that happen when trying to get past events by calling `contract.getPastEvents` or `contract.events.allEvents()`, if there is no matching events. (#6647)
2328-
- Fixed: The Contract is not using the context wallet passed if context was passed at constructor. (#6661)
2326+
- Fix and error that happen when trying to get past events by calling `contract.getPastEvents` or `contract.events.allEvents()`, if there is no matching events. (#6647)
2327+
- Fixed: The Contract is not using the context wallet passed if context was passed at constructor. (#6661)
23292328

23302329
#### web3-utils
23312330

@@ -2347,7 +2346,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
23472346

23482347
- Adds missing exported type `AbiItem` from 1.x to v4 for compatabiltiy (#6678)
23492348

2350-
### Changed
2349+
### Changed
23512350

23522351
#### web3
23532352

@@ -2359,7 +2358,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
23592358

23602359
#### web3
23612360

2362-
- Added EIP-6963 utility function `requestEIP6963Providers` for multi provider discovery
2361+
- Added EIP-6963 utility function `requestEIP6963Providers` for multi provider discovery
23632362

23642363
#### web3-eth
23652364

@@ -2393,16 +2392,88 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
23932392

23942393
#### web3-eth-ens
23952394

2396-
- Added function getText and getName in ENS and resolver classes (#6914)
2395+
- Added function getText and getName in ENS and resolver classes (#6914)
23972396

23982397
### fixed
23992398

24002399
#### web3-validator
24012400

2402-
- Multi-dimensional arrays(with a fix length) are now handled properly when parsing ABIs (#6798)
2401+
- Multi-dimensional arrays(with a fix length) are now handled properly when parsing ABIs (#6798)
24032402

24042403
#### web3-utils
24052404

2406-
- fixed erroneous parsing of big numbers in the `toNumber(...)` function (#6880)
2405+
- fixed erroneous parsing of big numbers in the `toNumber(...)` function (#6880)
2406+
2407+
## [4.8.0]
2408+
2409+
### Changed
2410+
2411+
#### web3-eth-abi
2412+
2413+
- Dependencies updated
2414+
2415+
#### web3-eth-accounts
2416+
2417+
- Dependencies updated
2418+
2419+
### Fixed
2420+
2421+
#### web3-eth-contract
2422+
2423+
- Fix an issue with smart contract function overloading (#6922)
2424+
2425+
#### web3-utils
2426+
2427+
- fixed toHex incorrectly hexing Uint8Arrays and Buffer (#6957)
2428+
- fixed isUint8Array not returning true for Buffer (#6957)
2429+
2430+
### Added
2431+
2432+
#### web3-eth-contract
2433+
2434+
- Added a console warning in case of an ambiguous call to a solidity method with parameter overloading (#6942)
2435+
- Added contract.deploy(...).decodeData(...) and contract.decodeMethodData(...) that decode data based on the ABI (#6950)
2436+
2437+
#### web3-eth
2438+
2439+
- method `getBlock` now includes properties of eip 4844, 4895, 4788 when returning block (#6933)
2440+
- update type `withdrawalsSchema`, `blockSchema` and `blockHeaderSchema` schemas to include properties of eip 4844, 4895, 4788 (#6933)
2441+
2442+
#### web3-types
2443+
2444+
- Added `signature` to type `AbiFunctionFragment` (#6922)
2445+
- update type `Withdrawals`, `block` and `BlockHeaderOutput` to include properties of eip 4844, 4895, 4788 (#6933)
2446+
2447+
## [Unreleased]
2448+
2449+
### Added
2450+
2451+
#### web3-core
2452+
2453+
- `defaultReturnFormat` was added to the configuration options. (#6947)
2454+
2455+
#### web3-eth
2456+
2457+
- `defaultReturnFormat` was added to all methods that have `ReturnType` param. (#6947)
2458+
2459+
#### web3-eth-contract
2460+
2461+
- `defaultReturnFormat` was added to all methods that have `ReturnType` param. (#6947)
2462+
2463+
#### web3-eth-ens
2464+
2465+
- `defaultReturnFormat` was added to all methods that have `ReturnType` param. (#6947)
2466+
2467+
#### web3-net
2468+
2469+
- `defaultReturnFormat` was added to all methods that have `ReturnType` param. (#6947)
2470+
2471+
#### web3-types
2472+
2473+
- Added `signature` to type `AbiFunctionFragment` (#6922)
2474+
- update type `Withdrawals`, `block` and `BlockHeaderOutput` to include properties of eip 4844, 4895, 4788 (#6933)
2475+
2476+
### Fixed
2477+
2478+
#### web3-validator
24072479

2408-
## [Unreleased]

docs/docs/guides/web3_config/index.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ There is list of configuration params that can be set for modifying behavior of
2727
- [defaultHardfork](/api/web3-core/class/Web3Config#defaultHardfork)
2828
- [defaultCommon](/api/web3-core/class/Web3Config#defaultCommon)
2929
- [defaultTransactionType](/api/web3-core/class/Web3Config#defaultTransactionType)
30+
- [defaultReturnFormat](/api/web3-core/class/Web3Config#defaultReturnFormat)
3031

3132
## Global level Config
3233

@@ -198,4 +199,46 @@ console.log(web3.getContextObject().config)
198199
transactionPollingTimeout: 750000,
199200
...
200201
*/
201-
```
202+
```
203+
204+
205+
### defaultReturnFormat
206+
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.
207+
```ts
208+
import { Web3, FMT_NUMBER, FMT_BYTES } from 'web3';
209+
210+
web3.defaultReturnFormat = {
211+
number: FMT_NUMBER.BIGINT,
212+
bytes: FMT_BYTES.HEX,
213+
};
214+
215+
```
216+
:::info
217+
The `defaultReturnFormat` can be configured both globally and at the package level:
218+
```ts
219+
import { Web3Eth, FMT_NUMBER, FMT_BYTES } from 'web3-eth';
220+
221+
const eth = new Web3Eth()
222+
eth.defaultReturnFormat = {
223+
number: FMT_NUMBER.BIGINT,
224+
bytes: FMT_BYTES.HEX,
225+
};
226+
227+
```
228+
:::
229+
#### All available choices for numeric data:
230+
```ts
231+
export enum FMT_NUMBER {
232+
NUMBER = 'NUMBER_NUMBER',
233+
HEX = 'NUMBER_HEX',
234+
STR = 'NUMBER_STR',
235+
BIGINT = 'NUMBER_BIGINT',
236+
}
237+
```
238+
#### All available choices for bytes data:
239+
```ts
240+
export enum FMT_BYTES {
241+
HEX = 'BYTES_HEX',
242+
UINT8ARRAY = 'BYTES_UINT8ARRAY',
243+
}
244+
```

docs/docs/guides/web3_upgrade_guide/1.x/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ It will not have:
7979
- `givenProvider` default value is `undefined` instead of `null`
8080
- `currentProvider` default value is `undefined` instead of `null` (if web3 is instantiated without a provider)
8181

82+
:::warning
83+
In version 4.x, all numbers return as BigInt instead of string or number, which constitutes a breaking change for users accustomed to handling numbers as string or number in their code. For instance, web3.eth.getBalance will now return BigInt instead of string or number. If you wish to retain numbers as number or string, you can refer to [this guide](/guides/web3_config/#defaultreturnformat) on how to set returning types in web3js 4.x.
84+
:::
8285
### Web3 BatchRequest
8386

8487
```ts

packages/web3-core/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,7 @@ Documentation:
207207

208208
- Web3config `contractDataInputFill` has been defaulted to `data`, istead of `input`. (#6622)
209209

210-
## [Unreleased]
210+
## [Unreleased]
211+
212+
### Added
213+
- `defaultReturnFormat` was added to the configuration options. (#6947)

packages/web3-core/src/types.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ You should have received a copy of the GNU Lesser General Public License
1515
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
import { HexString, Transaction } from 'web3-types';
18+
import { HexString, JsonRpcResponse, Transaction, Web3APIMethod, Web3APIRequest, Web3APIReturnType } from 'web3-types';
1919

2020
export type TransactionTypeParser = (
2121
transaction: Transaction,
@@ -30,3 +30,18 @@ export interface ExtensionObject {
3030
property?: string;
3131
methods: Method[];
3232
}
33+
34+
export interface RequestManagerMiddleware<API> {
35+
processRequest<
36+
AnotherMethod extends Web3APIMethod<API>
37+
>(
38+
request: Web3APIRequest<API, AnotherMethod>,
39+
options?: { [key: string]: unknown }): Promise<Web3APIRequest<API, AnotherMethod>>;
40+
41+
processResponse<
42+
AnotherMethod extends Web3APIMethod<API>,
43+
ResponseType = Web3APIReturnType<API, AnotherMethod>>
44+
(
45+
response: JsonRpcResponse<ResponseType>,
46+
options?: { [key: string]: unknown }): Promise<JsonRpcResponse<ResponseType>>;
47+
}

packages/web3-core/src/web3_config.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ You should have received a copy of the GNU Lesser General Public License
1515
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
import { Numbers, HexString, BlockNumberOrTag, Common } from 'web3-types';
18+
import {
19+
Numbers,
20+
HexString,
21+
BlockNumberOrTag,
22+
Common,
23+
DEFAULT_RETURN_FORMAT,
24+
DataFormat,
25+
} from 'web3-types';
1926
import { ConfigHardforkMismatchError, ConfigChainMismatchError } from 'web3-errors';
2027
import { isNullish, toHex } from 'web3-utils';
2128
import { TransactionTypeParser } from './types.js';
@@ -52,6 +59,7 @@ export interface Web3ConfigOptions {
5259
};
5360
transactionBuilder?: TransactionBuilder;
5461
transactionTypeParser?: TransactionTypeParser;
62+
defaultReturnFormat: DataFormat;
5563
}
5664

5765
type ConfigEvent<T, P extends keyof T = keyof T> = P extends unknown
@@ -93,6 +101,7 @@ export abstract class Web3Config
93101
},
94102
transactionBuilder: undefined,
95103
transactionTypeParser: undefined,
104+
defaultReturnFormat: DEFAULT_RETURN_FORMAT,
96105
};
97106

98107
public constructor(options?: Partial<Web3ConfigOptions>) {
@@ -348,6 +357,15 @@ export abstract class Web3Config
348357
this.config.maxListenersWarningThreshold = val;
349358
}
350359

360+
public get defaultReturnFormat() {
361+
return this.config.defaultReturnFormat;
362+
}
363+
public set defaultReturnFormat(val) {
364+
this._triggerConfigChange('defaultReturnFormat', val);
365+
366+
this.config.defaultReturnFormat = val;
367+
}
368+
351369
public get defaultNetworkId() {
352370
return this.config.defaultNetworkId;
353371
}

packages/web3-core/src/web3_context.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { isNullish } from 'web3-utils';
2525
import { BaseTransaction, TransactionFactory } from 'web3-eth-accounts';
2626
import { isSupportedProvider } from './utils.js';
2727
// eslint-disable-next-line import/no-cycle
28-
import { ExtensionObject } from './types.js';
28+
import { ExtensionObject, RequestManagerMiddleware } from './types.js';
2929
import { Web3BatchRequest } from './web3_batch_request.js';
3030
// eslint-disable-next-line import/no-cycle
3131
import { Web3Config, Web3ConfigEvent, Web3ConfigOptions } from './web3_config.js';
@@ -65,6 +65,7 @@ export type Web3ContextInitOptions<
6565
registeredSubscriptions?: RegisteredSubs;
6666
accountProvider?: Web3AccountProvider<Web3BaseWalletAccount>;
6767
wallet?: Web3BaseWallet<Web3BaseWalletAccount>;
68+
requestManagerMiddleware?: RequestManagerMiddleware<API>;
6869
};
6970

7071
// eslint-disable-next-line no-use-before-define
@@ -129,6 +130,7 @@ export class Web3Context<
129130
registeredSubscriptions,
130131
accountProvider,
131132
wallet,
133+
requestManagerMiddleware
132134
} = providerOrContext as Web3ContextInitOptions<API, RegisteredSubs>;
133135

134136
this.setConfig(config ?? {});
@@ -138,6 +140,7 @@ export class Web3Context<
138140
new Web3RequestManager<API>(
139141
provider,
140142
config?.enableExperimentalFeatures?.useSubscriptionWhenCheckingBlockTimeout,
143+
requestManagerMiddleware
141144
);
142145

143146
if (subscriptionManager) {
@@ -352,6 +355,11 @@ export class Web3Context<
352355
this.provider = provider;
353356
return true;
354357
}
358+
359+
public setRequestManagerMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>){
360+
this.requestManager.setMiddleware(requestManagerMiddleware);
361+
}
362+
355363
/**
356364
* Will return the {@link Web3BatchRequest} constructor.
357365
*/

0 commit comments

Comments
 (0)