I am trying to iterate through the ethereum ldb files. When I run this code my iterator believes there is nothing stored on the ropsten's testnet blockchain. There are no errors, and the iter gets to the for loop's test for whether it hasNext(). So it loads the DB properly, just doesn't recognize the keys.

I am using Dain's LevelDB API.

public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub

    Options options = new Options();
    ReadOptions ROoptions = new ReadOptions();
    try {
        DB db = factory.open(new File("chaindata"), options);
        try {
            // Use the db in here....
            System.out.println("Creating itr");
            DBIterator iterator = db.iterator(ROoptions);
            try {
                System.out.println("Testing itr");
                for (iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {
                    String key = asString(iterator.peekNext().getKey());
                    String value = asString(iterator.peekNext().getValue());
                    System.out.println(key + " = " + value);
            } finally {
                // Make sure you close the iterator to avoid resource leaks.

        } finally {
            // Make sure you close the db to shutdown the
            // database and avoid resource leaks.
    } catch (FileNotFoundException E) {
        System.out.println("File not found! " + E);
        throw new FileNotFoundException();


  • I doubt somebody could help you with this one, you put the code and said "it doesn't work", this doesn't help us. Run a debugger, watch the variables, and then if you have a specific question, post it
    – Nulik
    Oct 8 '17 at 3:38

Two things were wrong with my code.

  1. The source of the folder was incorrect, so I was not grabbing the right files.

  2. Dain's levelDB only works with .sst files and not .ldb. LevelDB updated because of a conflict with the Windows core files. This caused me issues after I fixed the folder issue.

I hope this helps someone else in the future.


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.