Home

Awesome

Accept Bitcoin accept-bitcoin

Finally a developer-friendly tool to simply accept bitcoins in your site.

Get Started

Simply install via npm:

npm install accept-bitcoin

Load AC and you're ready to go!

var acceptBitcoin = require('accept-bitcoin');
var ac = new acceptBitcoin('YOUR_BITCOIN_ADDRESS');

Motivation

Accepting bitcoins online can be complex to program and require you to install a bitcoin RPC client in order to read and write to the blockchain. This client require a lot of resources (in terms of CPU, networking and storage).
Most of the users are using a wallet to store their bitcoins. This wallet is a simple way to secure your public and private key. For security reasons you better save this wallet offline in a "cold storage".
More about the motivation behind this project at my blog post.

Example

You can override the default settings on creating

Examples are provided here

var settings = {network: 'live'}
var acceptBitcoin = require('accept-bitcoin');
var ac = new acceptBitcoin('YOUR_BITCOIN_ADDRESS', settings);
key = ac.generateAddress({alertWhenHasBalance: true});
console.log("Hello buyer! please pay to: " + key.address());
key.on('hasBalance', function(amount){
  console.log("thanks for paying me " + amount); //do stuff
  key.transferBalanceToMyAccount(function(err, d){
    if (d.status === 'success') console.log("Cool, the bitcoins are in my private account!");
  });
});

Settings

You can override the default settings:

nametypedefault valuecomment
payToAddressstring-Your bitcoin adress you wish to transfer incomes to.
networkstringtestchoose your bitcoin RPC env. values are: test and livemore info here
passwordstring-choose your random password to encrypt generated keys.
storePathstring./keys.txtpath to store a file containing all the ad-hoc generated keys.
encryptPrivateKeyboolfalsein case you want the stored keys to be encrypted (using password).
payReminderToAddressstringpayToAddressIn case transfer amount is smaller than income and fees.
includeUnconfirmedboolfalseinclude unconfirmed transactions when checking for unspent incomes
checkTransactionEveryint1000 * 60 * 2 (2 minutes)how often (in millisecond) to ping the network when checking for transactions.
checkBalanceTimeoutint1000 * 60 * 60 * 2 (2 hours)timeout (in millisecond) when checking balance of an address.
checkUnspentTimeoutint1000 * 60 * 60 * 2 (2 hours)timeout (in millisecond) when checking unspent transactions of an address.
minimumConfirmationsint6minimum confirmations needed in order to trigger hasBalance event.
txFeefloat0.0001fee (in bitcoin) for transferring amount from ad hoc address to your address.

Key class

This class is responsible for creating new bitcoin addresses, storing them and transferring funds between them. Some key functions are:
storeKey(wk) - store your key in a local file. Can be encrypted.
checkBalance()- check and notify you when an address has minimum balance. payTo(payToAddress, options, callback) - transfer all balance of this address to another address.

Encrypt class

Contains helpers to encrypt and decrypt strings. Used for storing your keys data locally.

Contribute

Please do. Fork it, star it, share it and add your code to the project. Help others.
All the src code is written in coffeescript and is under src. There's a tool that convert it automatically to js each time you change a file and put it under lib folder. Simply run cake build for that.

License

MIT