How to expose ethers provider as RPC provider? #1922
Replies: 4 comments
-
You can try out the experimental Eip1193Bridge, which is still quite early, but will expose a ethers Provider and Signer as an EIP-1193 provider. You might also consider checking out the GsnSigner by @yuetloo. It currently only supports v1 of GSN, but I think she is thinking about supporting v2 as well. |
Beta Was this translation helpful? Give feedback.
-
Unrelated to GSN, I'm working on a package which uses ethers at its core, but has a dependency that needs an RPC provider in the constructor. It sounds like the Eip1193Bridge is the way to go here. Could you expand a bit on what is experimental about the EIP-1193 bridge and how stable/functional/tested it is? |
Beta Was this translation helpful? Give feedback.
-
@mds1 I just haven't had a chance to really go through it thoroughly and use it. For example, I would like to expand it to allow for an array of Signers (currently I think it only supports a single Singer). It has not been tested other than a few quick tests. If you want to use it though, and try it out, go for it. :) You should make sure you lock in on the version though; i.e. in your package.json, use |
Beta Was this translation helpful? Give feedback.
-
Got it, thanks! I'll give a shot and be sure to open issues if I find anything funky 🙂 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
ethers supports wrapping an rpc, using the
ethers.providers.Web3Provider
However, how can I do the reverse: expose a given ethers provider as RPC provider ?
background:
We work on GSN.
GSN takes a provider, and wrap it so that all transactions are routed through a relayer, and thus can delegate the gas payment to another entity (paymaster)
rpcProvider = RelayProvider.newProvider({provider: window.ethereum})
The resulting provider is an RPC provider - just like the original
window.ethereum
was.To work with ethers, we direct out users to use
ethersProvider = ethers.providers.Web3Provider(RelayProvider.newProvider({provider: window.ethereum}))
The problem:
Several times people stumble to add GSN since they have an existing "ethers" project (with no web3 provider), and they try to pass that into GSN - and it fails.
The only answer we can currently give them is to create a web3 provider instead, and use that as an underlying provider.
It would be best if we could direct people on a simple way to wrap their current ethers provider with RPC provider, and pass that into GSN.
(in the long run, we might rewrite GSN to use ethers at its core, as its lighter than web3, but that will take some time..)
Beta Was this translation helpful? Give feedback.
All reactions