Join
June 1, 2026
Login

Java: bitcoinj; how to download a full block?

I would like to download a full block using Java and bitcoinj and then parse it to an array to be able to work with it. Here is some (very basic) pseudocode:

connect to network;  
download latestBlock;  
write/convert block to readable array;  
read blockArray;  
   sout: blockArray[23][55] // this should get me eg. a txid, address, ...  
// or similar. I just want to be able to read values from the block 

Is there a way to do this? I found the following solution here (Using bitcoinj to discover peers and download the block chain):

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);
    }
}

Unfortunately, kit.startAndWait() isn’t available anymore.

Can someone help me to get the latest block and be able to read its values?

Thank you very much 🙂

Previous Article

There’s talk of increasing the blocksize – if this can be achieved – does this mean that the 21m btc limit can also be changed?

Next Article

I have a old version of Bitcoin QT on Apple

You might be interested in …

Bitcoin Core 0.21.2 released

Bitcoin Core 0.21.2 released Bitcoin Core version 0.21.2 is now available for download. See the release notes for more information about the many new features and bug fixes in this release. If have any questions, […]

Bitcoin Core 0.20.1 Released

Bitcoin Core 0.20.1 Released Bitcoin Core version 0.20.1 is now available for download. For a complete list of changes in this new major version release, please see the release notes. If have any questions, please […]