javascriptgoogle-chrome-extensionethereummetamaskbrave

What is Metamask's ethereum.window object?


So I'm developing a chrome extension blockchain wallet just like metamask. The extension communicates with webpages to sign transactions and stuff. Metamask does this by injecting a window.ethereum object in the browser's global API. I'm trying to do the same. I've successfuilly managed to inject the window.ethereum object.

The problem is that my window.ethereum object is not the same as Metamask's window.ethereum object. Which is why dapps built using web3.js and ethers.js library cannot connect to it.

How can I build that window.ethereum object the same way Metamask does it? Is there any documentation provided by Metamask or ethers js on it? Is there any other way or better way to do this?

What I'm doing: -> Using react js to build popup scripts. Writing content scripts in vanilla js. Using content script to inject inject.js script in webpage's DOM. Declaring window.ethereum object in inject.js.

What I want: -> Metamask's window.ethereum object log.

Thanks in advance.


Solution

  • MetaMask states in their docs that the extension implements the EIP-1193: Ethereum Provider JavaScript API.

    It's a standardized set of rules (properties, methods, behavior) that your browser extension needs to implement in order to be able to communicate with EIP-1193 wrappers such as ethers.js.