diff --git a/src/client/lcd/APIRequester.ts b/src/client/lcd/APIRequester.ts index a9d2d5e0..11a08637 100644 --- a/src/client/lcd/APIRequester.ts +++ b/src/client/lcd/APIRequester.ts @@ -24,15 +24,25 @@ export class APIRequester { private axios: AxiosInstance; private readonly baseURL: string; - constructor(baseURL: string) { + constructor(baseURL: string, apiToken?: string) { this.baseURL = baseURL; - this.axios = Axios.create({ - headers: { - Accept: 'application/json', - }, - timeout: 30000, - }); + if (apiToken) { + this.axios = Axios.create({ + headers: { + Accept: 'application/json', + Authorization: `Bearer ${apiToken}`, + }, + timeout: 30000, + }); + } else { + this.axios = Axios.create({ + headers: { + Accept: 'application/json', + }, + timeout: 30000, + }); + } } private computeEndpoint(endpoint: string) { diff --git a/src/client/lcd/LCDClient.ts b/src/client/lcd/LCDClient.ts index 87c63eb6..dc5e782a 100644 --- a/src/client/lcd/LCDClient.ts +++ b/src/client/lcd/LCDClient.ts @@ -34,6 +34,11 @@ export interface LCDClientConfig { */ lcd: string; + /** + * The API key to be included in requests sent to the LCD. + */ + apiToken?: string; + /** * Chain ID of the blockchain to connect to. */ @@ -142,7 +147,10 @@ export class LCDClient { this.apiRequesters = Object.keys(chains).reduce( (result: Record, chainID) => { - result[chainID] = new APIRequester(chains[chainID].lcd); + result[chainID] = new APIRequester( + chains[chainID].lcd, + chains[chainID].apiToken + ); return result; }, {}