npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

coinbase-fork

v2.0.9

Published

The Coinbase API for Node.js

Downloads

2

Readme

Coinbase

The official Node.js library for the Coinbase API.

Features

  • Full Test coverage.
  • Support for both API Key + Secret and OAuth 2 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

Npm coinbase package name used to refer to the unofficial coinbase library maintained by Matt Walters. Matt graciously allowed us to use the name for this package instead. You can still find that package on Github. Thanks, Matt.

Quick Start

The first thing you'll need to do is sign up for coinbase.

API Key

If you're writing code for your own Coinbase account, enable an API key. Next, create a Client object for interacting with the API:

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. 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 and documentation. Once you have these credentials, create a client:

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. These classes each have methods for making the relevant API calls; for instance, coinbase.model.Transaction.complete maps to the complete bitcoin request 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

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

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

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

Sending bitcoin

var args = {
  "to": "[email protected]",
  "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

var args = {
  "to": "[email protected]",
  "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

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

Using pagination

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

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

Verifying merchant callback authenticity

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 module.

Errors contain name, status, and message fields for error handling. You can find more information about error types here

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 and nock. To run the tests, clone the repository and then:

npm install

npm test

Please also scan the packages for known vulnerabilities.

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