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
{{ message }}
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: docs/docs/guides/web3_plugin_guide/plugin_authors.md
+18-10Lines changed: 18 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,14 +13,18 @@ To provide type safety and IntelliSense for your plugin users, please refer to t
13
13
14
14
## Plugin Dependencies
15
15
16
-
At the minimum, your plugin should depend on the `4.x` version of `web3`. This will allow your plugin class to extend the provided `Web3PluginBase` abstract class. However, `web3` shouldn't be listed as a regular dependency, instead it should be listed in your plugin's `package.json` as a [peer dependency](https://nodejs.org/en/blog/npm/peer-dependencies/):
16
+
At the minimum, your plugin should depend on `web3` package version `4.0.2`. This will allow your plugin class to extend the provided `Web3PluginBase` abstract class. However, `web3` shouldn't be listed as a regular dependency, instead it should be listed in your plugin's `package.json` as a [peer dependency](https://nodejs.org/en/blog/npm/peer-dependencies/).
@@ -210,9 +214,9 @@ public link(parentContext: Web3Context) {
210
214
211
215
## Setting Up Module Augmentation
212
216
213
-
To ensure type safety and enable IntelliSense for your plugin (which still needs to be registered by the user), you must augment the `Web3Context`class inside the `web3`module. In simpler terms, this is to modify the `Web3Context` class, and any inheriting classes, to make your plugin's functionality accessible from within. As a result, your plugin object will be accessible within a namespace of your choice, which will be available within any `Web3Context` object.
217
+
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.
214
218
215
-
For a general understanding of Module Augmentation, you can refer to [this tutorial](https://www.digitalocean.com/community/tutorials/typescript-module-augmentation).
219
+
A good tutorial that further explains Module Augmentation, in general, can be found [here](https://www.digitalocean.com/community/tutorials/typescript-module-augmentation).
216
220
217
221
### Module Augmentation
218
222
@@ -245,16 +249,16 @@ declare module 'web3' {
245
249
1. By augmenting `Web3Context` (and, by extension, all the classes that extend it), your plugin's interface will show up in things like IntelliSense for **all** Web3 modules that extend `Web3Context`, even if your plugin isn't registered.
246
250
This is something worth making your users aware of, as they'll only be able to use your plugin if they register it with a Web3 class instance using `.registerPlugin`.
247
251
248
-
:::warning
252
+
:::danger
249
253
250
-
The following represent what your **plugin users** would see, when they use the plugin `CustomRpcMethodsPlugin`, without calling `.registerPlugin`:
254
+
The following represent what your **plugin users** would see, when they use the plugin `CustomRpcMethodsPlugin`, without calling `.registerPlugin`:
The above screenshot shows IntelliSense thinking `.customRpcMethods.someMethod` is available to call on the instance of `Web3`, regardless if the plugin user registered or did not register `CustomRpcMethodsPlugin`.
255
-
But, the user who does not call `.registerPlugin`, before accessing your plugin, would face an error. And you need to make it clear for them that they need to call `.registerPlugin`, before they can access any plugin functionality.
258
+
The above screenshot shows IntelliSense thinking `.customRpcMethods.someMethod` is available to call on the instance of `Web3`, regardless if the plugin user registered or did not register `CustomRpcMethodsPlugin`.
259
+
But, the user who does not call `.registerPlugin`, before accessing your plugin, would face an error. And you need to make it clear for them that they need to call `.registerPlugin`, before they can access any plugin functionality.
256
260
257
-
:::
261
+
:::
258
262
259
263
2. The `registerPlugin` method exists on the `Web3Context` class, so any class that `extends Web3Context` has the ability to add your plugin's additional functionality to its interface. So, by augmenting `Web3Context` to include your plugin's interface, you're essentially providing a blanket augmentation that adds your plugin's interface to **all** Web3 modules that extend `Web3Context` (i.e. `web3`, `web3-eth`, `web3-eth-contract`, etc.).
260
264
@@ -298,3 +302,7 @@ declare module 'web3' {
298
302
// on the instance of Web3
299
303
web3.customRpcMethods;
300
304
```
305
+
306
+
## CompleteExample
307
+
308
+
Youmayfindithelpfultoreferenceacompleteexamplefordevelopingandusingaweb3plugin. The [Web3.jsChainlinkPlugin](https://github.com/ChainSafe/web3.js-plugin-chainlink/) repository provides an excellent example which you can check out.
Copy file name to clipboardExpand all lines: docs/docs/guides/web3_plugin_guide/plugin_users.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,14 +9,14 @@ This guide intends to provide the necessary context for registering plugins with
9
9
10
10
## Installing the Plugin
11
11
12
-
Unless otherwise mentioned by the plugin author, installing a plugin should be as simple as `yarn add web3-sample-plugin`. This should add the plugin as a dependency within your `package.json` and the plugin should be available to import within your code.
12
+
Unless otherwise mentioned by the plugin author, installing a plugin should be as simple as `yarn add web3-plugin-example`. This should add the plugin as a dependency within your `package.json` and the plugin should be available to import within your code.
13
13
14
14
```json
15
15
# package.json
16
16
{
17
17
...
18
18
"dependencies": {
19
-
"web3-sample-plugin": "0.1.0"
19
+
"web3-plugin-example": "0.1.0"
20
20
}
21
21
}
22
22
```
@@ -32,8 +32,8 @@ For illustration purposes, let's assume a plugin developer has the following cod
32
32
33
33
import { Web3PluginBase } from'web3';
34
34
35
-
exportclassSamplePluginextendsWeb3PluginBase {
36
-
public pluginNamespace ='samplePlugin';
35
+
exportclassPluginExampleextendsWeb3PluginBase {
36
+
public pluginNamespace ='pluginExample';
37
37
38
38
public sampleMethod() {
39
39
return'simpleValue';
@@ -43,21 +43,21 @@ export class SamplePlugin extends Web3PluginBase {
43
43
// Module Augmentation
44
44
declaremodule'web3' {
45
45
interfaceWeb3Context {
46
-
samplePlugin:SamplePlugin;
46
+
pluginExample:PluginExample;
47
47
}
48
48
}
49
49
```
50
50
51
-
Here is an example of how to register the `SamplePlugin` onto an instance of `Web3`:
51
+
Here is an example of how to register the `PluginExample` onto an instance of `Web3`:
0 commit comments