Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
For Java developers, BitCoinJ is an entry point to developing applications that interact with the Bitcoin network. In this final article in a three-part series, Dirk Merkel helps you set up BitCoinJ in an Eclipse development environment, then walks through several short exercises that will familiarize you with this lightweight implementation of the Bitcoin transaction protocol.
Previous installments in this three-part series have introduced the conceptual and technological framework of Bitcoin, a virtual currency and peer-to-peer network. This article, a tutorial introduction to the BitCoinJ API, assumes that you are familiar with Bitcoin addresses, transactions, blocks, and the block chain.
BitCoinJ is an open source Java implementation of the Bitcoin protocol. As such, it's a handy tool to have if you want to write Java applications that interact with the Bitcoin network. In order to explore the BitCoinJ API, we'll construct various sample applications that illustrate the programming steps necessary to construct more complex Bitcoin applications in Java. After using Maven to built and set up a project in the Eclipse IDE, we'll practice creating a Bitcoin address, storing it in a wallet, and saving the wallet to disk. We'll then establish a connection to the Bitcoin test network and retrieve its genesis block. Finally, we'll tie together our sample code so far by sending some Bitcoins to an address on the test network.
BitCoinJ is a Java implementation of the Bitcoin protocol. Written by Mike Hearn, BitCoinJ is not a full implementation of the original Bitcoin client, but a more lightweight and accessible version. While it's solid enough to learn from, BitCoinJ is still under development (currently at v.0.3) and should not be used to move large numbers of Bitcoins.
BitCoinJ is hosted by Google Code in a Subversion repository, and can be anonymously checked out. Once you check out the trunk of the BitCoinJ project you'll be able to easily keep it updated. You will not, however, be able to commit any changes.
You can use the Subversion client built into your favorite IDE or simply check out the project from the command-line, as I did:
Once you have the code, you'll compile it with Maven, BitCoinJ's build system. Maven takes a lifecycle approach to building projects and is highly extensible with many core and third-party plugins. What Maven does exceedingly well is manage dependencies. If you look at the Maven pom.xml file in BitCoinJ's root directory, you'll see that it uses only a handful of dependencies; these include JUnit and EasyMock for unit testing, SLF4J for logging, and the Bouncy Castle Crypto APIs for cryptographic operations such as hashing and signing.
From the command-line, run mvn clean package and Maven will retrieve these and other dependencies, compile the project, run the unit test suite, and package the compiled
code into a snapshot JAR file. As shown in Figure 2, Maven first executes the clean lifecycle to get rid of any artifacts
from previous builds. It then executes the phases of the default lifecycle up to and including the package phase.
More from JavaWorld