(options?: CreateClientOptions)
| 10 | } |
| 11 | |
| 12 | export const createClient = (options?: CreateClientOptions): RpcClient => { |
| 13 | const { api = 'mainnet', authToken } = options || {}; |
| 14 | |
| 15 | let baseUrl: string; |
| 16 | if (typeof api === 'object') { |
| 17 | baseUrl = api.url; |
| 18 | } else { |
| 19 | baseUrl = CHAIN_API_MAP[api]; |
| 20 | } |
| 21 | |
| 22 | const openapiClient = createOpenapiClient<paths>({ baseUrl }); |
| 23 | |
| 24 | if (authToken) { |
| 25 | openapiClient.use({ |
| 26 | onRequest: ({ request }) => { |
| 27 | request.headers.set('X-API-Key', authToken); |
| 28 | return request; |
| 29 | }, |
| 30 | }); |
| 31 | } |
| 32 | |
| 33 | return adaptClientRpc(openapiClient); |
| 34 | }; |
no test coverage detected