{"id":41464094,"url":"https://github.com/coinbase-samples/prime-sdk-ts","last_synced_at":"2026-01-23T16:17:57.647Z","repository":{"id":274083476,"uuid":"866736391","full_name":"coinbase-samples/prime-sdk-ts","owner":"coinbase-samples","description":"Sample TypeScript SDK for the Coinbase Prime REST APIs","archived":false,"fork":false,"pushed_at":"2025-12-16T12:04:09.000Z","size":690,"stargazers_count":7,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-12-17T11:00:29.209Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docs.cdp.coinbase.com/prime/reference/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coinbase-samples.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-10-02T19:28:30.000Z","updated_at":"2025-12-16T12:04:14.000Z","dependencies_parsed_at":"2025-04-30T15:51:09.490Z","dependency_job_id":"3f62c875-8807-406b-a042-68fd73366ce6","html_url":"https://github.com/coinbase-samples/prime-sdk-ts","commit_stats":null,"previous_names":["coinbase-samples/prime-sdk-ts"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/coinbase-samples/prime-sdk-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase-samples%2Fprime-sdk-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase-samples%2Fprime-sdk-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase-samples%2Fprime-sdk-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase-samples%2Fprime-sdk-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coinbase-samples","download_url":"https://codeload.github.com/coinbase-samples/prime-sdk-ts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase-samples%2Fprime-sdk-ts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28695529,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T15:57:05.722Z","status":"ssl_error","status_checked_at":"2026-01-23T15:56:27.656Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-23T16:17:56.891Z","updated_at":"2026-01-23T16:17:57.636Z","avatar_url":"https://github.com/coinbase-samples.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Coinbase Prime API TypeScript SDK\n\n[![npm version](https://badge.fury.io/js/%40coinbase-sample%2Fprime-sdk-ts.svg)](https://badge.fury.io/js/%40coinbase-sample%2Fprime-sdk-ts)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n## Overview\n\nWelcome to the Coinbase Prime API TypeScript SDK. This TypeScript project provides a comprehensive, type-safe interface to the [Coinbase Prime API](https://docs.cdp.coinbase.com/prime/docs/welcome) with multiple consumption patterns optimized for different use cases.\n\n## License\n\nThe _Prime Typescript SDK_ sample library is free and open source and released under the [Apache License, Version 2.0](LICENSE).\n\nThe application and code are only available for demonstration purposes.\n\n## 🚀 Quick Start\n\n### Installation\n\n```bash\nnpm install @coinbase-sample/prime-sdk-ts\n```\n\n### Basic Usage (Recommended)\n\nThe SDK provides a **modular client** with lazy-loaded services for the best developer experience:\n\n```typescript\nimport { CoinbasePrimeClientWithServices } from '@coinbase-sample/prime-sdk-ts';\n\n// Create client from environment variables\nconst client = CoinbasePrimeClientWithServices.fromEnv();\n\n// Access services directly - no manual instantiation needed!\nconst portfolios = await client.portfolios.listPortfolios();\nconst orders = await client.orders.listPortfolioOrders({ portfolioId: 'your-id' });\nconst wallets = await client.wallets.listWallets({ portfolioId: 'your-id' });\n```\n\n### Environment Setup\n\nCopy `env.example` to `.env` and populate with your values:\n\n```bash\ncp env.example .env\n```\n\nThen edit `.env` with your actual credentials:\n```env\n# API Credentials (JSON format)\nPRIME_CREDENTIALS={\"AccessKey\":\"your-access-key\",\"SecretKey\":\"your-secret-key\",\"Passphrase\":\"your-passphrase\"}\n\n# Required IDs\nENTITY_ID=your-entity-id\nPORTFOLIO_ID=your-portfolio-id\nWALLET_ID=your-wallet-id\n```\n\n## 📚 Usage Examples\n\n### **List Portfolios**\n```typescript\nconst portfolios = await client.portfolios.listPortfolios();\nconsole.log(portfolios.portfolios);\n```\n\n### **Get Assets**\n```typescript\nconst assets = await client.assets.listAssets({ \n  entityId: portfolioId \n});\nconsole.log(assets.assets);\n```\n\n### **Create Order**\n```typescript\nimport { OrderSide, OrderType } from '@coinbase-sample/prime-sdk-ts';\n\nconst order = await client.orders.createOrder({\n  portfolioId: 'your-portfolio-id',\n  productId: 'BTC-USD',\n  side: OrderSide.BUY,\n  type: OrderType.MARKET,\n  baseQuantity: '0.001'\n});\nconsole.log(order.orderId);\n```\n\nSee the example folder for more robust examples for many of the available services and endpoints. \n\n## 🔧 Configuration Options\n\n### Pagination Control\n\nThe SDK provides powerful pagination controls at both the client and request level:\n\n```typescript\nconst client = CoinbasePrimeClientWithServices.fromEnv(undefined, {\n  maxPages: 5,        // Max pages to fetch automatically\n  maxItems: 1000,     // Max total items across all pages\n  defaultLimit: 100   // Items per page\n});\n\n// Or per-request\nconst response = await client.transactions.listPortfolioTransactions(\n  { portfolioId, limit: 50 },\n  { maxPages: 10, maxItems: 500 }\n);\n```\n\n### Advanced Pagination Methods\n\nAll paginated responses include powerful methods for manual pagination control:\n\n```typescript\n// Get the first page\nconst firstPage = await client.transactions.listPortfolioTransactions({ portfolioId });\n\n// Check if there are more pages\nif (firstPage.hasNext()) {\n  console.log('More data available');\n}\n\n// Get the next page manually\nconst secondPage = await firstPage.next();\n\n// Fetch ALL remaining pages and combine the data\nconst allTransactions = await firstPage.fetchAll(\n  undefined,  // options\n  (page, totalItems) =\u003e console.log(`Fetched page ${page}, total items: ${totalItems}`)\n);\n\n// Example: Manual pagination loop\nlet currentPage = firstPage;\nwhile (currentPage.hasNext()) {\n  console.log(`Processing ${currentPage.transactions.length} transactions`);\n  currentPage = await currentPage.next();\n}\n```\n\n#### Pagination Methods\n\n| Method | Description | Returns |\n|--------|-------------|---------|\n| **`hasNext()`** | Check if more pages are available | `boolean` |\n| **`next()`** | Fetch the next page | `Promise\u003cResponse \\| null\u003e` |\n| **`fetchAll()`** | Fetch all remaining pages and combine data | `Promise\u003cDataArray[]\u003e` |\n| **`getNextCursor()`** | Get the next page cursor | `string \\| undefined` |\n\n## 📦 Alternative Import Patterns\n\nWhile the **modular client** (`CoinbasePrimeClientWithServices`) is recommended for most use cases, the SDK provides additional import patterns optimized for specific scenarios:\n\n### 🎯 For Bundle Size Optimization\n\n#### **Manual Client** (`@coinbase-sample/prime-sdk-ts/manual`)\nWhen you need full control over service instantiation:\n\n```typescript\nimport { CoinbasePrimeClient, OrdersService, WalletsService } from '@coinbase-sample/prime-sdk-ts/manual';\n\nconst client = CoinbasePrimeClient.fromEnv();\nconst orders = new OrdersService(client);\nconst wallets = new WalletsService(client);\n\n// Only the services you import are included in your bundle\n```\n\n#### **Ultra-Minimal Client** (`@coinbase-sample/prime-sdk-ts/client`)\nFor services-only patterns (97% smaller bundles):\n\n```typescript\nimport { CoinbasePrimeClient } from '@coinbase-sample/prime-sdk-ts/client';\nimport { OrdersService } from '@coinbase-sample/prime-sdk-ts/services';\n\nconst client = CoinbasePrimeClient.fromEnv();\nconst orders = new OrdersService(client);\n// Total bundle: ~3kb (perfect for microservices)\n```\n\n### 📊 Bundle Size Comparison\n\n| Import Pattern | Bundle Size | Use Case |\n|----------------|-------------|----------|\n| **Modular Client** (recommended) | ~30kb | Best developer experience |\n| **Manual Client** | ~90kb | Full control, all services available |\n| **Services + Client** | ~6kb | Custom implementations |\n| **Individual Service** | ~3kb | Microservices, Lambda functions |\n\n### 🎨 Type-Only Imports\n\nFor shared libraries or type definitions:\n\n```typescript\nimport type { CreateOrderRequest, OrderSide } from '@coinbase-sample/prime-sdk-ts/types';\n// 0kb runtime - perfect for shared type libraries\n```\n\n## 🤔 When to Use Which?\n\n- **🏆 Modular Client**: Default choice - best DX, good performance\n- **⚡ Manual Client**: Need all services, want explicit control\n- **🎯 Services-Only**: Microservices, custom clients, minimal bundles\n- **📦 Individual Services**: Lambda functions, single-purpose apps\n- **📝 Types-Only**: Shared libraries, type definitions\n\n## 🛠️ Development\n\n### Installation\n```bash\ngit clone https://github.com/coinbase-samples/prime-sdk-ts.git\ncd prime-sdk-ts\nnpm install\n```\n\n### Build\n```bash\nnpm run build\n```\n\n### Run Examples\nThe SDK includes comprehensive examples in the `example/` directory:\n\n```bash\n# Set up environment (copy env.example to .env first)\ncp env.example .env\n# Edit .env with your actual entityId, portfolioId, and walletId\n\n# Run examples\nnode example/listPortfolios.js\nnode example/createOrder.js\nnode example/listWallets.js TRADING\n```\n\n## 🧪 TypeScript Support\n\nThe SDK is built with TypeScript and provides full type safety:\n\n```typescript\nimport { \n  CoinbasePrimeClientWithServices, \n  OrderSide, \n  OrderType,\n  CreateOrderRequest \n} from '@coinbase-sample/prime-sdk-ts';\n\nconst client = CoinbasePrimeClientWithServices.fromEnv();\n\n// Full IntelliSense and type checking\nconst request: CreateOrderRequest = {\n  portfolioId: 'your-id',\n  productId: 'BTC-USD',\n  side: OrderSide.BUY,  // Enum with autocomplete\n  type: OrderType.MARKET,\n  baseQuantity: '0.001'\n};\n\nconst order = await client.orders.createOrder(request);\n// Response is fully typed - no manual type assertions needed\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoinbase-samples%2Fprime-sdk-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoinbase-samples%2Fprime-sdk-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoinbase-samples%2Fprime-sdk-ts/lists"}