Adding Custom Network using JS, walletconnect #5436
Unanswered
Umair72Raza
asked this question in
Developer Support
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I am new to blockchain and wallet connect
Background:
I am trying to connect account to my dApp using walletconnect. I am using meta mask as the wallet app on my mobile. My contracts are deployed on Polygon Amoy Test net and therefore, I am bound to use the same for the interactions with the contracts. The problem is that this is a custom network. Most of the users may not have added this as a custom network. I am using Vanilla JS, reown's app kit.
RPC URL
https://rpc-amoy.polygon.technology
Chain ID:
80002
Currency Symbol:
MATIC
Below is the code of basic configurations of dApp
`
const metadata = {
name: 'AppKit',
description: 'AppKit Example',
url: 'https://reown.com/appkit', // origin must match your domain & subdomain
icons: ['https://avatars.githubusercontent.com/u/179229932']
};
const polygonAmoyTestnet = {
id: 'eip155:80002', // Matching the format used for Polygon Mainnet
chainId: 80002,
name: 'Polygon Amoy Testnet',
currency: 'MATIC', // Mapping the 'nativeCurrency' to 'currency' like in the first object
explorerUrl: 'https://www.oklink.com/amoy', // Using the Oklink explorer URL
rpcUrl: 'https://rpc-amoy.polygon.technology', // Using the provided RPC URL
chainNamespace: 'eip155', // Keeping the same namespace as for Polygon
testnet: true // Keeping the testnet flag
};
// 3. Create a AppKit instance
const modal = createAppKit({
adapters: [new EthersAdapter()],
networks: [ polygonAmoyTestnet],
metadata,
projectId,
allowUnsupportedChain: true,
features: {
email: false, // default to true
socials: [],
emailShowWallets: true, // default to true
},
});
`
Problem Scenario:
Say a user does not have the Polygon amoy test net custom network added in their wallet and they scan the wallet connect QR code on my dApp. they'll get the prompt on the Mobile wallet to confirm connection. On confirmation, the Account gets connected and the dApp but the network is not detected and I see this pop up.
a: clicking on the option does not do anything (like prompting on the wallet to add a network or anything else).
b: There is another case that if the user has some balance of MATIC, the balance is shown with "Unknown Network" and on reload I see the "Polygon Amoy Testnet" Network.
On reload
I am using the button below for connecting the mobile wallet using walletconnect
<w3m-button></w3m-button>
I have tried to add a button on clicking which I try to add network in mobile wallet using this code below
`
document.getElementById("switch-network").addEventListener('click', async() =>
{
// await modal.switchNetwork(polygonAmoyTestnet)
const address = modal.getAddress();
console.log("got ADRESS ", address)
const walletProvider = await modal.getWalletProvider();
provider = new ethers.BrowserProvider(walletProvider);
const network = await provider.getNetwork();
console.log("network", network.chainId);
console.log("ethers.toBeHex(polygonAmoyTestnet.chainId)",ethers.toBeHex(polygonAmoyTestnet.chainId))
})`
All it does is switch the network and if switching fails, it does not prompt me on the app to add the network.
Question:
How can I make prompt the app to add the network using the dApp.
Beta Was this translation helpful? Give feedback.
All reactions