# coinbase

> The Coinbase API for Node.js

Latest version **2.0.8** (published 2018-04-18) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install coinbase
pnpm add coinbase
yarn add coinbase
bun add coinbase
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.8 |
| Published | 2018-04-18 |
| First published | 2013-05-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/coinbase) |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 148.4 KB |
| Known vulnerabilities | 0 (+6 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 364 |
| Author | Coinbase |
| Maintainers | coinbase, kbcbhq, maksim, sds |
| Keywords | API, bitcoin, coinbase, real-time, payments |

## Links

- npm: https://www.npmjs.com/package/coinbase
- Repository: https://github.com/coinbase/coinbase-node
- Issues: https://github.com/coinbase/coinbase-node/issues
- npm.io page: https://npm.io/package/coinbase

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) 3.1.0
- [request](https://npm.io/package/request.md) 2.85.0
- [http-errors](https://npm.io/package/http-errors.md) 1.3.1
- [object-assign](https://npm.io/package/object-assign.md) 2.0.0

## Recent versions

- 2.0.8 (latest) — 2018-04-18
- 2.0.7 — 2018-01-09
- 2.0.6 — 2016-09-06
- 2.0.5 — 2016-04-26
- 2.0.4 — 2016-02-18
- 2.0.3 — 2016-02-17
- 2.0.2 — 2016-01-04
- 2.0.1 — 2015-12-31
- 2.0.0 — 2015-10-19
- 1.0.4 — 2015-09-22
- 1.0.3 — 2015-07-07
- 1.0.2 — 2015-03-18
- 1.0.1 — 2015-03-18
- 0.1.4 — 2015-01-11
- 0.1.3 — 2014-08-21
- … 4 more at https://npm.io/package/coinbase/versions

## README

# Coinbase

The official Node.js library for the [Coinbase API](https://developers.coinbase.com/api/v2).

## Features

* Full Test coverage.
* Support for both [API Key + Secret](https://developers.coinbase.com/api/v2#api-key) and [OAuth 2](https://developers.coinbase.com/api/v2#oauth2-coinbase-connect) authentication.
* Convenient methods for making calls to the API.
* Automatic parsing of API responses into relevant Javascript objects.
* Adheres to the nodejs error-first callback protocol.
* Continuous Integration testing against node 0.10, 0.11, and 0.12.

## Installation

`npm install coinbase`

## Version Compatibility

Version | GitHub repository
--------|------------------
`2.0.x` | This repository
`0.1.x` | [mateodelnorte/coinbase](https://github.com/mateodelnorte/coinbase)

Npm `coinbase` package name used to refer to the unofficial [coinbase](https://github.com/mateodelnorte/coinbase) library maintained by [Matt Walters](https://github.com/mateodelnorte). Matt graciously allowed us to use the name for this package instead. You can still find that package on [Github](https://github.com/mateodelnorte/coinbase). Thanks, Matt.

## Quick Start

The first thing you'll need to do is [sign up for coinbase](https://coinbase.com).

## API Key

If you're writing code for your own Coinbase account, [enable an API key](https://coinbase.com/settings/api). Next, create a ``Client`` object for interacting with the API:


```javascript
var Client = require('coinbase').Client;
var client = new Client({'apiKey': mykey, 'apiSecret': mysecret});
```

## OAuth2

If you're writing code that will act on behalf of another user, start by
[creating a new OAuth 2 application](https://coinbase.com/oauth/applications). You will need to do some work to obtain OAuth credentials for your users; while outside the scope of this document, please refer to our [OAuth 2 tutorial](https://developers.coinbase.com/docs/wallet/coinbase-connect/integrating) and [documentation](https://developers.coinbase.com/docs/wallet/coinbase-connect/reference). Once you have these credentials, create a client:

```javascript
var Client = require('coinbase').Client;
var client = new Client({'accessToken': accessToken, 'refreshToken': refreshToken});
```

## Making API Calls

With a `client instance`, you can now make API calls. We've included some examples below, but in general the library has Javascript prototypes for each of the objects described in our [REST API documentation](https://developers.coinbase.com/api/v2).  These classes each have methods for making the relevant API calls; for instance, ``coinbase.model.Transaction.complete`` maps to the [complete bitcoin request](https://developers.coinbase.com/api/v2#complete-request-money) API endpoint. The comments of each method in the code references the endpoint it implements. Each API method returns an ``object`` representing the JSON response from the API.

**Listing available accounts**

```javascript
var coinbase = require('coinbase');
var client   = new coinbase.Client({'apiKey': mykey, 'apiSecret': mysecret});

client.getAccounts({}, function(err, accounts) {
  accounts.forEach(function(acct) {
    console.log('my bal: ' + acct.balance.amount + ' for ' + acct.name);
  });
});
```

**Get Balance from an Account Id**

```javascript
var coinbase = require('coinbase');
var client   = new coinbase.Client({'apiKey': mykey, 'apiSecret': mysecret});

client.getAccount('<ACCOUNT ID>', function(err, account) {
  console.log('bal: ' + account.balance.amount + ' currency: ' + account.balance.currency);
});
```

**Selling bitcoin**

```javascript
var args = {
  "amount": "12",
  "currency": "BTC"
};
account.sell(args, function(err, xfer) {
  console.log('my xfer id is: ' + xfer.id);
});
```

**Sending bitcoin**

```javascript
var args = {
  "to": "user1@example.com",
  "amount": "1.234",
  "currency": "BTC",
  "description": "Sample transaction for you"
};
account.sendMoney(args, function(err, txn) {
  console.log('my txn id is: ' + txn.id);
});
```

**Requesting bitcoin**

```javascript
var args = {
  "to": "user1@example.com",
  "amount": "1.234",
  "currency": "BTC",
  "description": "Sample transaction for you"
};
account.requestMoney(args, function(err, txn) {
  console.log('my txn id is: ' + txn.id);
});
```

**Listing current transactions**

```javascript
account.getTransactions(null, function(err, txns) {
  txns.forEach(function(txn) {
    console.log('my txn status: ' + txn.status);
  });
});
```

**Using pagination**

```javascript
account.getTransactions(null, function(err, txns, pagination) {
  txns.forEach(function(txn) {
    console.log('my txn: ' + txn.id);
  });
  console.log(pagination.next_uri);
  account.getTransactions(pagination, function(err, txns) {
    txns.forEach(function(txn) {
      console.log('my txn: ' + txn.id);
    });
  });
});
```

**Checking bitcoin prices**

```javascript
client.getBuyPrice({'currencyPair': 'BTC-USD'}, function(err, obj) {
  console.log('total amount: ' + obj.data.amount);
});
```

**Verifying merchant callback authenticity**
```javascript
if (client.verifyCallback(req.raw_body, req.headers['CB-SIGNATURE'])) {
  // Process callback
}
```

## Error Handling

Errors are thrown for invalid arguments but are otherwise returned as the
first argument to callback functions using [http-errors](https://github.com/jshttp/http-errors) module.

Errors contain `name`, `status`, and `message` fields for error handling. You can find
more information about error types [here](https://developers.coinbase.com/api/v2#errors)

## Testing / Contributing

Any and all contributions are welcome! The process is simple:

1. Fork this repo
2. Make your changes and add tests
3. Run the test suite
4. Submit a pull request.

Tests are run via [mocha](http://mochajs.org) and [nock](https://github.com/pgte/nock). To run the tests, clone the repository and then:

`npm install`

`npm test`

Please also scan the packages for known vulnerabilities.

```bash
npm install -g nsp
nsp check --output summary
```

You can also run the tests against various node environments using the Dockerfile.example file.

1. `cp Dockerfile.example Dockerfile`
2. edit Dockerfile and uncomment the node version that interests you
3. `[sudo] docker build -t coinbase-node .`
4. `[sudo] docker run -it coinbase-node`

---
_Source: https://npm.io/package/coinbase · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
