extension-provider icon indicating copy to clipboard operation
extension-provider copied to clipboard

Fix sample extension

Open danfinlay opened this issue 4 years ago • 7 comments

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.

danfinlay avatar Sep 30 '20 16:09 danfinlay

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

mohsinaliryk avatar Apr 01 '21 11:04 mohsinaliryk

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

toki-sean avatar May 15 '21 00:05 toki-sean

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.

artem-bayandin avatar Oct 02 '21 09:10 artem-bayandin

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

cryptoKevinL avatar May 07 '22 20:05 cryptoKevinL

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

ogiste avatar Mar 09 '23 08:03 ogiste

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.

bug-author avatar Apr 30 '24 13:04 bug-author

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

Is this still an issue with the new version?

legobeat avatar May 29 '24 21:05 legobeat