# TypeScript SDK

The official TypeScript/JavaScript SDK wraps the CoinMarketCap Pro API with full type definitions, automatic retries, and a namespace API grouped by endpoint category.

- **npm:** [`@coinmarketcap/sdk`](https://www.npmjs.com/package/@coinmarketcap/sdk)
- **GitHub:** [OpenCMC/coinmarketcap-api-typescript](https://github.com/OpenCMC/coinmarketcap-api-typescript)
- **Requires:** Node.js 18+ (TypeScript 5.0+ recommended)

## Get started

1. **Install the package**

   ```bash
   npm install @coinmarketcap/sdk
   ```

   Or with Yarn / pnpm:

   ```bash
   yarn add @coinmarketcap/sdk
   pnpm add @coinmarketcap/sdk
   ```

1. **Create a client**

   Set your API key from the [Developer Portal](https://pro.coinmarketcap.com/account). For keyless endpoints, use `environment: 'public'`.

   ```typescript
   import { CoinMarketCap } from "@coinmarketcap/sdk";

   const cmc = new CoinMarketCap({
     apiKey: process.env.CMC_PRO_API_KEY!,
   });
   ```

1. **Call an endpoint**

   Endpoints are grouped under `cmc.api`:

   ```typescript
   const { data, error } = await cmc.api.cryptocurrency.quotesLatest({
     query: { id: "1,1027" },
   });

   if (data) {
     console.log(data);
   }
   ```

   Or throw on error:

   ```typescript
   const { data } = await cmc.api.cryptocurrency.quotesLatest({
     query: { id: "1" },
     throwOnError: true,
   });
   ```

1. **Handle errors**

   The SDK returns typed error classes (or throws when `throwOnError: true`):

   ```typescript
   import { RateLimitError, AuthenticationError, CMCError } from "@coinmarketcap/sdk";

   const { data, error } = await cmc.api.cryptocurrency.quotesLatest({
     query: { id: "1" },
   });

   if (error instanceof RateLimitError) {
     // 429 — check Retry-After header
   } else if (error instanceof AuthenticationError) {
     // 401 — check your API key
   } else if (error instanceof CMCError) {
     console.log(error.status, error.message);
   }
   ```

## Public (keyless) mode

```typescript
import { CoinMarketCap } from "@coinmarketcap/sdk";

const cmc = new CoinMarketCap({ environment: "public" });

await cmc.api.cryptocurrency.listingsLatest({ query: { limit: 10 } });
```

See the [Keyless Public API](/pro-api-reference/keyless-public-api) for available endpoints without a key.

## Next steps

- [Get Started with an API Key](/guides/quick-start) if you have not set up authentication yet
- [Choose an endpoint](/pro-api-reference/endpoint-overview) to find the right API family
- Full README and API reference on [GitHub](https://github.com/OpenCMC/coinmarketcap-api-typescript)
