I got local private blockchain in:


How i can connect to it, to get chain data by ethereum.pow.chain.get_block(hash)? I know that to look at chain data i first must get state and in that point i have problem. I tried do like:

levelDB = leveldb.LevelDB('/Users/User/EthereumTestNet/geth/chaindata')
state = trie.Trie(levelDB, '81fe149a7edc2e26b6cb14c17077ed6fd0d31f3a2c6b3e48eb8c42908493cbdc'.decode('hex'))

levelDB = leveldb.LevelDB('/Users/User/EthereumTestNet/geth/chaindata')
state = trie.Trie(db.BaseDB(levelDB), '81fe149a7edc2e26b6cb14c17077ed6fd0d31f3a2c6b3e48eb8c42908493cbdc'.decode('hex'))

baseDB = db.BaseDB(filename='/Users/User/EthereumTestNet/geth/chaindata')
state = trie.Trie(db.EphemDB(), '81fe149a7edc2e26b6cb14c17077ed6fd0d31f3a2c6b3e48eb8c42908493cbdc'.decode('hex'))

No any ideas, can anybody help?

use last pyethereum, last geth, MacOS

2 Answers 2


I had the same issue. It looks like the database layer in pyethereum has been abstracted out such that databases other than leveldb can be used. The challenge is that even if you pass a leveldb object into the db parameter of trie.Trie(db, root_hash) you are going to have issues with the way it calls the get put and delete methods. Leveldb uses upper case Get Put and Delete and the internal code in Trie uses lowercase.

I worked around this by creating a new object to wrap the leveldb object and implemented the pyethereum method signature in ethereum.db.

So, create a file named something like db_leveldb.py:

import os
import leveldb
import ethereum.db

databases = {}

class DB(db.BaseDB):

    def __init__(self, dbfile):
        self.dbfile = dbfile
        if dbfile not in databases:
            databases[dbfile] = leveldb.LevelDB(dbfile)

        self.db = databases[dbfile]

    def get(self, key):
        return self.db.Get(key)

    def put(self, key, value):
        self.db.Put(key, value)

    def delete(self, key):

    def _has_key(self, key):
            return True
        except KeyError:
            return False

    def __contains__(self, key):
        return self._has_key(key)

    def __eq__(self, other):
        return isinstance(other, self.__class__) and self.db == other.db

Then use this object similar to the following:

import db_leveldb, ethereum.trie

state = trie.Trie(db_leveldb.DB('/Users/User/EthereumTestNet/geth/chaindata'), bytes.fromhex('81fe149a7edc2e26b6cb14c17077ed6fd0d31f3a2c6b3e48eb8c42908493cbdc'))

Hope this points you in the direction of a workable solution.


(This isn't a full answer - as I'm not familiar with how Pythereum does things - but might be a potential starting point.)

Have a look at the State() class in state.py.

This appears to have some code for the following:

  • Loading a state trie from a given root (line 138);
  • Getting data from the trie for a specific address (line 175);
  • Decoding that data from RLP format (line 177).
  • Can say even more - looked at it... that call in line 138 RefcountDB() get self.db, which is set in line 136 in env=Env() init in line 104. If look at Env __init__ we see that it need EphemDB or BaseDB to set self.db. So, i tried to create good EphemDB or BaseDB, but there are no init in them which can open local chain data
    – Gudsaf
    Commented Dec 3, 2017 at 18:18
  • About db you can see in db.py. BaseDB looks like main class which called by another db classes like _EphemDB or RefcountDB or... , but i am not understand how to send to BaseDB my database in /Users/User/EthereumTestNet/geth/chaindata
    – Gudsaf
    Commented Dec 3, 2017 at 18:31
  • I too am having this issue, I am trying to work with the mainnet while using pyethereum. Any ideas would be helpful.
    – Fortune
    Commented Dec 28, 2017 at 22:47
  • Did any of the ideas above help? Are you trying to read the same data? If not, you might want to start a new question. Commented Dec 29, 2017 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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