My goal is to authenticate the user using their Metamask wallet. To achieve this, I am utilizing the web3 package for interacting with blockchain and signing transactions. However, I am encountering an issue where attempting to retrieve user accounts results in an empty response:
const Web3 = require('web3');
const web3 = new Web3(
new Web3.providers.HttpProvider('https://api.avax.network/ext/bc/C/rpc')
);
const addresses = await web3.eth.getAccounts();
I believe that I may need to request the accounts differently, such as
await window.ethereum.request({ method: 'eth_requestAccounts'});
, but the window
object does not exist in the mobile app.
In a typical scenario, the user would click an authentication button and then be redirected to their Metamask wallet to authorize the application. How can I accomplish this flow?