3

I'm sorry everyone, I have looked and stared at the API and I'm coming up with nothing.

I've got a public static void main (naturally), but have no idea how to:

  1. Connect to the network
  2. Download the block chain
  3. Navigate through it.

The purpose of this is to keep the block chain as a record of transactions and perform reporting on my own transactions. I don't have my wallet on the same machine.

Unfortunately for me, my ability to read the api is still underdeveloped, and the various pages I've seen don't really go step by dummy step.

Most important of the above steps is, how to get the block chain...

3

The class WalletAppKit is a good start. Here's a snippet of code that dumps the most recent block, you can probably take it from here. It will take a while to download the block chain and then it will print out the most recent transactions.

public class DumpLastBlock {
public static void main(String args[]) throws Exception {
    WalletAppKit kit = new WalletAppKit(MainNetParams.get(), new java.io.File("."), "test");
    kit.startAndWait();
    BlockChain chain = kit.chain();
    BlockStore bs = chain.getBlockStore();
    Peer peer = kit.peerGroup().getDownloadPeer();
    Block b = peer.getBlock(bs.getChainHead().getHeader().getHash()).get();
    System.out.println(b);
}
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.