I am trying to use a meta mask provider that allows me to connect to MetaMask from within a chrome extension. The wagmi libraries have changed and cannot see any example code of how to do this.
Am not sure if I need to use any of these:
LocalMessageDuplexStream
createExternalExtensionProvider
MetaMaskInPageProvider
Can anyone point me to some code for connecting a chrome extension to MetaMask.
Ultimately I would like Web3Modal from WalletConnect to find the provider.
Thank you for your time.
0xroo
October 3, 2023, 7:27am
2
Thanks for your answer.
In extension-provider/blob/master/index.js I see:
const metamaskPort = chrome.runtime.connect(currentMetaMaskId)
const pluginStream = new PortStream(metamaskPort)
The chrome namespace is not available in a tab application opened by the background script.
I want the wallet to connect to the extension address:
`chrome-extension://oahhaapnfpkfnbgeopliehfgenifngde/tab.html#register`
instead of the address that the content script happens to be in.
Can you advise how to do this?
0xroo
October 4, 2023, 6:32am
4
Hi @javaspeak sorry for delay, where this root is coming from extension-provider/blob/master/index.js
Sorry I do not understand your question or statement.
0xroo
October 4, 2023, 9:10am
6
I’m sorry I was asking where to find this file
It is the extension-provider github project:
https_github.com/MetaMask/extension-provider/blob/master/index.js
Do not have sufficient privileges to paste a link - do not know why (hence modified link)
0xroo
October 5, 2023, 5:39am
8
Is it possible for you to open an issue: Issues · MetaMask/extension-provider · GitHub
const { MetaMaskInpageProvider } = require('@metamask/inpage-provider')
const PortStream = require('extension-port-stream')
const { detect } = require('detect-browser')
const browser = detect()
const config = require('./config.json')
module.exports = function createMetaMaskProvider () {
let provider
try {
let currentMetaMaskId = getMetaMaskId()
const metamaskPort = chrome.runtime.connect(currentMetaMaskId)
const pluginStream = new PortStream(metamaskPort)
provider = new MetaMaskInpageProvider(pluginStream)
} catch (e) {
console.dir(`Metamask connect error `, e)
throw e
}
return provider
}
This file has been truncated. show original
Thank you Oxroosh. Have raised an issue:
https_github.com/MetaMask/extension-provider/issues/30
The link above is modified for it says new users do not have permissions to paste links.
0xroo
October 5, 2023, 7:31am
10
Thanks yes it’s a security thing thank you again
system
Closed
November 4, 2023, 7:31am
11
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.