- Download and install Node.js and npm (comes with Node.js)
- Download this code
- Change to the directory where the source code is (with a terminal)
- Type
npm install
to install module dependencies - Edit
app.js
and edit the "settings" section - Run the app by typing
node app.js
Last active
December 12, 2015 10:09
-
-
Save maxkueng/4757191 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -- settings / edit below | |
var DEMO_MODE = true; // set this to false to enable sending bitcoins | |
var BTC_AMOUNT = 0.01; // amount in BTC to send to each address | |
var TWITTER_TRACK_KEYWORD = '@BTCForMe'; | |
// Twitter API credentials. Get them here: https://dev.twitter.com/apps/new | |
var TWITTER_CONSUMER_KEY = '**********'; | |
var TWITTER_CONSUMER_SECRET = '**********'; | |
var TWITTER_ACCESS_TOKEN_KEY = '**********'; | |
var TWITTER_ACCESS_TOKEN_SECRET = '**********'; | |
// You could also use your Bitcoin client's JSON-RPC interface instead of blockchain.info | |
var JSONRPC_USER = '********-****-****-****-************'; // e.g. blockchain.info wallet identifier | |
var JSONRPC_PASSWORD = '**********'; // e.g. blockchain.info wallet password | |
var JSONRPC_HOST = 'blockchain.info'; | |
var JSONRPC_PORT = 80; | |
// -- end of settings | |
var Twitter = require('ntwitter'); | |
var bitcoin = require('bitcoin'); | |
var client = new bitcoin.Client({ | |
'host' : JSONRPC_HOST, | |
'port' : JSONRPC_PORT, | |
'user' : JSONRPC_USER, | |
'pass' : JSONRPC_PASSWORD | |
}); | |
var findBitcoinAddress = function (tweet) { | |
var matches = /[123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ]{25,34}/.exec(tweet); | |
if (matches && matches[0]) { | |
return matches[0]; | |
} | |
return false; | |
}; | |
var twit = new Twitter({ | |
'consumer_key' : TWITTER_CONSUMER_KEY, | |
'consumer_secret' : TWITTER_CONSUMER_SECRET, | |
'access_token_key' : TWITTER_ACCESS_TOKEN_KEY, | |
'access_token_secret' : TWITTER_ACCESS_TOKEN_SECRET | |
}); | |
twit.stream('statuses/filter', { | |
'track' : TWITTER_TRACK_KEYWORD | |
}, function (stream) { | |
stream.on('data', function (data) { | |
var bitcoinAddress = findBitcoinAddress(data.text); | |
if (!bitcoinAddress) { return console.error('Tweet does not contain a bitcoin address'); } | |
client.validateAddress(bitcoinAddress, function (err, check) { | |
if (err) return console.error(err); | |
if (check.isvalid) { | |
if (DEMO_MODE === false) { | |
client.sendToAddress(bitcoinAddress, BTC_AMOUNT, function (err, transactionId) { | |
if (err) return console.error(err); | |
console.info('Sent', BTC_AMOUNT, 'BTC to', bitcoinAddress); | |
console.info('Transaction:', transactionId); | |
}); | |
} else { | |
console.info('DEMO MODE:', 'Didn\'t send', BTC_AMOUNT, 'BTC to', bitcoinAddress); | |
} | |
} | |
}); | |
}); | |
stream.on('error', function (err) { | |
console.error(err); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name" : "BTCForMe", | |
"version" : "0.0.1", | |
"dependencies" : { | |
"ntwitter": "*", | |
"bitcoin" : "*" | |
}, | |
"engines" : { | |
"node" : "*" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment