web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

Example Plugin Implementation

Open spacesailor24 opened this issue 2 years ago • 11 comments

Example implementation for #5091

Points of Discussion

  • I believe the Web3APISpec on this line should be ChainlinkPluginAPI, but when making the change the following error appears for this
Argument of type 'this' is not assignable to parameter of type 'Web3Context<EthExecutionAPI, { logs: typeof LogsSubscription; newHeads: typeof NewHeadsSubscription; newBlockHeaders: typeof NewHeadsSubscription; }>'.
  Type 'ChainlinkPlugin' is not assignable to type 'Web3Context<EthExecutionAPI, { logs: typeof LogsSubscription; newHeads: typeof NewHeadsSubscription; newBlockHeaders: typeof NewHeadsSubscription; }>'.
    Types of property '_requestManager' are incompatible.
      Type 'Web3RequestManager<ChainlinkPluginAPI>' is not assignable to type 'Web3RequestManager<EthExecutionAPI>'.
        Type 'ChainlinkPluginAPI' is missing the following properties from type 'EthExecutionAPI': eth_getBlockByHash, eth_getBlockByNumber, eth_getBlockTransactionCountByHash, eth_getBlockTransactionCountByNumber, and 44 more.ts(2345)
  • ~In order to get the declare module to work, I needed to update the Web3 package from using the default export to a named one - I'm not sure if/how this affects anything~ This commit updates Web3 to be exported using default and named export
    • ~Related to this change, importing Web3 like this is the only way I could get the module augmentation to work~ The above mentioned commit also updates this to use web3 to augment module instead of web3/dist/web3
  • The return type for getPrice is inferred from the contract ABI instead of ChainlinkPluginAPI
    • This doesn't matter so much because the type the end user will see when calling web3.chainlink.getPrice is defined by ChainlinkPluginAPI (i.e. user will see getPrice returns Promise<Price>)

spacesailor24 avatar Aug 30 '22 02:08 spacesailor24

Your Render PR Server URL is https://web3js-docs-pr-5393.onrender.com.

Follow its progress at https://dashboard.render.com/static/srv-cc6n52pgp3jv8lhb6gb0.

render[bot] avatar Aug 30 '22 02:08 render[bot]

This pull request introduces 1 alert when merging d0d388b6f26b739d787653285f1ba8a88eb4fcfe into aeceed263c4b031e57ae32b5acd452b08a75a505 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

lgtm-com[bot] avatar Aug 30 '22 02:08 lgtm-com[bot]

This pull request introduces 1 alert when merging db296ff7f47723980cb520f2bf98340dde096803 into aeceed263c4b031e57ae32b5acd452b08a75a505 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

lgtm-com[bot] avatar Aug 30 '22 03:08 lgtm-com[bot]

This pull request introduces 1 alert when merging a2f43db59abaa84072894182af333dbfa2979011 into e2afb752b2e6fd0d8bec0b0dabe5c279415dc20c - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

lgtm-com[bot] avatar Aug 30 '22 17:08 lgtm-com[bot]

If we want to keep this as example for others to implement plugins, : web3-plugin-example example package should be placed under tools

@jdevcs My thinking was to create this package with unit and black box tests that can be ran as apart of our test suite for releases to verify the plugin system continues to work as expected. I could move this under tools/, but we'd have to setup Lerna and such to build and execute tests in tools/ and packages/

spacesailor24 avatar Aug 30 '22 19:08 spacesailor24

This pull request introduces 1 alert when merging 9b4896e5cacc8e83b93999cc16492813389f38d5 into a804401e2177dc76b87f5f20bf54460f93978239 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

lgtm-com[bot] avatar Aug 30 '22 19:08 lgtm-com[bot]

This pull request introduces 1 alert when merging dc36d4b087c011516a5b8a19da8d71148e845fb4 into a804401e2177dc76b87f5f20bf54460f93978239 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

lgtm-com[bot] avatar Aug 30 '22 20:08 lgtm-com[bot]

This pull request introduces 1 alert when merging 755d6d65fb490493b3fbf529589f27069e6e7f59 into 37219fc114ce4d53387b7b9626358b12f4eaa3c6 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

lgtm-com[bot] avatar Sep 01 '22 01:09 lgtm-com[bot]

This pull request introduces 1 alert when merging 103683687341718ab4adc280c82276562b1db1bc into 37219fc114ce4d53387b7b9626358b12f4eaa3c6 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

lgtm-com[bot] avatar Sep 01 '22 12:09 lgtm-com[bot]

Hello @spacesailor24, I opened an MR (https://github.com/ChainSafe/web3.js/pull/5416) for addressing the discussion points mentioned at #5393 (comment). More details are at its description. Please feel free to check and discuss. Thanks,

Muhammad-Altabba avatar Sep 06 '22 17:09 Muhammad-Altabba

@spacesailor24 this PR is still draft and waiting from few sprints, are there any pending items or required discussion?

jdevcs avatar Sep 20 '22 10:09 jdevcs

Please check that this PR is not causing any actions failing in CI.+ Just need some minor changes, and we can merge this PR.

As discussed in call for remaining bugs, improvements and more features we should do in another PR.

jdevcs avatar Oct 06 '22 18:10 jdevcs

Please check that this PR is not causing any actions failing in CI.+ Just need some minor changes, and we can merge this PR.

As discussed in call for remaining bugs, improvements and more features we should do in another PR.

@jdevcs It looks like failing tests are related to a validation error in web-eth-contract that is unrelated to the changes introduced in this PR

spacesailor24 avatar Oct 11 '22 06:10 spacesailor24