admin管理员组文章数量:1356905
when I try to connect to my wallet from trust wallet browser, it redirects me to google
Image 1
Image 2
The code is like this which is just as the same as trustWallet doc
- how can I properly connect to the wallet connect?
- is there anyway to connect to testnets like ropsten with wallet connect?
// set chain id and rpc mapping in provider options
const providerOptions = {
walletconnect: {
package: WalletConnectProvider,
options: {
rpc: {
56: ''
},
chainId: 56
}
}
}
const web3Modal = new Web3Modal({
network: "mainnet", // optional
cacheProvider: true, // optional
providerOptions // required
});
const provider = await web3Modal.connect();
await web3Modal.toggleModal();
// regular web3 provider methods
const newWeb3 = new Web3(provider);
const accounts = await newWeb3.eth.getAccounts();
console.log(accounts);
when I try to connect to my wallet from trust wallet browser, it redirects me to google
Image 1
Image 2
The code is like this which is just as the same as trustWallet doc
- how can I properly connect to the wallet connect?
- is there anyway to connect to testnets like ropsten with wallet connect?
// set chain id and rpc mapping in provider options
const providerOptions = {
walletconnect: {
package: WalletConnectProvider,
options: {
rpc: {
56: 'https://bsc-dataseed1.binance'
},
chainId: 56
}
}
}
const web3Modal = new Web3Modal({
network: "mainnet", // optional
cacheProvider: true, // optional
providerOptions // required
});
const provider = await web3Modal.connect();
await web3Modal.toggleModal();
// regular web3 provider methods
const newWeb3 = new Web3(provider);
const accounts = await newWeb3.eth.getAccounts();
console.log(accounts);
Share
Improve this question
edited Oct 24, 2022 at 20:32
TylerH
21.1k78 gold badges79 silver badges114 bronze badges
asked Oct 6, 2021 at 11:00
Mohammad Amin AhmadiMohammad Amin Ahmadi
541 gold badge2 silver badges3 bronze badges
3 Answers
Reset to default 3If i understand you correct, try
const provider = await Web3Modal.connectTo('walletconnect')
instead of
const provider = await web3Modal.connect();
await web3Modal.toggleModal();
UPD: walletConnect is just 'agregator'. you can't connect directly to any wallet (at least first time) you should choose wallet which you want connect to (left tab with button will choose apps on your mobile phone to which it can connect (metamask, trust, ...) and right tab 'qr-code' will show you qr which you can scan with wallet apps (metamask, trust, ...) on another devices). then if 'cacheProvider' is true, you don't need to click it again till disconnect from wallet
Just ran across this by chance. To answer your second question, to connect to specific Testnet chain:
- check the chainId from https://chainlist/ (remember to check the "Include Testnets" option)
- find the correct chain name (unfortunately, Polygon's Testnet is named Mumbai instead of something relatable, like "Polygon Mumbai Testnet"), then open the pull down to get a list of RPCs
- use both chainId and one RPCs to add an entry to the
options.rpc
node, ensuring the "gas token" is also correctly set in thenetwork
node
Considering WalletConnect v1 has been deprecated (as of writing this), if you happen to move to using Web3Modal and WalletConnect v2, you could import chain defaults from '@wagmi/core/chains', then use in the "defaultChain".
For the first problem, I found out, it doesn't work because I was on localhost. When I launched my dapp on server it easily connected to my trustwallet on phone. For the second question I found this:
walletconnect: {
package: WalletConnectProvider,
options: {
rpc: {
137: "https://rpc-mainnet.maticvigil./",
},
network: "matic",
},
},
};
to connect to matic(polygon) network but I couldn't connect to any testnets.
本文标签: javascriptconnect to walletconnect with web3modalStack Overflow
版权声明:本文标题:javascript - connect to walletconnect with web3modal - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744064088a2584666.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论