diff --git a/src/index.ts b/src/index.ts index 1356c09..2cac6ec 100644 --- a/src/index.ts +++ b/src/index.ts @@ -195,12 +195,16 @@ export class IFrameEthereumProvider extends EventEmitter< */ private async execute( method: string, - params?: TParams + params?: TParams, + optionalId?: number ): Promise< | JsonRpcSucessfulResponseMessage | JsonRpcErrorResponseMessage > { - const id = getUniqueId(); + const id = Number.isNaN(optionalId as any) + ? getUniqueId() + : (optionalId as number); + const payload: JsonRpcRequestMessage = { jsonrpc: JSON_RPC_VERSION, id, @@ -274,14 +278,18 @@ export class IFrameEthereumProvider extends EventEmitter< * @param callback callback to be called when the provider resolves */ public async sendAsync( - payload: { method: string; params?: any[] }, + payload: { method: string; params?: any[]; id?: number }, callback: ( error: string | null, result: { method: string; params?: any[]; result: any } | any ) => void ): Promise { try { - const result = await this.execute(payload.method, payload.params); + const result = await this.execute( + payload.method, + payload.params, + payload.id + ); callback(null, result); } catch (error) {