Thanks to visit codestin.com
Credit goes to github.com

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

Commit c3ffd52

Browse files
authored
Merge branch '4.x' into fix-infura
2 parents 5174efa + cbbbd84 commit c3ffd52

File tree

11 files changed

+119
-20
lines changed

11 files changed

+119
-20
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,4 +2631,21 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
26312631

26322632
- `web3.eth.Contract` will get transaction middleware and use it, if `web3.eth` has transaction middleware. (#7138)
26332633

2634+
## [4.11.1]
2635+
2636+
### Fixed
2637+
2638+
#### web3-errors
2639+
2640+
- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905)
2641+
2642+
#### web3-eth
2643+
2644+
- Adds transaction property to be an empty list rather than undefined when no transactions are included in the block (#7151)
2645+
- Change method `getTransactionReceipt` to not be casted as `TransactionReceipt` to give proper return type (#7159)
2646+
2647+
#### web3
2648+
2649+
- Remove redundant constructor of contractBuilder (#7150)
2650+
26342651
## [Unreleased]

docs/docs/guides/web3_plugin_guide/plugin_authors.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,73 @@ public link(parentContext: Web3Context) {
233233
}
234234
```
235235

236+
## Plugin Middleware
237+
238+
Middleware allows plugins to intercept network interactions and inject custom logic. There are two types of plugin middleware: [request middleware](#request-middleware) and [transaction middleware](#transaction-middleware). In both cases, the middleware is implemented as a new class and registered with the plugin in the plugin's `link` method. Keep reading to learn how to add middleware to a plugin.
239+
240+
### Request Middleware
241+
242+
Request middleware allows plugins to modify RPC requests before they are sent to the network and modify RPC responses before they are returned to Web3.js for further internal processing. Request middleware must implement the [`RequestManagerMiddleware`](/api/web3-core/interface/RequestManagerMiddleware) interface, which specifies two functions: [`processRequest`](/api/web3-core/interface/RequestManagerMiddleware#processRequest) and [`processResponse`](/api/web3-core/interface/RequestManagerMiddleware#processResponse). Here is a simple example of request middleware that prints RPC requests and responses to the console:
243+
244+
```ts
245+
export class RequestMiddleware<API> implements RequestManagerMiddleware<API> {
246+
public async processRequest<ParamType = unknown[]>(
247+
request: JsonRpcPayload<ParamType>
248+
): Promise<JsonRpcPayload<ParamType>> {
249+
const reqObj = { ...request } as JsonRpcPayload;
250+
console.log("Request:", reqObj);
251+
return Promise.resolve(reqObj as JsonRpcPayload<ParamType>);
252+
}
253+
254+
public async processResponse<
255+
Method extends Web3APIMethod<API>,
256+
ResponseType = Web3APIReturnType<API, Method>
257+
>(
258+
response: JsonRpcResponse<ResponseType>
259+
): Promise<JsonRpcResponse<ResponseType>> {
260+
const resObj = { ...response };
261+
console.log("Response:", resObj);
262+
return Promise.resolve(resObj);
263+
}
264+
}
265+
```
266+
267+
To add request middleware to a plugin, use the [`Web3RequestManager.setMiddleware`](/api/web3-core/class/Web3RequestManager#setMiddleware) method in the plugin's `link` method as demonstrated below:
268+
269+
```ts
270+
public link(parentContext: Web3Context): void {
271+
parentContext.requestManager.setMiddleware(new RequestMiddleware());
272+
super.link(parentContext);
273+
}
274+
```
275+
276+
### Transaction Middleware
277+
278+
Transaction middleware allows plugins to modify transaction data before it is sent to the network. Transaction middleware must implement the [`TransactionMiddleware`](/api/web3-eth/interface/TransactionMiddleware) interface, which specifies one function: [`processTransaction`](/api/web3-eth/interface/TransactionMiddleware#processTransaction). Here is a simple example of transaction middleware that prints transaction data to the console:
279+
280+
```ts
281+
export class TxnMiddleware implements TransactionMiddleware {
282+
public async processTransaction(
283+
transaction: TransactionMiddlewareData
284+
): Promise<TransactionMiddlewareData> {
285+
const txObj = { ...transaction };
286+
console.log("Transaction data:", txObj);
287+
return Promise.resolve(txObj);
288+
}
289+
}
290+
```
291+
292+
To add transaction middleware to a plugin, use the [`Web3Eth.setTransactionMiddleware`](/api/web3-eth/class/Web3Eth#setTransactionMiddleware) method in the plugin's `link` method as demonstrated below:
293+
294+
```ts
295+
public link(parentContext: Web3Context): void {
296+
(parentContext as any).Web3Eth.setTransactionMiddleware(
297+
new TxnMiddleware()
298+
);
299+
super.link(parentContext);
300+
}
301+
```
302+
236303
## Setting Up Module Augmentation
237304

238305
In order to provide type safety and IntelliSense for your plugin when it's registered by the user, you must [augment](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation) the `Web3Context` module. In simpler terms, you will be making TypeScript aware that you are modifying the interface of the class `Web3Context`, and any class that extends it, to include the interface of your plugin (i.e. your plugin's added methods, properties, etc.). As a result, your plugin object will be accessible within a namespace of your choice, which will be available within any `Web3Context` object.

packages/web3-errors/CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ Documentation:
172172

173173
- Added `InvalidIntegerError` error for fromWei and toWei (#7052)
174174

175-
## [Unreleased]
175+
## [1.2.1]
176176

177177
### Fixed
178178

179-
- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905)
179+
- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905)
180+
181+
## [Unreleased]

packages/web3-errors/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web3-errors",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "This package has web3 error classes",
55
"main": "./lib/commonjs/index.js",
66
"module": "./lib/esm/index.js",
@@ -41,7 +41,7 @@
4141
"test:integration": "jest --config=./test/integration/jest.config.js --passWithNoTests"
4242
},
4343
"dependencies": {
44-
"web3-types": "^1.6.0"
44+
"web3-types": "^1.7.0"
4545
},
4646
"devDependencies": {
4747
"@types/jest": "^28.1.6",

packages/web3-eth/CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,11 @@ Documentation:
262262

263263
- Fixed geth issue when running a new instance, transactions will index when there are no blocks created (#7098)
264264

265-
## [Unreleased]
265+
## [4.8.2]
266266

267267
### Fixed
268268

269-
- Adds transaction property to be an empty list rather than undefined when no transactions are included in the block (#7151)
269+
- Adds transaction property to be an empty list rather than undefined when no transactions are included in the block (#7151)
270+
- Change method `getTransactionReceipt` to not be casted as `TransactionReceipt` to give proper return type (#7159)
271+
272+
## [Unreleased]

packages/web3-eth/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web3-eth",
3-
"version": "4.8.1",
3+
"version": "4.8.2",
44
"description": "Web3 module to interact with the Ethereum blockchain and smart contracts.",
55
"main": "./lib/commonjs/index.js",
66
"module": "./lib/esm/index.js",
@@ -64,7 +64,7 @@
6464
"dependencies": {
6565
"setimmediate": "^1.0.5",
6666
"web3-core": "^4.5.0",
67-
"web3-errors": "^1.2.0",
67+
"web3-errors": "^1.2.1",
6868
"web3-eth-abi": "^4.2.3",
6969
"web3-eth-accounts": "^4.1.3",
7070
"web3-net": "^4.1.0",

packages/web3-eth/src/rpc_method_wrappers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,13 @@ export async function getTransactionReceipt<ReturnFormat extends DataFormat>(
521521
}
522522

523523
}
524-
525524
return isNullish(response)
526525
? response
527526
: (format(
528527
transactionReceiptSchema,
529528
response as unknown as TransactionReceipt,
530529
returnFormat ?? web3Context.defaultReturnFormat,
531-
) as TransactionReceipt);
530+
));
532531
}
533532

534533
/**

packages/web3/CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,21 @@ Documentation:
419419

420420
- `web3.eth.Contract` will get transaction middleware and use it, if `web3.eth` has transaction middleware. (#7138)
421421

422+
## [4.11.1]
423+
424+
### Fixed
425+
426+
#### web3-errors
427+
428+
- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905)
429+
430+
#### web3-eth
431+
432+
- Adds transaction property to be an empty list rather than undefined when no transactions are included in the block (#7151)
433+
- Change method `getTransactionReceipt` to not be casted as `TransactionReceipt` to give proper return type (#7159)
434+
435+
#### web3
436+
437+
- Remove redundant constructor of contractBuilder (#7150)
438+
422439
## [Unreleased]

packages/web3/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web3",
3-
"version": "4.11.0",
3+
"version": "4.11.1",
44
"description": "Ethereum JavaScript API",
55
"main": "./lib/commonjs/index.js",
66
"module": "./lib/esm/index.js",
@@ -87,8 +87,8 @@
8787
},
8888
"dependencies": {
8989
"web3-core": "^4.5.0",
90-
"web3-errors": "^1.2.0",
91-
"web3-eth": "^4.8.1",
90+
"web3-errors": "^1.2.1",
91+
"web3-eth": "^4.8.2",
9292
"web3-eth-abi": "^4.2.3",
9393
"web3-eth-accounts": "^4.1.3",
9494
"web3-eth-contract": "^4.6.0",

packages/web3/src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/* eslint-disable header/header */ export const Web3PkgInfo = { version: '4.11.0' };
1+
/* eslint-disable header/header */ export const Web3PkgInfo = { version: '4.11.1' };

0 commit comments

Comments
 (0)