Manage Bitcoin with the Coinbase API

By  on  

One of my biggest recent regrets was not pouring money into bitcoin when Kim Dotcom said we should; this was approximately 18 months ago when the bitcoin value was $170.  Today bitcoin value has topped $1000 which is why I'm kicking myself so hard.  I buy my bitcoin through Coinbase, a very user friendly, reliably vendor that makes bitcoin seem less scary to anyone that doesn't know the blockchain up and down.

In the past I've detailed a few ways to get the bitcoin value at any given time.  I wanted to write a short post bringing to light that Coinbase also has an awesome API for buying, selling, sending, and managing bitcoin via Node.js:

var Client = require('coinbase').Client;

// API capabilities for your account must be enabled
// within the Coinbase account settings
var client = new Client({
    'apiKey': '#####',
    'apiSecret': '#####'
});

// Get accounts and their bitcoin balance
client.getAccounts({}, (err, accounts) => {
  accounts.forEach(account => {
      console.log(`${account.name}: ${account.balance.amount} ${account.balance.currency}`);
      // My Wallet: 12.03 BTC
  });
});

// Get the current bitcoin buy price:
client.getBuyPrice({'currencyPair': 'BTC-USD'}, (err, info) => {
  console.log(`Buy Price: ${info.data.amount}`);
});

// Selling bitcoin
account.sell({ amount: "1", currency: "BTC" }, (err, transaction) => {
  console.log(`Transaction ID is: ${transaction.id}`);
});

// Sending bitcoin
account.requestMoney({
  "to": "someuser@outthere.com",
  "amount": "1.001",
  "currency": "BTC",
  "description": "This is payment for ...."
}, (err, transaction) => {
  console.log(`Transaction ID is: ${transaction.id}`);
});

There are a lot of cryptic sites out there for bitcoin and alt-coin trading; most of them are probably legit but I guess I enjoy the piece of mind provided by a professional site with lots of awesome tools and loads of security features.  The fact that Coinbase also provides an excellent API is another reason I'm sticking with them.

Kim Dotcom recently said he sees bitcoin at the $2000 level by the end of 2017 and $10000 by the end of 2020.  That would be ... mental.  Anyways, I get asked who I use quite a bit and, as you can see, I really love Coinbase.  Happy mining!

Recent Features

  • By
    Responsive Images: The Ultimate Guide

    Chances are that any Web designers using our Ghostlab browser testing app, which allows seamless testing across all devices simultaneously, will have worked with responsive design in some shape or form. And as today's websites and devices become ever more varied, a plethora of responsive images...

  • By
    CSS Animations Between Media Queries

    CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very little CSS code. Quite often we add CSS transforms to elements via CSS during...

Incredible Demos

  • By
    MooTools Text Flipping

    There are lots and lots of useless but fun JavaScript techniques out there. This is another one of them. One popular April Fools joke I quickly got tired of was websites transforming their text upside down. I found a jQuery Plugin by Paul...

  • By
    CSS content and attr

    CSS is becoming more and more powerful but in the sense that it allows us to do the little things easily.  There have been larger features added like transitions, animations, and transforms, but one feature that goes under the radar is generated content.  You saw a...

Discussion

  1. Anonymous

    well those predictions were exceeded quite a bit this week! hope you still have those 12btc and i wish i jumped on the band wagon prior to this week.

    thanks for code samples !

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!