i am using React with moralis and i want to integrate web3. I want to include two options like connect with metamask and connect with portis in my Dapp how do i provide custom provider and the moralis examples with react are very less.
Hey @PRATIK
I’m not sure is there a way to connect a Portis wallet.
Here is an example of using WalletConnect provider:
authenticate({ provider: "walletconnect" })
WallectConnect supports a lot of wallets. Take a look at Suported Wallets WallectConnect
Hope it will help you
It’s not There I will find a Way to do that if I found a solution then will definitely share it with the forum.
I found a Solution Using Custom Wallet Docs in the moralis docs.
Hey @Yomoo
I was looking into the same thing and according to Moralis Docs to add custom wallet, you have overwrite Moralis.Web3.enable
. I wanted to add the options for both MetaMask and a custom wallet but once Moralis.Web3.enable
is overwritten, you can’t use metamask.
Is there a workaround for it, or am I missing something out?
I’m using Moralis along side react-moralis and I have a modal with two buttons, one for metamask and one for portis.
For metamask, I’m simply using authenticate
method from useMoralis
react hook.
This particular part handles the onClick
event for portis.
const handlePortis = async () => {
class MoralisPortisProvider {
async activate() {
const portis = new Portis(
'portis dapp id',
'maticMumbai'
);
this.provider = portis.provider;
const MWeb3 = typeof Web3 === 'function' ? Web3 : window.Web3;
this.web3 = new MWeb3(this.provider);
this.isActivated = true;
return this.web3;
}
}
// Global Moralis object overwritten
Moralis.Web3.enable = async () => {
const web3Provider = new MoralisPortisProvider();
const web3 = await web3Provider.activate();
console.log('RUNNING');
console.log('WEB3', web3);
const accounts = await web3.eth.getAccounts();
console.log(accounts);
return web3;
};
enableWeb3();
authenticate();
};
Once the Moralis.Web3.enable
is overwritten, it would only use Portis as it’s provider. So that’s the issue I have been facing. Is there any way, to restore the Moralis.Web3.enable
to it’s initial value.
Hi @PRATIK
I’s a bit difficuilt to test it without a full code
But i think you can use the solution from this topic Disconnect a web3 wallet [Solved]
window.Moralis.Web3.cleanup();
or
Moralis.Web3.cleanup();
Let me know how it will work for you
If you will have any difficulties, share the full code, I will help