Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for dapp to request network change #5101

Closed
etienneroudeix opened this issue Aug 20, 2018 · 36 comments · Fixed by #9724
Closed

API for dapp to request network change #5101

etienneroudeix opened this issue Aug 20, 2018 · 36 comments · Fixed by #9724
Labels
area-permissions Issues relating to exposing permissions from the trusted MetaMask context to less-trusted contexts. type-enhancement

Comments

@etienneroudeix
Copy link

Hello,

I would like to connect a metamask user to a custom network directly from my dapp.
The idea is to avoid the user to have to copy the new custom RPC url and paste it in a second page metamask form.

Context :

Today when a dapp running on a custom Ethereum blockchain wants a user to sign a transaction, the user needs to :

  • Copy the custom url
  • Open Metamask
  • Click the dropdown menu
  • Click the parameters button
  • Search for the « New RPC URL » form
  • Paste the url
  • Realize that the other form fields has no connection and are not needed
  • Click the save button
  • Click to the cross to go back to the main menu

And this a very long process. And metamask does not always remember the custom network.

My proposal :

The web3 metamask provider accepts a new function to add a custom RPC from the dapp.
The metamask extension shows a window to warn the metamask user that it’s network has been changed. The warning should be enforced if the chainId is 1.
The dapp can ask the user to send a tx to the custom network using eth_sendTransaction.

What do you think about this feature ?

@etienneroudeix
Copy link
Author

Hi there,

I am really insteresting in developing the feature myself and share it with the community, but I would like to be sure it has a real chance of being accepted.

cheers

@bdresser
Copy link
Contributor

bdresser commented Sep 4, 2018

@etienneroudeix I think this proposal makes a lot of sense. We've discussed this internally a couple times and would love to collaborate on a solution.

This could be a good candidate for an EIP, and will likely have some downstream effects on the Custom RPC UI we show in our settings menu.

See #3604 #5134 #3512

cc @danfinlay

@danfinlay
Copy link
Contributor

This is very aligned with my general thinking of MetaMask going forward. For example, it is reminiscent of how we have begun addressing managing a list of tokens:
https://ethereum-magicians.org/t/eip-747-wallet-watchasset/1048/9

Once we merge support for custom chainIds, we could begin implementing this.

Two open questions from that PR:

  • Where do we get prices for a custom chain?
  • What block explorer do we link to for a custom chain?

Both of these things (prices & explorer links) have previously been neatly trustless parts of MetaMask (you can cross-check what a Dapp claims against them). If Dapps could propose networks, how would we answer these basic questions?

@ghost
Copy link

ghost commented Sep 4, 2018

@danfinlay I would like to know the eta schedule for optional chain id support , it has been open from 12 days ago and still no sign of review or merge 😂

@etienneroudeix
Copy link
Author

@bdresser @danfinlay Thank for these answers and the referred issues/PR links.
I'm glad MetaMask wish to move in this direction.
If Dapps can propose networks, it must/should provide any element Metamask needs, like the block explorer link patterns for block/tx.
Concerning the currency converter it is indead a bit more complicated. But the convertion is already not shown for testnets and custom RPCs. So I think it is an unrelated issue.

@bdresser bdresser changed the title Feature proposal : Dapp can add custom RPC to Metamask API for dapp to suggest network change May 9, 2019
@danfinlay
Copy link
Contributor

A good discussion on this topic with a sample spec was raised in January on ethereum-magicians

@bdresser bdresser changed the title API for dapp to suggest network change API for dapp to request network change May 9, 2019
@danfinlay
Copy link
Contributor

New EIP for this: ethereum/EIPs#2015

@PierreJeanjacquot
Copy link

Hi, the EIP-2015 looks really nice for UX.
I need an easy way to ask the user to switch between chains, as described @etienneroudeix the current process is really painful and this EIP will help a lot for the user adoption.
@bdresser Is there any plan at MetaMask to work on this feature?

@danfinlay
Copy link
Contributor

Yes, we're looking forward on integrating an API for suggesting network change, but we currently think it might be more appropriate to either/both:

  • Integrate it into the initial sign-in prompt (.enable())
  • Allow additional network providers to be requested at will (allow multiple network connections without user confirmation).

We are doing work towards both of those right now, and while this might be slightly lower-hanging fruit, these solutions seem more beneficial long-term. Thoughts?

@etienneroudeix
Copy link
Author

hi @danfinlay

Allow additional network providers to be requested at will (allow multiple network connections without user confirmation).

Does it mean a dapp can ask the user to sign a tx on Rinkeby (or any other network) while his current network is the main network ?
And the opposite ? This last one might be tricky for the user.

@danfinlay
Copy link
Contributor

Does it mean a dapp can ask the user to sign a tx on Rinkeby (or any other network) while his current network is the main network ?
And the opposite ? This last one might be tricky for the user.

Long term, I think the concept of "connected network" will become less meaningful. What is more important are the assets you hold. Some are test ether, some are real ether. If we represent the asset being transferred correctly, we should be able to provide a good inter-chain dapp development experience without exposing the user to unusual phishing risks.

@wbt
Copy link
Contributor

wbt commented Aug 5, 2019

Could we first add a feature allowing the dapp to query the address of the node it is connected to, in addition to being able to get the chainID? This is much more important for custom RPC addresses. The user can see what's there, but the dapp currently cannot, and this reduces usability by adding failure paths that are not intuitive for users to debug, even/especially when they can verify that dapp files (e.g. HTML and Javascript) are coming from an expected server.

@danfinlay
Copy link
Contributor

