4

I want to make a basic program/script that utilizes Bitcoin payments, but I don't have the storage space to sync with the entire blockchain, and I don't want to be dependent on a third-party API like those offered by blockchain.info or block.io.

Basically, I need a wallet with these three properies:

  • Lightweight (i.e. doesn't require the full blockchain)
  • Has a CLI to generate and return a receiving address on command
  • Has a CLI to get the total wallet balance

I'm vaguely familiar with thin clients such as Electrum, MultiBit, and MultiBit HD, and I know Electrum even has a CLI, but there doesn't seem to be anything in their documentation about generating new addresses:

https://docs.electrum.org/en/latest/cmdline.html

I've read that Electrum wallets work with a queue of addresses and generate new ones automatically after they have been used, so even if I could just get a list of addresses associated with the wallet I could get something like the functionality I want. But again, the CLI seems really limited.

All in all, I'm frustrated. Surely there is a way to do what I am trying to do, and if there isn't an obvious solution, why not? It seems counterintuitive that I should have to use centralized services and APIs for basic wallet functionality just because I can't afford to rent a server with 90+GB of space to store the blockchain.

2
  • Since Bitcoin Core 0.12 you can run in pruning mode, where you still sync and fully verify and download all transactions, but only the last blocks are kept on disk. This allows you to run a fully validating node with all CLI functions (except rescan) with ~2GB disk space. Commented Feb 4, 2017 at 19:07
  • @PieterWuille excellent suggestion! Could you post that as an answer?
    – user45779
    Commented Feb 4, 2017 at 20:17

2 Answers 2

4

If you don't want to run a node or use any 3rd party APIs you can use a library since you only want to accept payments.

Use an extended public key from one of your wallets, and generate new addresses from the HD xpub using a library. When a user pays it will show up in your Phone/PC wallet.

For example with Bitcore library it would be:

var bitcore = require("bitcore-lib");

var pub = new bitcore.HDPublicKey('xpubMyHDPublicKey');
var derivedHdPublicKey = pub.derive('m/0/1'); 
//increment up the keychain m/0/2, m/0/3, etc each order
var derivedPublicKey = derivedHdPublicKey.publicKey;
var address = new bitcore.Address(derivedPublicKey);
console.log(address);

Then just keep track of orders and addresses on your server database.

6
  • 1
    It's you! I bought a copy of your book "Building Bitcoin Websites" over winter break, and I was actually watching a few of your videos on YouTube today from your Bitcoin JSON-RPC tutorial series. I was planning on just using a similar setup for this project, but this solution seems even simpler. Thanks for the answer, and more than that, thank you for all of your interest and work in making Bitcoin more accessible for the average developer. You rock man!
    – user45779
    Commented Feb 5, 2017 at 0:15
  • Also, do you know of any similar libraries for server-side execution (i.e. sans JavaScript?)
    – user45779
    Commented Feb 5, 2017 at 0:45
  • Thanks for the positive feedback Rick! The bitcore lib is server side with nodejs, another one would be the bitcoinjs-lib(npmjs.com/package/bitcoinjs-lib). I've heard that bit-wasp for PHP will work as well, but I have not tried it myself.
    – m1xolyd1an
    Commented Feb 5, 2017 at 1:12
  • So this may be a noobish question, but how do I find my extended public key from a wallet like bitcoin core?
    – user45779
    Commented Feb 5, 2017 at 19:08
  • bitcoin.stackexchange.com/questions/50244/…
    – m1xolyd1an
    Commented Feb 5, 2017 at 21:44
0

The Mycelium Gear is probably the most practical way to go. While technically it's a 3rd party, the money is not routed through them, and thus no KYC/AML, no censorship, and no commission. Mycelium Gear simply notifies you about the incoming payments based on your HD wallet xpubkey.

Alternatively, you can setup their open source software yourself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.