Problem
Currently, when an instance of SafeEventEmitterProvider is passed to the Web3Provider constructor from Ethers v5 or the BrowserProvider constructor from Ethers v6, it produces a type error. Web3Provider produces:
Argument of type 'SafeEventEmitterProvider' is not assignable to parameter of type 'ExternalProvider | JsonRpcFetchFunc'.
Type 'SafeEventEmitterProvider' is not assignable to type 'ExternalProvider'.
Types of property 'sendAsync' are incompatible.
Type '(req: JsonRpcRequest<JsonRpcParams>, callback: (error: unknown, providerRes?: any) => void) => void' is not assignable to type '(request: { method: string; params?: any[]; }, callback: (error: any, response: any) => void) => void'.
Types of parameters 'req' and 'request' are incompatible.
Type '{ method: string; params?: any[]; }' is not assignable to type 'JsonRpcRequest<JsonRpcParams>'.
Type '{ method: string; params?: any[]; }' is missing the following properties from type '{ params?: (Record<string, Json> | Json[]) & ExactOptionalGuard; id: string | number | null; method: string; jsonrpc: "2.0"; }': id, jsonrpctypescript(2345)
and BrowserProvider produces:
Argument of type 'SafeEventEmitterProvider' is not assignable to parameter of type 'Eip1193Provider'.
Property 'request' is missing in type 'SafeEventEmitterProvider' but required in type 'Eip1193Provider'.typescript(2345)
The first error happens because Web3Provider allows jsonrpc and id to be missing from the request object, whereas JsonRpcRequest does not; the second error happens because BrowserProvider expects the provider to conform to EIP-1193, which specifies that it ought to have a request method.
Proposed Solution
We can address both of these issues by:
- Aligning SafeEventEmitterProvider to EIP-1193 by adding a
request method and deprecating send and sendAsync (which aren't part of the spec)
- Ensuring that
request does not require id and jsonrpc to be set, filling them in if they are missing
Acceptance Criteria
- We should be able to pass an instance of SafeEventEmitter to the constructor from each of these libraries without type errors:
Web3Provider constructor from Ethers v5
BrowserProvider constructor from Ethers v6
eth-query constructor
ethjs-query constructor
- Using
send and sendAsync should produce deprecation warnings
eth-json-rpc-provider tests should not use send and sendAsync except where necessary to test the above
Problem
Currently, when an instance of SafeEventEmitterProvider is passed to the
Web3Providerconstructor from Ethers v5 or theBrowserProviderconstructor from Ethers v6, it produces a type error.Web3Providerproduces:and
BrowserProviderproduces:The first error happens because
Web3Providerallowsjsonrpcandidto be missing from the request object, whereasJsonRpcRequestdoes not; the second error happens becauseBrowserProviderexpects the provider to conform to EIP-1193, which specifies that it ought to have arequestmethod.Proposed Solution
We can address both of these issues by:
requestmethod and deprecatingsendandsendAsync(which aren't part of the spec)requestdoes not requireidandjsonrpcto be set, filling them in if they are missingAcceptance Criteria
Web3Providerconstructor from Ethers v5BrowserProviderconstructor from Ethers v6eth-queryconstructorethjs-queryconstructorsendandsendAsyncshould produce deprecation warningseth-json-rpc-providertests should not usesendandsendAsyncexcept where necessary to test the above