hi guys. I have a valid waletconnect connection, provider, and signer. However, my app already has {Moralis, enableWeb3, isAuthenticated, logout, deactivateWeb3 } = useMoralis(); in different pages, and I like using these hooks. but I would want to inject my custom connection into the moralis context what is the easiest way to go about this? Note: when I enableWeb3(provider:âwalletconnectâ) ,I always get rate limited because of how often walletconnect calls the speedy node URL. so ideally Iâm trying to inject my own connection with my own URL to prevent clogging the moralis default speedy node link.
You can use a custom connector in enableWeb3 similar to authenticate.
Moralis.enableWeb3({ connector: CustomConnector })
Hi @alex I checked out this method of yours, I am using the moralis-v1 SDK only in which this code is available. So can I use this custom WalletConnectWeb3Connector directly from SDK?
As I am not clear how to implement that code. @cryptokid @Yomoo
you can try to check the examples from documentation
https://v1docs.moralis.io/moralis-dapp/users/web3-login/custom-auth-any-eip1193-provider#example-implementations
There is an example here for using a custom connector. You can do something similar to the WalletConnect connector.
Hi @alex, thanks for the suggestion. I tried to implement the mentioned code in my dApp.
But I keep getting type errors and import errors.
My dApp(s) configuration Next JS+ TypeScript, React JS + TypeScript
âreactâ: â^18.2.0â,
ânextâ: â12.3.1â,
â@coinbase/wallet-sdkâ: â^3.6.2â,
âweb3â: â^1.8.1â,
âmoralisâ: â^2.9.0â,
âmoralis-v1â: â^1.11.0â,
âreact-moralisâ: â^1.4.2â,
other project related packages
Error 1: When trying to extend the Moralis?.AbstractWeb3Connector
I tried using moralis sdk and also moralis-v1 sdk, but none exports the AbstractWeb3Connector method and I keep getting type error. So I canât progress with this.
- I tried Passing the custom connector this way,
await Moralis.authenticate({connector: CoinbaseConnector});
TypeError: Type âtypeof CoinbaseWalletConnectorâ is missing the following properties from type âConnectorâ: type, network, account, chainId, and 2 more.
Connector type mentioned: interface Connector {
type: string;
network: string;
account: null | string;
chainId: null | string;
activate: () => Promise<{
provider: Provider;
account?: string | null;
chainId?: string | null;
}>;
deactivate: () => Promise;
[key: string]: any;
}
Please correct me where I am getting this wrong. My dApp is dependent upon the react-moralis âuseMoralisâ hook, so I am trying to work walletConnect/coinbase wallet in same way.
If you know some way by which I can get benefits of both the world like implementing separate authentication method and still able to use âuseMoralisâ please let me know. Thanks.
So you do want to use that particular Coinbase connector, not WalletConnect? Try ignoring the type issue first and see if it works like the demo - I believe that example should still work - make sure you change import Moralis from 'moralis'
to import Moralis from 'moralis-v1';
.
No I want the walletConnect to work, but I am not able to implement it as of now. So when I came across this implementation of yours, I thought let me try this, as this Coinbase connector also has walletConnect and metamask supported.
Okay I will try to ignore types and check if it works. Thanks.
Hi @alex as mentioned I disable typing and implemented coinbase as mentioned here and also implemented the custom wallet connector as per given moralis docs.
I am getting authenticated via both the methods but none updates the useMoralis hook that I am authenticated. And if I refresh the page, I get connected to browser injected metamask.
I am stuck in this loop and donât seem the way of getting out, what else alternatives I should try?
Try changing:
await Moralis.authenticate({connector: CoinbaseWalletConnector});
to
await authenticate({connector: CoinbaseWalletConnector}); // from useMoralis
If you want the states to update from any react-moralis
hooks, youâll need to use the hook versions.
What do you mean by this?
Okay thanks, its working now.
I was using useMoralis hook only but in this way so it wasnât getting updated.
const {Moralis}:any = useMoralis();
Moralis.authenticate({connector:WalletConnectWeb3Connector})