From 117226315dc5599fbc5e61a3442807c60ac456b4 Mon Sep 17 00:00:00 2001 From: florian-bellotti Date: Mon, 15 Jul 2024 21:37:00 +0200 Subject: [PATCH] :sparkless: Adding api key in GaslessOptions --- src/services.ts | 6 +++++- src/types.ts | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/services.ts b/src/services.ts index c921e25..a0446d6 100644 --- a/src/services.ts +++ b/src/services.ts @@ -17,13 +17,17 @@ import { const baseUrl = (options?: GaslessOptions): string => options?.baseUrl ?? BASE_URL; const getRequest = (options?: GaslessOptions): RequestInit => ({ signal: options?.abortSignal, - headers: { ...(options?.apiPublicKey !== undefined && { 'ask-signature': 'true' }) }, + headers: { + ...(options?.apiPublicKey !== undefined && { 'ask-signature': 'true' }), + ...(options?.apiKey && { 'api-key': options.apiKey }), + }, }); const postRequest = (body: unknown, options?: GaslessOptions): RequestInit => ({ method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json', + ...(options?.apiKey && { 'api-key': options.apiKey }), ...(options?.apiPublicKey && { 'ask-signature': 'true' }), }, body: JSON.stringify(body), diff --git a/src/types.ts b/src/types.ts index 6a51060..0df05f0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -64,6 +64,8 @@ export interface ExecuteCallsOptions { export interface GaslessOptions { baseUrl?: string; + // The api key allows you to sponsor the gas fees for your users + apiKey?: string; abortSignal?: AbortSignal; apiPublicKey?: string; }