Bitcoinj: Multiple wallets

3

2

In my Java application I am now required to handle multiple bitcoin wallets (HD wallets?). This means sending and receiving BTC. Unfortunately bitcoin is quite new for me, so there are some questions:

Would it be possible to use BitcoinJ in order to do this? Is it performing well with hundrets of wallets (or more)? If not, what would be the alternative?

Regarding the workflow: Of course the private key will stay on the user side and thus cannot be read by the application itself. Would it still be possible to raise events like "money received" without having the private key of the wallet?

einherjer

Posted 2015-10-24T21:52:22.827

Reputation: 45

Concerning the second question, I did it using watch addresses.fcracker79 2016-01-24T21:59:17.970

Answers

1

I had the same doubt. I've done a little research in the library bitcoinj, and I think that it is possible to use multiple wallets at the same time. I recommend you first work with a single wallet so that you can understand a little how it works the library. I leave an example:

public class MainClass {
    private static final File BLOCKCHAIN_FILE = new File("block.dat");
    private static final NetworkParameters NET_PARAMS = MainNetParams.get();

    public static void main(String[] args) throws Exception {

        List<Wallet> wallets = getWallets();
        BlockStore blockStore = new SPVBlockStore(NET_PARAMS, BLOCKCHAIN_FILE);
        BlockChain blockChain = new BlockChain(NET_PARAMS, wallets, blockStore);
        PeerGroup peerGroup = new PeerGroup(NET_PARAMS, blockChain);

        for (Wallet w : wallets) {
            peerGroup.addWallet(w);
        }

        //Starting peerGroup;
        peerGroup.startAsync();

        //Start download blockchain
        peerGroup.downloadBlockChain();
    }

    public static List<Wallet> getWallets() throws UnreadableWalletException {

        List<Wallet> wallets = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Wallet w = Wallet.loadFromFile(new File("wallet_" + i + ".dat"), null);
            wallets.add(w);
        }

        return wallets;
    }
}

Ander Acosta

Posted 2015-10-24T21:52:22.827

Reputation: 372

0

You can use bitcoinj with multiple wallets (just use peerGroup.addWallet(wallet) multiple times), but it isn't designed to scale well in such a scenario. Depending on your resources and the activity on the wallets, two, three or five wallets might work ok. But hundreds will almost certainly not work.

Andreas Schildbach

Posted 2015-10-24T21:52:22.827

Reputation: 499