how can i know if a provider is connected or not?
See original GitHub issuei need to get a cached provider used by our user previously. if that provider is connected, i will get first user account and display it on the page. or if not, i don’t want to invoke connect process by default, unless user click on the connect button.
some methods of web3js can detect whether a wallet connected to network or not. but i need to use web3modal.connect()
to get a provider to construct a web3 instance.
some code snippet:
// use connect method to get a cached provider will invoke connect process and metamask chrome plugin will popup.
const provider = await web3Modal.connect();
const web3 = new Web3(provider);
so, is there any way to get a cached provider without calling the connect
function? or any way to detect a cached provider is connected to network or not?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:13
Top Results From Across the Web
How to check if a doctor is in-network | HealthPartners Blog
Call your insurance company using the member services line, which you can usually find on your insurance card. HealthPartners members can also find...
Read more >How Can I Verify if a Provider is in My Coverage Network?
You did the right thing by calling your doctor's office and using Aetna's provider lookup tool. Follow up by calling your insurance company...
Read more >Does my doctor know what providers are in my network?
No, you are responsible to check if a provider is in your network. Every insurance company has different benefit plans and network requirements....
Read more >How to Verify If Your Provider Is in Your Coverage Network
The next step is to contact your insurance provider and ask what physicians or other medical professionals are covered under your specific plan....
Read more >How do I find out if my doctor is in my health insurance plan's ...
How do I find out if my doctor is in my health insurance plan's network? That's a common question we hear in our...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
First thing: @vanvantsyan thank you for the downvote.
You can get providers the same way Web3Modal gets them (see web3modal connectors). I do this all the time. Web3Modal just abstracts away all the low-level logic to extract providers from the various sources (most of them are different properties in the window object) It’s no voodoo magic.
Unless you take the provider you don’t have a meaningful way to see if that provider was injected and unless you istantiate it via ethers or web3 you don’t have a meaningful way to know what account is connected and on what network. If you don’t want to spawn the dialog with .connect() then simply try to get the provider you want and check it’s state by yourself.
Following some example on how you can get can providers:
Get MetaMask provider
(This may also trigger other injected providers (e.g. Coinbase) but you can filter MetaMask if you want).
Get Binance Wallet provider
Get Coinbase Wallet provider
Get Fortmatic provider
What I’ve just shown you is obviously painful and it’s just to show you how you can do it manually! To do it without spawning the modal you’ll have to import connectors from Web3Modal library and evaluate them. (see web3modal connectors).
So if I understood you want the provider without the modal showing up, right?
With the above code you should be able to leverage your Web3Modal configurations and get a working provider and feed it in your library of choice without the need of calling the connect method.
I’ve tested the above code and had the expected result:
Ah, you may need to put some if-clauses to guard from undefined, infact if there’s no cached provider you get the following error:
Keep in mind I’m not part of the team, I’m not even an expert of this library. I just read their source code and come up with the above snippet.
Let’s ask the guys from the project itself if my snippet is reliable: @miohtama, @jamesmorgan, @miguelmota, @ptescher and @arronhunt.