MetaMask / MetaMask/metamask-mobile

'ethereum#initialized' event is not triggered by metamask android app.

Open
#3,118 3 comments 2 reactions 0 assignees View on GitHub
community
Dominant language
TypeScript
Stars
3k
Forks
1.7k
Avg merge
1d 14h
Merged PRs (30d)
669

Description

The 'ethereum#initialized' event is not triggered on Android inside the metamask app. Works fine in browser. Dapp code below:

```
var provider = null;
var user = null;
var contract = null;

if (window.ethereum) {
setup();
} else {
window.addEventListener('ethereum#initialized', setup, {
once: true,
});
setTimeout(setup, 30000); // 30 seconds in which nothing happens on android
}

function setup() {
$('#network').html("starting connection..."); // this is only displayed after 30 seconds
const {ethereum} = window;
ethereum.on('chainChanged', (_chainId) => window.location.reload());
const newAccounts = ethereum.request({method: 'eth_requestAccounts'});
provider = new ethers.providers.Web3Provider(ethereum, 'any');
provider.getNetwork().then((chain) => {$('#network').html(chain.name);});
//++ const openProvider = new opencontracts.providers.Web3Provider(provider);
user = provider.getSigner();
}
```
Same issue with @metamask/detect-provider.

_Originally posted by @open-contracts in https://github.com/MetaMask/metamask-mobile/issues/1975#issuecomment-917527245_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the ethereum#initialized flow in the MetaMask Android app using the provided setup() snippet, then compare it with browser behavior and @metamask/detect-provider. Trace the mobile provider initialization entry point and determine whether the event is emitted; done means the event or provider detection behaves consistently on Android without relying on the 30-second timeout.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, javascript, react-native, typescript
Domain
blockchain, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.