I am thinking to create a chrome extension that requires logging in to a crypto wallet.
Is it possible?
I am thinking to create a chrome extension that requires logging in to a crypto wallet.
Is it possible?
I think that it should be possible, but I donât know on what problems you will get down the line
The problem which I am currently facing is
âUncaught ReferenceError: Moralis is not definedâ
As external scripts are allowed in the chrome extension.
Just searched on google and found this: https://stackoverflow.com/questions/7781851/loading-external-javascript-in-google-chrome-extension
donât know if it helps
It seems to load the scripts the from the web paths. but for some reason it is showing me the same error.
I may have to explore other ways
hmm it could work with walletconnect (i doubt it will work with metamask as its plugin calling another plugin which i think doesnt work in chrome)
we havent tested this so you are first explorer
Hi all,
I managed to call metamask from an other chrome extension using this: https://github.com/DimensionDev/extension-provider
However, when I integrate Moralis, I got the error
âNon ethereum enabled browserâ.
I think itâs because Im not running Moralis through a live server, problem is: client side, chrome extensions are not running through live serverâŚ
So my question is: do you know how to directly pass the injected web3 provider object, or account, to Moralis in order to login and get Moralis user object, instead of calling Moralis.authenticate() ? I need moralis user id and moralis username associated with the account in order for my app to work. Thanks a lot !
you may be able to do a custom function for the provider: https://docs.moralis.io/moralis-server/users/crypto-login#custom-wallet-login
Did you find a working solution for this?
Can you provide some more hints? I guess you are referring to:
const web3Provider = await Moralis.enableWeb3();
How can we login with Metamask using the web3Provider directly instead of using Moralis.authenticate()?
it may be different now with latest SDK update: Moralis JS-SDK v1.0.0 [beta] (Ethers.js support)
there was setEnableWeb3 function in the past
Can you provide some insight, on why a custom function would work better for Metamask? Than the one already provided? The problem here:
Is that window.ethereum is not available in the context of a chrome plugin.
âyou may be able to do a custom function for the providerâ
Do you think this will solve the problem with MetaMask?
I donât know if it will solve it, for some wallets you could use a custom function
SOLVED. I will need a few days to put together a working example, but I am now able to communicate with MetaMask extension from my extension using a Custom Function for the provider.
This is how to do it.
You will need to use browserify to compile your plugin.
class customConnector extends Moralis.AbstractWeb3Connector {
async activate() {
const provider = createMetaMaskProvider();
if (!provider) {
console.error("MetaMask provider not detected.");
throw new Error("MetaMask provider not detected.");
}
const [accounts, chainId] = await Promise.all([
provider.request({
method: 'eth_requestAccounts',
}),
provider.request({ method: 'eth_chainId' }),
]);
const account = accounts[0] ? accounts[0].toLowerCase() : null;
this.chainId = provider.chainId;
this.account = provider.selectedAddress;
this.provider = provider;
this.subscribeToEvents(provider);
return { provider, chainId, account };
}
}
Moralis.authenticate({ connector: customConnector })