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');
}
:pimp
|