Some RPC URLs include private authorization keys as query parameters, so I'm not sure I'd want to leak that information to every site a user visits. I would hope providing chainId/networkId checks as well as the ability to suggest a specific RPC would satisfy most applications' needs. If checking the exact URL of the user's RPC were really necessary, I would be inclined to provide it as an additional sign-in permission, so the user would explicitly grant that information disclosure.

@wbt
Copy link
Contributor

wbt commented Aug 5, 2019

How would a dapp know if it needs to request a network change, if it doesn't know what it's on?
Maybe a feature to get an accurate answer to "Am I connected to RPC URL <x>?" would be a better way to address both.

@danfinlay
Copy link
Contributor

For the time being, the networkId and chainId parameters can be used to identify EVM-based blockchains, and should be used instead of an RPC, since a user may choose to connect to a given blockchain with their own / a custom RPC.

@Moejoe90
Copy link

Moejoe90 commented Oct 2, 2019

any update on implementing EIP-2015?

@danfinlay
Copy link
Contributor

We are currently putting more effort into EIP 2255, which will eventually incorporate the parameters from EIP 2015, but allowing the wallet to connect to different networks on different dapps, instead of preserving the fairly broken notion of a single network for all browser tabs.

@berniegao
Copy link

Hi @danfinlay any ETA for this function to be supported? looking forward to it

@LucasMoskun
Copy link

I see here that EIP-2255 has been integrated into the browser version
(https://docs.metamask.io/guide/rpc-api.html#permissions).

"Currently, the only permission is eth_accounts, which allows you to access the user's Ethereum address(es). More permissions will be added in the future."

Is the proposed EIP-2015 functionality still planning to be incorporated as a permission call? If so, is there any idea when this may be?

@rekmarks
Copy link
Member

rekmarks commented Jan 6, 2021

Update: We're doing this: https://eips.ethereum.org/EIPS/eip-3085

It's basically like 2015, but without update functionality (for now). We'll have some additional restrictions on the kind of chains that can be added, and will ignore some fields for the time being, but e.g. xDAI, Optimism, and similar EVM-compatible chains with ETH-analogue native currencies (with 18 decimals) will be addable using wallet_addEthereumChain.

Basically, fi you can add via the existing custom network RPC form today, you should be able to add via the new RPC method once it ships (soon), so long as the chain ID does not collide with one of the default MetaMask networks.

@LucasMoskun
Copy link

Update: We're doing this: https://eips.ethereum.org/EIPS/eip-3085

It's basically like 2015, but without update functionality (for now). We'll have some additional restrictions on the kind of chains that can be added, and will ignore some fields for the time being, but e.g. xDAI, Optimism, and similar EVM-compatible chains with ETH-analogue native currencies (with 18 decimals) will be addable using wallet_addEthereumChain.

Basically, fi you can add via the existing custom network RPC form today, you should be able to add via the new RPC method once it ships (soon), so long as the chain ID does not collide with one of the default MetaMask networks.

Woooooo! 🍻

@sameepsi
Copy link

Any updates on this?

@rekmarks
Copy link
Member

@sameepsi we're close to finishing the feature on our end and should ship soon.

@sameepsi
Copy link

sameepsi commented Feb 9, 2021

@rekmarks That's good to hear. Do let us know when this feature is out. We are very much eager to integrate it within QuickSwap.

@alexauroradev
Copy link

@rekmarks , thanks for your work on this issue. NEAR is waiting for this too.

@Lafachief
Copy link

@rekmarks wow, that will make everything so much easier especially in those gasintense times right now :)

DEUS is also waiting!

@Marksmargon
Copy link

Fuse is waiting anxiously as well :)
Thanks for pushing this forward @rekmarks

@alexauroradev
Copy link

@brad-decker, great work! Congratz!
When do you expect to release it?

@wbt
Copy link
Contributor

wbt commented Feb 14, 2021

They merged a PR with the "T12-DONOTMERGE" tag...

@sameepsi
Copy link

Any updates on this?

@KaiRo-at
Copy link

Update: We're doing this: https://eips.ethereum.org/EIPS/eip-3085

Apparently, that doesn't allow to switch users to a built-in network though, which makes operation a lot more difficult for anything that wants to switch and is not using custom chains...

@masterbd
Copy link

Pancakeswap does this 'network change request', do you guys have any idea how they do it.
I have to mention that I searched through their github repo, but with no success. Probably some code example will be useful for other new developers.

@cosminimum
Copy link

Hello @masterbd

You should use wallet_addEthereumChain (https://docs.metamask.io/guide/rpc-api.html#wallet-addethereumchain) for network change request.

Small snippet:

window.ethereum.request({ method: 'wallet_addEthereumChain', params: [{ chainId: '0x38', chainName: 'Binance Smart Chain', nativeCurrency: { name: 'BNB', symbol: 'BNB', decimals: 18 }, rpcUrls: ['https://bsc-dataseed.binance.org/'], blockExplorerUrls: ['https://bscscan.com/'] }] }

@misotsune
Copy link

misotsune commented May 1, 2021

@zkipart switching between added chains and adding new chains are fundamentally different things though, also metamask doesn't allow to add default chains so any multichain service that also serves on ethereum mainnet can categorically scratch the idea of using this.

is there any reason why this issue was closed?

@KaiRo-at
Copy link

KaiRo-at commented May 6, 2021

#10597 is the current issue for this request, FWIW - but someone still needs to implement it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-permissions Issues relating to exposing permissions from the trusted MetaMask context to less-trusted contexts. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.