BitCoinJ for Cloud based application

3

I am currently working on a cloud based project that will be accepting payments using bitcoins. I intend to use BitCoinJ to handle the payment. Unfortunately the only help I am able to get is from the JavaWorld demo, which seems to be out of sync with the current code. Could you please point me to some better/updated helping links/material.

Raghav Bali

Posted 2013-02-16T19:04:48.590

Reputation: 101

Answers

1

WalletAppKit kit=new WalletAppKit(MainNetParams.get(), new File("."), "mywalletfilename");
kit.setAutoSave(true);
kit.startAsync();
kit.awaitRunning();
kit.wallet().addEventListener(new WalletListener());

while listener looks like:

public class WalletListener  extends AbstractWalletEventListener {
public WalletListener() {
}

@Override
public void onCoinsReceived(org.bitcoinj.core.Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
    System.out.println("-----> coins resceived: " + tx.getHashAsString()+" prevBalance = "+prevBalance.getValue()+" newBal="+newBalance.getValue());
    System.out.println("received: " + tx.getValue(wallet));
}

@Override
public void onTransactionConfidenceChanged(org.bitcoinj.core.Wallet wallet, Transaction tx) {
    System.out.println("-----> confidence changed: " + tx.getHashAsString());
    TransactionConfidence confidence = tx.getConfidence();
    System.out.println("new block depth: " + confidence.getDepthInBlocks());
}

@Override
public void onCoinsSent(org.bitcoinj.core.Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
    System.out.println("coins sent");
}

@Override
public void onReorganize(org.bitcoinj.core.Wallet wallet) {
}

@Override
public void onWalletChanged(org.bitcoinj.core.Wallet wallet) {
}

@Override
public void onKeysAdded(List<ECKey> keys) {
    System.out.println("new key added");
}

    /*@Override
    public void onScriptsAdded(Wallet wallet, List<Script> scripts) {
        System.out.println("new script added");
    }*/

}

Should be working enough for receiving BTC ;) dont forget TXConfidence changed where it tells you that TX confirmations count changed and to what it changed... ;-)

Wenza

Posted 2013-02-16T19:04:48.590

Reputation: 41

1

There are some examples in the bitcoinj library itself which are always up to date (as they are part of the build).

The command line tool 'WalletTool' that Mike wrote is pretty useful for the basics of wallet creation, sending, receiving etc.

jim618

Posted 2013-02-16T19:04:48.590

Reputation: 3 205