Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sample extension #13

Open
danfinlay opened this issue Sep 30, 2020 · 7 comments
Open

Fix sample extension #13

danfinlay opened this issue Sep 30, 2020 · 7 comments

Comments

@danfinlay
Copy link
Contributor

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.

@mohsinaliryk
Copy link

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

@toki-sean
Copy link

We're also facing the same issue as @mohsinaliryk . Thanks!

@artem-bayandin
Copy link

artem-bayandin commented Oct 2, 2021

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.

@cryptoKevinL
Copy link

Would it be possible to update the example so this works after a git clone of the repo? I'm seeing the same error.

@ogiste
Copy link

ogiste commented Mar 9, 2023

Faced a similar problem recently trying to connect to metamask from an extension project we're building. Any help here would be greatly appreciated!

@bug-author
Copy link

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.

@legobeat
Copy link
Contributor

[email protected] has just been published and with a rebuilt sample.

Is this still an issue with the new version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants