I'm playing with Gas Station Network, and in their GSN with ethers example they have:
const Web3HttpProvider = require('web3-providers-http')
// ...
const web3provider = new Web3HttpProvider('http://localhost:8545')
const deploymentProvider= new ethers.providers.Web3Provider(web3provider)
Can I do the same using ethers.js only, or using web3-providers-http is the only way?
The ethers equivalent would be the ethers.providers.JsonRpcProvider. I think you should be able to use it directly without wrapping the web3-http-provider in a Web3Provider.
Try new ethers.providers.JsonRpcProvider(), which will automatically use http://localhost:8545 too, I think. :)
I tried to use it instead of Web3Provider in the GSN example, and I got an error:
Uncaught (in promise) Error: Method [object Object] not supported.
at v (ethers.min.js:1)
at XMLHttpRequest.o.onreadystatechange (ethers.min.js:1)
Not sure how to proceed.
What version of ethers are you using? There shouldn鈥檛 be any XMLHttpRequest calls left in ethers...
You might also be interested in the GsnSigner by @yuetloo : https://github.com/ethers-io/ethers.js/pull/836
What version of ethers are you using? There shouldn鈥檛 be any XMLHttpRequest calls left in ethers...
It was version 4, now I've updated to version 5 and I get a different error. It seems to be an issue with the JSONRPC call (I'm using ganache). This is the error I get from the browser console:
Uncaught (in promise) Error: processing response error (body={"id":43,"jsonrpc":"2.0","error":{"message":"Method [object Object] not supported.","code":-32000,"data":{"stack":"Error: Method [object Object] not supported.\n at GethApiDouble.handleRequest
... ... ...
requestBody="{\"method\":{\"method\":\"eth_chainId\",\"params\":[],\"id\":1,\"jsonrpc\":\"2.0\"},\"id\":43,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="http://localhost:8545", code=SERVER_ERROR, version=web/5.0.1)
at Logger.makeError (ethers.umd.js:3658)
at Logger.throwError (ethers.umd.js:3667)
at ethers.umd.js:17924
at step (ethers.umd.js:17765)
at Object.next (ethers.umd.js:17746)
at fulfilled (ethers.umd.js:17737)
You might also be interested in the GsnSigner by @yuetloo : #836
I saw it! Would it be a replacement for the GSNRelayProvider in the @opengsn/gsn/dist/src/relayclient/ module?
The opengsn implementation is v2. #836 was implemented based on GSN v1. Looks like there are significant changes in GSN from v1 to v2. I'll take a look closer at GSN v2 later and report back.
@vrde How are you calling the provider.send? It looks like you are including the JSON-RPC payload, but you should only include the method and parameters. Can you share your code?
This is what calling the this.send should look like: https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/json-rpc-provider.ts#L269
@vrde Did changing the call signature fix your problem?
Any updates on when GsnProvider for gsnv2 might be implemented?
@justussoh , currently gsnv2 is not on the schedule. However if there's good interest in this, @ricmoo would like this implemented as an ancillary package instead of part of ethers.
I think this has been resolved. If there is interest in a GSNv2 Signer, and someone wishes to provide funding for it, let me know. Otherwise, the implementation for v1 by @yuetloo works.
Ideally, this is a library that the GSN team would maintain themselves. If they are listening and would like to, feel free to reach out to either myself or @yuetloo for assistance.
Thanks! :)
Most helpful comment
@justussoh , currently gsnv2 is not on the schedule. However if there's good interest in this, @ricmoo would like this implemented as an ancillary package instead of part of ethers.