From 5ca1131210386dedca0ace5eba7223d56688f0b2 Mon Sep 17 00:00:00 2001 From: Jonathan Dunlap Date: Sun, 5 Apr 2020 08:05:55 -0700 Subject: [PATCH] add request --- src/index.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/index.ts b/src/index.ts index 1356c09..a8dfa04 100644 --- a/src/index.ts +++ b/src/index.ts @@ -231,6 +231,24 @@ export class IFrameEthereumProvider extends EventEmitter< return promise; } + /** + * Request the JSON RPC and return the result. + * @param method method to send to the parent provider + * @param params parameters to send + */ + public async request( + method: string, + params?: TParams + ): Promise { + const response = await this.execute(method, params); + + if ('error' in response) { + throw new RpcError(response.error.code, response.error.message); + } else { + return response.result; + } + } + /** * Send the JSON RPC and return the result. * @param method method to send to the parent provider