-
Hello, User gets asked for approval in metamask when used this provider when calling a smart contract But, I dont get that behaviour when using JSON RPC Provider like this: My idea is basically to enforce usage of certain chains, e.g, I want to force that JSON RPC because I want users to use the BSC only, if my approach to do this is incorrect, how can I enforce BSC networks only? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The MetaMask operates as an EIP-1193 provider. You cannot connect to a local socket on a users machine (which is what 127.0.0.1 refers to). You must use MetaMask (window.Ethereum) if you want to access MetaMask itself. I believe you can specify the chain ID if you wish, to individual methods and you should check the chain ID of the provider to make sure it matches. But localhost is not going to work for most users. Does that make sense? |
Beta Was this translation helpful? Give feedback.
-
Also, when im on a site that requires X network, and im on another, a metamak popups asks you to change your network, how do you do that with ethers.js? |
Beta Was this translation helpful? Give feedback.
The MetaMask operates as an EIP-1193 provider. You cannot connect to a local socket on a users machine (which is what 127.0.0.1 refers to).
You must use MetaMask (window.Ethereum) if you want to access MetaMask itself.
I believe you can specify the chain ID if you wish, to individual methods and you should check the chain ID of the provider to make sure it matches.
But localhost is not going to work for most users. Does that make sense?