Skip to content

Commit

Permalink
Merge branch '4.x' into format-files
Browse files Browse the repository at this point in the history
  • Loading branch information
luu-alex committed Sep 9, 2024
2 parents 7517ec6 + 27155ea commit 98c1491
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 105 deletions.
40 changes: 22 additions & 18 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2458,7 +2458,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-errors

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

#### web3-eth

Expand All @@ -2484,8 +2484,8 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-utils

- `toWei` add warning when using large numbers or large decimals that may cause precision loss (#6908)
- `toWei` and `fromWei` now supports integers as a unit. (#7053)
- `toWei` add warning when using large numbers or large decimals that may cause precision loss (#6908)
- `toWei` and `fromWei` now supports integers as a unit. (#7053)

### Fixed

Expand All @@ -2495,13 +2495,13 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-utils

- `toWei` support numbers in scientific notation (#6908)
- `toWei` and `fromWei` trims according to ether unit successfuly (#7044)
- `toWei` support numbers in scientific notation (#6908)
- `toWei` and `fromWei` trims according to ether unit successfuly (#7044)

#### web3-validator

- The JSON schema conversion process now correctly assigns an id when the `abi.name` is not available, for example, in the case of public mappings. (#6981)
- `browser` entry point that was pointing to an non-existing bundle file was removed from `package.json` (#7015)
- The JSON schema conversion process now correctly assigns an id when the `abi.name` is not available, for example, in the case of public mappings. (#6981)
- `browser` entry point that was pointing to an non-existing bundle file was removed from `package.json` (#7015)

#### web3-core

Expand Down Expand Up @@ -2600,7 +2600,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-eth-accounts

- baseTransaction method updated (#7095)
- baseTransaction method updated (#7095)

#### web3-providers-ws

Expand All @@ -2612,7 +2612,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-rpc-providers

- Change request return type `Promise<ResultType>` to `Promise<JsonRpcResponseWithResult<ResultType>>` (#7102)
- Change request return type `Promise<ResultType>` to `Promise<JsonRpcResponseWithResult<ResultType>>` (#7102)

### Added

Expand All @@ -2623,7 +2623,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-rpc-providers

- When error is returned with code 429, throw rate limit error (#7102)
- When error is returned with code 429, throw rate limit error (#7102)

#### web3

Expand All @@ -2635,7 +2635,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-errors

- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905)
- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905)

#### web3-eth

Expand All @@ -2646,7 +2646,6 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

- Remove redundant constructor of contractBuilder (#7150)


## [4.12.0]

### Fixed
Expand All @@ -2657,7 +2656,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-eth-accounts

- Fix `TransactionFactory.registerTransactionType` not working, if there is a version mistatch between `web3-eth` and `web3-eth-accounts` by saving `extraTxTypes` at `globals`. (#7197)
- Fix `TransactionFactory.registerTransactionType` not working, if there is a version mistatch between `web3-eth` and `web3-eth-accounts` by saving `extraTxTypes` at `globals`. (#7197)

### Added

Expand All @@ -2667,11 +2666,11 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-eth-contract

- Added `populateTransaction` to the `contract.deploy(...)` properties. (#7197)
- Added `populateTransaction` to the `contract.deploy(...)` properties. (#7197)

#### web3-providers-http

- Added `statusCode` of response in ResponseError, `statusCode` is optional property in ResponseError.
- Added `statusCode` of response in ResponseError, `statusCode` is optional property in ResponseError.

#### web3-rpc-providers

Expand All @@ -2680,21 +2679,26 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-errors

- Added optional `statusCode` property of response in ResponseError.
- Added optional `statusCode` property of response in ResponseError.

### Changed

#### web3-eth-contract

- The returnred properties of `contract.deploy(...)` are structured with a newly created class named `DeployerMethodClass`. (#7197)
- Add a missed accepted type for the `abi` parameter, at `dataInputEncodeMethodHelper` and `getSendTxParams`. (#7197)
- Add a missed accepted type for the `abi` parameter, at `dataInputEncodeMethodHelper` and `getSendTxParams`. (#7197)

## [4.12.1]

### Fixed

#### web3-eth-accounts

- Revert `TransactionFactory.registerTransactionType` if there is a version mistatch between `web3-eth` and `web3-eth-accounts` and fix nextjs problem. (#7216)
- Revert `TransactionFactory.registerTransactionType` if there is a version mistatch between `web3-eth` and `web3-eth-accounts` and fix nextjs problem. (#7216)

#### web3

- `Web3.providers` namespace exports `type EIP6963ProviderResponse = Map<string, EIP6963ProviderDetail>`. Return type for the static `Web3.requestEIP6963Providers` is now `Promise<EIP6963ProviderResponse>`. (#7239)
- The callback function provided to the static `Web3.onNewProviderDiscovered` function expects a parameter of type `EIP6963ProvidersMapUpdateEvent` as opposed to `EIP6963AnnounceProviderEvent`. (#7242)

## [Unreleased]
130 changes: 64 additions & 66 deletions docs/docs/guides/advanced/custom_RPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import TabItem from '@theme/TabItem';
Web3.js is a popular library for interacting with the Ethereum blockchain. It provides a set of APIs to interact with Ethereum nodes via JSON-RPC calls. For adding new JSON-RPC function calls to the library, you can do so using the plugin feature in web3.js 4.x. This allows you to extend the functionality of Web3.js and add support for new JSON-RPC methods.

:::caution
In Web3.js 1.x, `web3.extend()` function could be used to add new JSON-RPC methods. `web3.extend()` is also available in Web3 v4.0.4+ with some breaking changes. However it is recommended to use Web3 Plugin feature for extending web3 functionality if you are developing new feature.
In Web3.js 1.x, `web3.extend()` function could be used to add new JSON-RPC methods. `web3.extend()` is also available in Web3 v4.0.4+ with some breaking changes. However it is recommended to use Web3 Plugin feature for extending web3 functionality if you are developing new feature. Read the ["Extending Web3.js"](/guides/advanced/extend) guide to learn more about the legacy `web3.extend()` method.
:::

Following tutorial will guide you through the process of creating a custom plugin to extend the functionality of web3.js 4.x and add support for new RPC methods.
Expand All @@ -30,16 +30,16 @@ This will give your plugin access to [requestManager](/api/web3-core/class/Web3C

<Tabs groupId='prog-lang' queryString>

<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>
<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>

```javascript
const { Web3PluginBase } = require('web3');

//highlight-start
class CustomRpcMethodsPlugin extends Web3PluginBase {
// step 1
// ...
// step 1
// ...
}
//highlight-end

Expand All @@ -56,8 +56,8 @@ import { Web3PluginBase } from 'web3';

//highlight-start
export default class CustomRpcMethodsPlugin extends Web3PluginBase {
// step 1
// ...
// step 1
// ...
}
//highlight-end
```
Expand All @@ -69,19 +69,18 @@ export default class CustomRpcMethodsPlugin extends Web3PluginBase {

2. After that add public `pluginNamespace` property. This will be used to access your plugin, as mentioned in step number 5 code example.


<Tabs groupId='prog-lang' queryString>

<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>
<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>

```javascript
const { Web3PluginBase } = require('web3');

class CustomRpcMethodsPlugin extends Web3PluginBase {
//highlight-start
pluginNamespace = 'customRpcMethods'; // step 2
//highlight-end
//highlight-start
pluginNamespace = 'customRpcMethods'; // step 2
//highlight-end
}

module.exports = CustomRpcMethodsPlugin;
Expand All @@ -96,40 +95,39 @@ module.exports = CustomRpcMethodsPlugin;
import { Web3PluginBase } from 'web3';

export default class CustomRpcMethodsPlugin extends Web3PluginBase {
//highlight-start
public pluginNamespace = 'customRpcMethods'; // step 2
//highlight-end
//highlight-start
public pluginNamespace = 'customRpcMethods'; // step 2
//highlight-end
}
```

</TabItem>
</Tabs>


### Step 3: Creating Custom RPC Methods in the Plugin Class

3. Once plugin class is created using above mentioned steps, its very easy to add new RPC methods like:

<Tabs groupId='prog-lang' queryString>

<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>
<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>

```javascript
const { Web3PluginBase } = require('web3');

class CustomRpcMethodsPlugin extends Web3PluginBase {
pluginNamespace = 'customRpcMethods';
pluginNamespace = 'customRpcMethods';

//highlight-start
async customRpcMethod() {
// step 3
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
async customRpcMethod() {
// step 3
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
//highlight-end
}

Expand All @@ -145,18 +143,18 @@ module.exports = CustomRpcMethodsPlugin;
import { Web3PluginBase } from 'web3';

export default class CustomRpcMethodsPlugin extends Web3PluginBase {
public pluginNamespace = 'customRpcMethods';

//highlight-start
public async customRpcMethod() {
// step 3
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
//highlight-end
public pluginNamespace = 'customRpcMethods';

//highlight-start
public async customRpcMethod() {
// step 3
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
//highlight-end
}
```

Expand All @@ -169,22 +167,22 @@ export default class CustomRpcMethodsPlugin extends Web3PluginBase {

<Tabs groupId='prog-lang' queryString>

<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>
<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>

```javascript
const { Web3PluginBase } = require('web3');

class CustomRpcMethodsPlugin extends Web3PluginBase {
pluginNamespace = 'customRpcMethods';

async customRpcMethod() {
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
pluginNamespace = 'customRpcMethods';

async customRpcMethod() {
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
}

module.exports = CustomRpcMethodsPlugin;
Expand All @@ -199,25 +197,25 @@ module.exports = CustomRpcMethodsPlugin;
import { Web3PluginBase } from 'web3';

export default class CustomRpcMethodsPlugin extends Web3PluginBase {
public pluginNamespace = 'customRpcMethods';

public async customRpcMethod() {
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
public pluginNamespace = 'customRpcMethods';

public async customRpcMethod() {
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
}

//highlight-start
// Module Augmentation
declare module 'web3' {
// step 4
// step 4

interface Web3Context {
customRpcMethods: CustomRpcMethodsPlugin;
}
interface Web3Context {
customRpcMethods: CustomRpcMethodsPlugin;
}
}
//highlight-end
```
Expand All @@ -237,8 +235,8 @@ Once plugin is registered its custom methods will be available to use.

<Tabs groupId='prog-lang' queryString>

<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>
<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>

```javascript
const { Web3 } = require('web3');
Expand Down
Loading

0 comments on commit 98c1491

Please sign in to comment.