Comments (8)
Hey, thanks. Let me try out v3 and get back to you.
from web3-react.
And if you want to prompt users to download a web3 provider, you'll be able to render that conditionally based on context.active
/context.error
within the component calling context.setFirstValidConnector
.
Final note, I'm working on adding a bunch of other connectors (woo!), so in the near future it will be really easy to connect not only to metamask/infura/walletconnect, but also trezor, ledger, fortmatic, maybe portis, etc.
from web3-react.
Hi @michaelhly, I did remove the passive mode in v3! Basically, the package is now 'passive' by default, and you always have to manually initialize connectors.
There are some pretty bare-bones examples of this in the docs and codesandbox, but let me know if you have questions about any specific pattern.
As for detecting the network id before initialization, or for checking whether or not a global web3 object exists: I don't think there's any problem doing those kind of checks manually, though ideally it wouldn't be needed. One way to deal with with would be to call setFirstValidConnector
with MetaMask as the first argument, and Infura as the second for users without a web3 browser.
const metaMask = new MetaMaskConnector({ supportedNetworks: [1, 4] })
const infura = new NetworkOnlyConnector({ providerURL: '...' })
const connectors = { metaMask, infura }
// now you can call: setFirstValidConnector(['metaMask', 'infura'])
Does that make sense/cover your use cases?
from web3-react.
Hi @michaelhly, closing this issue for now, feel free to reopen if you have any issues with v3!
from web3-react.
Hi @NoahZinsmeister,
When not connected to the provider, the context object looks like this. My question was is it possible for the context to have whatever provider's networkId that is injected to the browser? Or if any web3 object exists in the browser?
As this is possible with regular web3.js. If my user does not have any sort of web3 provider, I'd like to prompt my user to go download one.
Update:
Nevermind, I'm stupid. I can get this information myself with window.ethereum
.
from web3-react.
Hi @michaelhly!
While you're definitely more than welcome to use window.ethereum
(and this might even be optimal depending on your use case), you can also use something like the 'automatic initialization' pattern described below:
In a component below the one where you initialize <Web3Provider ...>
(this is necessary so that the context is injected appropriately), you can write something like:
const context = useWeb3Context()
useEffect(() => {
context.setFirstValidConnector(['metamask', 'infura'])
}, [])
If you've named your connectors 'metamask' and 'infura', this code will attempt to activate web3-react using metamask, and if that fails (probably because the user doesn't have it installed/is on mobile/whatever), then it will fall back to infura.
Does that make sense/cover your use case?
from web3-react.
Yep. This is good. Thanks!
from web3-react.
And if you want to prompt users to download a web3 provider, you'll be able to render that conditionally based on
context.active
/context.error
within the component callingcontext.setFirstValidConnector
.Final note, I'm working on adding a bunch of other connectors (woo!), so in the near future it will be really easy to connect not only to metamask/infura/walletconnect, but also trezor, ledger, fortmatic, maybe portis, etc.
Nice. That would be awesome!
from web3-react.
Related Issues (20)
- Why is `connector.deactivate` always undefined? HOT 1
- **The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)
- Walletconect v2 chains not supported
- V3-core
- TypeError: Object(...) is not a function (WalletConnectV2) HOT 1
- How can I sign a transaction using web3-react library?
- dotnet add package dotnetstandard-bip39 --version 1.0.2
- Something happend with intendation
- How can I send transaction to ethereum via metamask?
- tags` as well.beezywqp
- How can i connect okx wallet (web3-react v6) ??
- Did Uniswap abandon this repo? HOT 1
- gm
- How can i use network connection as a fallback connector? HOT 1
- Issue with useWeb3React chainId property when changing Network in MetaMask mobile (WalletConnect v2 connector) HOT 1
- 1. [https://app.uniswap.org/swap?screen=transaction&userAddress=0xFa1dB6794de6e994b60741DecaE0567946992181&txHash=0x4e50890f8a8029ed34477725ed46efd519b400cdab6862f9ed094395fa01728a&chain=polygon](url)
- görev/npm-deploy-kurulumu
- WalleConnectV2 deactivate HOT 1
- connect function from useWalletConnect does not trigger the injectedWallet module automatically
- Missing or invalid. emit() chainId: eip155:11155111. & Cannot convert undefined or null to object at Function.keys (<anonymous>) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from web3-react.