View Single Post
Old 06-26-2017, 05:41 AM  
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,329
my code for creating btc addresses

I use this for my coinbase (this only works with coinbase api) use it the list all btc addresses in account, create a new address, list buy and sell prices, hopefully this is useful to someone .

node module coinbase needs to be installed.

Code:
#!/usr/bin/node

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

var client = new Client({
    'apiKey': 'apikeyhere',
    'apiSecret': 'apisecrethere'
});

var btcaccount = 'accountidhere';

if (process.argv.length <= 2) {
    console.log("usage: btc buyprice|sellprice|list|create");
    process.exit(-1);
}

switch (process.argv[2]) {

    case 'buyprice':
        client.getBuyPrice({'currencyPair': 'BTC-USD'}, function(err, price) {
                console.log('$' + price.data.amount);
        });
        break;

    case 'sellprice':
        client.getSellPrice({'currencyPair': 'BTC-USD'}, function(err, price) {
                console.log('$' + price.data.amount);
        });
        break;

    case 'create':
        client.getAccount(btcaccount, function(err, account) {
            account.createAddress(null, function(err, address) {
                console.log(address.address);
            });
        });
        break;

    case 'list':
        client.getAccount(btcaccount, function(err, account) {
            account.getAddresses(null, function(err, addresses) {
                addresses.forEach(function(item) {
                    console.log(item.address)
                })
            });
        });
        break;

    default:
        console.log('Not a Valid Command');
}
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote