JAVA / Android Library

Andreas Petersson &
Harald Schilly

## What's Bitcoin?
Bitcoin is an experimental new digital currency that enables instant payments to anyone, anywhere in the world. Bitcoin uses peer-to-peer technology to operate with no central authority: managing transactions and issuing money are carried out collectively by the network.
## In Short *
You are your own bank!
* Money is stored in your machine. * worldwide * instant * ... and chargebacks are impossible!
## What's the differece? * No middleman * No contract * No TOS to care about.
## Scared? You can also rely on a third-party service: * []( secure online wallet with an API * [BitPay]( full blown merchant solution * [Paysius]( US only :( * [WalletBit]( POS solutions
## Types of clients * [Classic "Satoshi" client]( * BitcoinJ * Forks / Alternative Implementations
## Resource Comparison
  • Satoshi client: 4800MB
  • Multibit: 21MB
  • BitcoinJ on Android: 5MB
## Projects using BitcoinJ * [Bitcoin Wallet for Android]( * [Multibit]( * Satoshidice * Tons of lesser known applications
## BitcoinJ Project * Started as a 20% project at Google * First Rev: March 4th, 2011 * Main Devs: [Mike Hearn](, [Miron Cuperman](, [Matt Corallo]( * Apache 2.0 Licensed * Still actively developed; alpha stage
BitcoinJ Website
## Goals * Java implementation of the Bitcoin protocol * Lightweight client for the Android ecosystem * Simple library for desktop applications * Suiteable for server-side processing
## Main Features
  • Manage a local Bitcoin wallet (no server!)
  • Connect and listen to other Bitcoin nodes directly
  • Send/recieve Bitcoins w/o storing the full blockchain (simplified payment verification)
## Ingredients * Public/Private Key in Wallet * Connection to Peers * Storage of past transactions (if necessary)
## Security BitcoinJ relies on the network to verify transactions. Only valid transactions are propagated and BitcoinJ checks if it receives its own transactions.
## BitcoinJ is not ... * a full Bitcoin node * fire-and-forget * 1.0 quality release
## The API

Show us the code!


File walletFile = new File("coins.dat");
try {
  wallet = Wallet.loadFromFile(walletFile);
} catch (IOException e) {
  wallet = new Wallet(params);
  wallet.addKey(new ECKey());

Network Type

For testing
NetworkParameters params = 
For production:
NetworkParameters params = 


Transform a public address to ...
Address a1 =
   new Address(params, "1HaSchNbFfLF8MJw41QNie7RPePPqdTozb");

Public/Private Key

ECKey key = new ECKey();
byte[] publicKey = key.getPubKey();
Gets the address corresponding to the public key.
Address addr = key.toAddress(params);

Connect to Network

final PeerGroup peerGroup =
  new PeerGroup(blockStore, params, chain);
peerGroup.setUserAgent("MyApp", "1.2");
  new PeerAddress(InetAddress.getLocalHost()));

Payment Notification

  new AbstractWalletEventListener() {
  public void onCoinsReceived(
      Wallet w,
      Transaction tx,
      BigInteger prevBalance,
      BigInteger newBalance) {
         // Running on a peer thread.

Introspect Payment

// Wallet w, Transaction tx;
TransactionInput input = tx.getInputs().get(0);
Address from = input.getFromAddress();
BigInteger value = tx.getValueSentToMe(w);
Note: For each payment request, generate a new address.

Send a Payment

// Address to; Wallet w
Wallet.SendResult sendResult =
    w.sendCoins(peerGroup, to, value);
println("Sent coins! TX=" +
Note: sendResult could be null.
## The Future of BitcoinJ * Full verification capability * Multisig support * External hardware wallets * Bloom filtering
## Bitcoin Network * No middleman: only *your* piece of software * No contract * No TOS to care about.




© 2012 Harald Schilly & Andreas Petersson


License: CC BY-SA

Based on work by Hakim El Hattab
Details: git blame ;-)