extension-provider
extension-provider copied to clipboard
Fix sample extension
The sample extension has not been updated since we made some changes to the underlying transport. Should be fairly simple and could facilitate more external extension interactions.
The sample extension has not been updated since we made some changes to the underlying transport. Should be fairly simple and could facilitate more external extension interactions.
Can you explain how to get account information using extension provider. I'm receiving empty array
We're also facing the same issue as @mohsinaliryk . Thanks!
Still empty array.
I'm trying to create a Chrome extension and use MM.
Tried to get user accounts by eth.accounts
(etherjs), web3.accounts
(web3js), MetaMaskInpageProvider.request({method:'eth_accounts'})
- all return an empty array and a warning saying ObjectMultiplex - orphaned data for stream "publicConfig"
[update]
Well, I think I've found at least entry point to happily communicate with MM extension, so that MM extension got opened, I can authorize, and receive an array of 1 element, which is current accountId
file 'myService.js':
const createMetaMaskProvider = require('metamask-extension-provider')
const Web3 = require('web3')
const web3Provider = createMetaMaskProvider()
const web3 = new Web3(web3Provider)
export { web3, web3Provider }
file 'App.js':
import React, { useState } from 'react'
import { web3, web3Provider } from './services/web3provider'
export const App = () => {
const [ account, setAccount ] = useState()
const login = (e) => {
e.preventDefault()
web3Provider
.enable()
.then(loadAccounts)
}
const loadAccounts = () => {
web3
.eth
.getAccounts()
.then(accounts => {
if (accounts && accounts.length) {
setAccount(accounts[0])
} else {
setAccount(null)
}
})
}
return (
<div>
{ account && <div>account: {account}</div> }
{ !account && <div onClick={login}>login</div> }
</div>
)
}
[update2]
As MM suggests, you might use await provider.request({method: 'eth_requestAccounts'})
instead of await provider.enable()
- and it works, I have just tested.
Would it be possible to update the example so this works after a git clone of the repo? I'm seeing the same error.
Faced a similar problem recently trying to connect to metamask from an extension project we're building. Any help here would be greatly appreciated!
Facing the same problem, it was working fine but when I started porting the code to my own repo now I dont get any accounts and this warning.
[email protected]
has just been published and with a rebuilt sample.
Is this still an issue with the new version?