Is it possible to develop chrome extensions with web3.js or Ethers.js?

Viewed 1300

I want to develop a ethereum wallet chrome extension.

While developing a simple prototype, I noticed that the node.js module cannot be run directly from the chrome extension.

But I must use web3.js or ethers.js.

Summary

Is there any way to develop Chrome extensions using web3.js or ethers.js?

1 Answers

Of course, when we check the packages of the MetaMask we will see both web3 & ethjs libraries which is also an extension:

// ...
    "web3": "^..."
// ...
    "ethjs": "^...",
    "ethjs-contract": "^...",
    "ethjs-ens": "^...",
    "ethjs-query": "^...",
// ...

What we might do either we can compile it via a tool like browserify or import the minified browser version like this(I tested it is working with metamask-extension-provider package*):

import Web3 from 'web3/dist/web3.min.js';

// or

const Web3 = require('web3/dist/web3.min.js');

*A specific version of provider for extensions, check its docs.

Related