# n8n-nodes-coinbase-cdp

[![npm version](https://img.shields.io/npm/v/n8n-nodes-coinbase-cdp)](https://www.npmjs.com/package/n8n-nodes-coinbase-cdp)
[![npm downloads](https://img.shields.io/npm/dt/n8n-nodes-coinbase-cdp)](https://www.npmjs.com/package/n8n-nodes-coinbase-cdp)

This is an n8n community node for **Coinbase CDP (Developer Platform)** with two powerful nodes:

- **Coinbase CDP (Advanced Trade API v3)** - For trading, portfolios, and market data
- **Coinbase Server Wallet (API v2)** - For wallet operations, deposits, withdrawals, and blockchain interactions (EVM & Solana)

## Installation

### Community Nodes (Recommended)

Install directly from n8n:

1. Go to **Settings > Community Nodes**
2. Select **Install**
3. Enter `n8n-nodes-coinbase-cdp`
4. Click **Install**

### Manual Installation

For local development or self-hosted n8n:

```bash
npm install n8n-nodes-coinbase-cdp
```

In n8n, search for "Coinbase" to find both nodes.

## Features

- **🔐 Secure Authentication**: Dual credential system for Advanced Trade and Server Wallet APIs
- **📊 Complete API Coverage**: Generated from official Coinbase OpenAPI specifications
- **🌐 Multi-Environment**: Supports both Production and Sandbox environments
- **⚡ Two Powerful Nodes**: 
  - **Coinbase CDP**: Trading, portfolios, orders, market data
  - **Coinbase Server Wallet**: EVM & Solana wallets, deposits, withdrawals, smart accounts
- **🔗 Blockchain Support**: Ethereum, Base, Arbitrum, Polygon, Solana networks

## Authentication

### Coinbase CDP API (Advanced Trade)

This node uses **Coinbase Developer Platform (CDP) API** keys with ES256 JWT authentication.

### Getting Your API Keys

1. Go to [Coinbase Developer Platform](https://portal.cdp.coinbase.com/)
2. Create a new API key
3. Download the private key (`.pem` file)
4. Copy the API Key Name (format: `organizations/{org_id}/apiKeys/{key_id}`)

### Setting Up Credentials in n8n

1. In n8n, create new credentials: **Coinbase CDP API**
2. Enter your **CDP API Key Name**
3. Paste your **EC Private Key** (see formats below)
4. Select **Environment** (Production or Sandbox)
5. Click **Save** and test the connection

### Private Key Format

The private key can be provided in two formats:

**Multi-line format** (recommended):
```
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg...
-----END PRIVATE KEY-----
```

**.env format** (single-line with literal `\n`):
```
-----BEGIN PRIVATE KEY-----\nMIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg...\n-----END PRIVATE KEY-----
```

Both SEC1 (`BEGIN EC PRIVATE KEY`) and PKCS8 (`BEGIN PRIVATE KEY`) formats are supported.

### Coinbase Server Wallet API (Wallet Operations)

This node uses **two-layer JWT authentication** with Secret API Key and Wallet Secret.

#### Getting Your API Keys

1. Go to [Coinbase Developer Platform](https://portal.cdp.coinbase.com/)
2. Create a **Secret API Key** for Server Wallet
3. Download the **Secret API Key** private key (`.pem` file)
4. Create or export your **Wallet Secret** private key
5. Copy the **Secret API Key Name**

#### Setting Up Credentials in n8n

1. In n8n, create new credentials: **Coinbase Server Wallet API**
2. Enter your **Secret API Key Name**
3. Paste your **Secret API Key (Private Key)**
4. Paste your **Wallet Secret (Private Key)**
5. Click **Save** and test the connection

**Note**: Both private keys support multi-line and `.env` format (with literal `\n`).

## Available Operations

### Coinbase CDP Node (Advanced Trade API)

Full-featured node with all Coinbase Advanced Trade API operations:

- **Portfolio**: View balances, portfolios, and portfolio breakdown
- **Accounts**: List and manage trading accounts
- **Orders**: Create, cancel, and query orders
- **Products**: Get product information, candles, and market data
- **Transactions**: View transaction history
- **Fees**: Query transaction and fee summaries

### Coinbase Server Wallet Node (Wallet API v2)

Comprehensive wallet operations for EVM and Solana blockchains:

#### EVM Operations (Ethereum, Base, Arbitrum, Polygon)
- **Accounts**: Create accounts, get balances, list accounts
- **Transactions**: Send transactions, sign transactions, get transaction status
- **Smart Accounts**: Create and manage smart contract accounts
- **Token Operations**: Token balances, token swaps
- **Faucet**: Request testnet tokens

#### Solana Operations
- **Accounts**: Create Solana accounts, get balances
- **Transactions**: Sign and send Solana transactions
- **Token Operations**: SPL token management

#### Additional Features
- **Payments**: Payment processing and confirmations
- **Data**: Blockchain data queries
- **Onramp**: Fiat-to-crypto onramp integration
- **Policy Engine**: Transaction policy management
- **X402**: Advanced wallet features

## Example Workflows

### Advanced Trade: Check Account Balance

1. Add **Coinbase CDP** node
2. Select **Resource**: Portfolio
3. Select **Operation**: List Portfolios
4. Execute to see all your portfolios

### Advanced Trade: Place a Market Order

1. Add **Coinbase CDP** node
2. Select **Resource**: Orders  
3. Select **Operation**: Create Order
4. Fill in order parameters (product, side, amount)
5. Execute to place the order

### Server Wallet: Create EVM Account

1. Add **Coinbase Server Wallet** node
2. Select **Resource**: EVM Accounts
3. Select **Operation**: Create Account
4. Specify network (e.g., "base-sepolia")
5. Execute to create a new wallet account

### Server Wallet: Send Transaction

1. Add **Coinbase Server Wallet** node
2. Select **Resource**: EVM Transactions
3. Select **Operation**: Send Transaction
4. Fill in: account address, recipient, amount, token
5. Execute to send the transaction

### Server Wallet: Get Token Balance

1. Add **Coinbase Server Wallet** node
2. Select **Resource**: EVM Token Balances
3. Select **Operation**: Get Token Balances
4. Specify network and address
5. Execute to see all token balances

## Troubleshooting

### "Authorization failed" or 401 errors

1. Verify your API Key Name is correct (should include `organizations/` and `apiKeys/`)
2. Ensure your private key is complete (includes `-----BEGIN` and `-----END` lines)
3. Check that your API key has the required permissions
4. Test the credential connection using the "Test" button in the credential modal

### Private key format issues

If you get "Failed to parse EC private key":
- Make sure there are no extra spaces or characters
- If copying from a file, include the full key with header/footer
- Try converting literal `\n` to actual newlines or vice versa

## Development

### Local Development Setup

```bash
# Clone repository
git clone <your-repo-url>
cd n8n-nodes-coinbase-cdp

# Install dependencies
npm install

# Build
npm run build

# Link for local testing
npm link
cd ~/.n8n/custom
npm init -y
npm link n8n-nodes-coinbase-cdp

# Start n8n
n8n start
```

### Commands

```bash
npm run build        # Build TypeScript and copy icons
npm run dev          # Watch mode for development
npm test             # Run tests
npm run format       # Format code with Prettier
npm run lint         # Lint code
npm run lintfix      # Fix linting issues
```

## Tech Stack

- Built with TypeScript
- Generated from [Coinbase Advanced Trade OpenAPI specification](https://docs.cdp.coinbase.com/advanced-trade/docs/rest-api-overview)
- Uses `@devlikeapro/n8n-openapi-node` for OpenAPI integration
- JWT authentication with ES256 algorithm

## Resources

- [Coinbase Developer Platform Documentation](https://docs.cdp.coinbase.com/)
- [Advanced Trade API Reference](https://docs.cdp.coinbase.com/advanced-trade/reference)
- [n8n Community Nodes Documentation](https://docs.n8n.io/integrations/community-nodes/)

## License

[MIT](LICENSE)

## Support

For issues, questions, or contributions:
- Open an issue on GitHub
- Check existing issues for solutions
- Contribute via pull requests

## Changelog

See [CHANGELOG.md](CHANGELOG.md) for version history and updates.
