1

I am trying to run the following script using NodeJS to interface with the LevelDB files stored by Geth:

//Just getting the requirements
var Trie = require('merkle-patricia-tree/secure');
var levelup = require('levelup');
var leveldown = require('leveldown');
var RLP = require('rlp');
var assert = require('assert');

//Connecting to the leveldb database
var db = levelup(leveldown('/home/web3success/full-node-volumes/volumes/eth-docker_geth-eth1-data/_data/geth/chaindata'));


//Obtaining the state root (of the latest block) using this command web3.eth.getBlock(web3.eth.defaultBlock).stateRoot
//block 2 at the time
//var root = '0x55b3b55cac8793a38209f410541ee93926cd58e2d49f5b82e0e4501428c1a823';
//block 13 at time time
//var root = '0x73f842ee4f51b59cbcfa31d213720bae992f0679cc0f27dc9eb16f891ab08e11';
//block 23 at the time
var root = '0x8c77785e3e9171715dd34117b047dffe44575c32ede59bde39fbf5dc074f2976';
//Creating a trie object of the merkle-patricia-tree library
var trie = new Trie(db, root);

//Creating a nodejs stream object so that we can access the data
var stream = trie.createReadStream()

//Turning on the stream (because the node js stream is set to pause by default)
stream.on('data', function (data){
  //printing out the keys of the "state trie"
  var arrayOfStateValues = RLP.decode(data.value);
  for (i = 0; i < arrayOfStateValues.length; i++){ console.log(RLP.decode(arrayOfStateValues[i], [skipRemainderCheck=false])); console.log("");}
  
  
    });


/*
var arrayLength = arrayOfStateValues[0].length;
  console.log("This array has " + arrayLength + " elements");
    for (var i = 0; i < arrayLength; i++) {
        console.log("Item " + i);
        console.log(arrayOfStateValues[0][i]);
        console.log(" ");
    }
*/

When I try to run the script using node filename.js, I am getting the following error that says that the module named secure is not within the merkle-patricia-tree package:

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'merkle-patricia-tree/secure'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/home/web3success/ethereum_database_research_and_testing/leveldb/javascript/print_state_trie_keys.js:5:12)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

Before running the script, I have installed all the dependencies using npm and here's what I am getting when I run npm ls:

read-leveldb-geth@1.0.0 /home/web3success/ethereum_database_research_and_testing/leveldb/javascript
├─┬ assert@2.0.0
│ ├── es6-object-assign@1.1.0
│ ├─┬ is-nan@1.3.2
│ │ ├─┬ call-bind@1.0.2
│ │ │ ├── function-bind@1.1.1
│ │ │ └─┬ get-intrinsic@1.1.3
│ │ │   ├── function-bind@1.1.1 deduped
│ │ │   ├─┬ has@1.0.3
│ │ │   │ └── function-bind@1.1.1 deduped
│ │ │   └── has-symbols@1.0.3
│ │ └─┬ define-properties@1.1.4
│ │   ├─┬ has-property-descriptors@1.0.0
│ │   │ └── get-intrinsic@1.1.3 deduped
│ │   └── object-keys@1.1.1
│ ├─┬ object-is@1.1.5
│ │ ├── call-bind@1.0.2 deduped
│ │ └── define-properties@1.1.4 deduped
│ └─┬ util@0.12.5
│   ├── inherits@2.0.4
│   ├─┬ is-arguments@1.1.1
│   │ ├── call-bind@1.0.2 deduped
│   │ └─┬ has-tostringtag@1.0.0
│   │   └── has-symbols@1.0.3 deduped
│   ├─┬ is-generator-function@1.0.10
│   │ └── has-tostringtag@1.0.0 deduped
│   ├─┬ is-typed-array@1.1.10
│   │ ├── available-typed-arrays@1.0.5
│   │ ├── call-bind@1.0.2 deduped
│   │ ├─┬ for-each@0.3.3
│   │ │ └── is-callable@1.2.7
│   │ ├─┬ gopd@1.0.1
│   │ │ └── get-intrinsic@1.1.3 deduped
│   │ └── has-tostringtag@1.0.0 deduped
│   └─┬ which-typed-array@1.1.9
│     ├── available-typed-arrays@1.0.5 deduped
│     ├── call-bind@1.0.2 deduped
│     ├── for-each@0.3.3 deduped
│     ├── gopd@1.0.1 deduped
│     ├── has-tostringtag@1.0.0 deduped
│     └── is-typed-array@1.1.10 deduped
├─┬ ethereumjs-util@6.2.1
│ ├─┬ @types/bn.js@4.11.6
│ │ └── @types/node@18.11.17
│ ├── bn.js@4.12.0
│ ├─┬ create-hash@1.2.0
│ │ ├─┬ cipher-base@1.0.4
│ │ │ ├── inherits@2.0.4 deduped
│ │ │ └── safe-buffer@5.2.1 deduped
│ │ ├── inherits@2.0.4 deduped
│ │ ├─┬ md5.js@1.3.5
│ │ │ ├─┬ hash-base@3.1.0
│ │ │ │ ├── inherits@2.0.4 deduped
│ │ │ │ ├── readable-stream@3.6.0 deduped
│ │ │ │ └── safe-buffer@5.2.1 deduped
│ │ │ ├── inherits@2.0.4 deduped
│ │ │ └── safe-buffer@5.2.1 deduped
│ │ ├─┬ ripemd160@2.0.2
│ │ │ ├── hash-base@3.1.0 deduped
│ │ │ └── inherits@2.0.4 deduped
│ │ └─┬ sha.js@2.4.11
│ │   ├── inherits@2.0.4 deduped
│ │   └── safe-buffer@5.2.1 deduped
│ ├─┬ elliptic@6.5.4
│ │ ├── bn.js@4.12.0 deduped
│ │ ├── brorand@1.1.0
│ │ ├─┬ hash.js@1.1.7
│ │ │ ├── inherits@2.0.4 deduped
│ │ │ └── minimalistic-assert@1.0.1 deduped
│ │ ├─┬ hmac-drbg@1.0.1
│ │ │ ├── hash.js@1.1.7 deduped
│ │ │ ├── minimalistic-assert@1.0.1 deduped
│ │ │ └── minimalistic-crypto-utils@1.0.1 deduped
│ │ ├── inherits@2.0.4 deduped
│ │ ├── minimalistic-assert@1.0.1
│ │ └── minimalistic-crypto-utils@1.0.1
│ ├─┬ ethereum-cryptography@0.1.3
│ │ ├─┬ @types/pbkdf2@3.1.0
│ │ │ └── @types/node@18.11.17 deduped
│ │ ├─┬ @types/secp256k1@4.0.3
│ │ │ └── @types/node@18.11.17 deduped
│ │ ├── blakejs@1.2.1
│ │ ├─┬ browserify-aes@1.2.0
│ │ │ ├── buffer-xor@1.0.3
│ │ │ ├── cipher-base@1.0.4 deduped
│ │ │ ├── create-hash@1.2.0 deduped
│ │ │ ├─┬ evp_bytestokey@1.0.3
│ │ │ │ ├── md5.js@1.3.5 deduped
│ │ │ │ └── safe-buffer@5.2.1 deduped
│ │ │ ├── inherits@2.0.4 deduped
│ │ │ └── safe-buffer@5.2.1 deduped
│ │ ├─┬ bs58check@2.1.2
│ │ │ ├─┬ bs58@4.0.1
│ │ │ │ └─┬ base-x@3.0.9
│ │ │ │   └── safe-buffer@5.2.1 deduped
│ │ │ ├── create-hash@1.2.0 deduped
│ │ │ └── safe-buffer@5.2.1 deduped
│ │ ├── create-hash@1.2.0 deduped
│ │ ├─┬ create-hmac@1.1.7
│ │ │ ├── cipher-base@1.0.4 deduped
│ │ │ ├── create-hash@1.2.0 deduped
│ │ │ ├── inherits@2.0.4 deduped
│ │ │ ├── ripemd160@2.0.2 deduped
│ │ │ ├── safe-buffer@5.2.1 deduped
│ │ │ └── sha.js@2.4.11 deduped
│ │ ├── hash.js@1.1.7 deduped
│ │ ├─┬ keccak@3.0.2
│ │ │ ├── node-addon-api@2.0.2
│ │ │ ├── node-gyp-build@4.5.0 deduped
│ │ │ └── readable-stream@3.6.0 deduped
│ │ ├─┬ pbkdf2@3.1.2
│ │ │ ├── create-hash@1.2.0 deduped
│ │ │ ├── create-hmac@1.1.7 deduped
│ │ │ ├── ripemd160@2.0.2 deduped
│ │ │ ├── safe-buffer@5.2.1 deduped
│ │ │ └── sha.js@2.4.11 deduped
│ │ ├─┬ randombytes@2.1.0
│ │ │ └── safe-buffer@5.2.1 deduped
│ │ ├── safe-buffer@5.2.1
│ │ ├── scrypt-js@3.0.1
│ │ ├─┬ secp256k1@4.0.3
│ │ │ ├── elliptic@6.5.4 deduped
│ │ │ ├── node-addon-api@2.0.2 deduped
│ │ │ └── node-gyp-build@4.5.0 deduped
│ │ └── setimmediate@1.0.5
│ ├─┬ ethjs-util@0.1.6
│ │ ├── is-hex-prefixed@1.0.0
│ │ └─┬ strip-hex-prefix@1.0.0
│ │   └── is-hex-prefixed@1.0.0 deduped
│ └── rlp@2.2.7 deduped
├─┬ level@4.0.0
│ ├─┬ level-packager@3.1.0
│ │ ├─┬ encoding-down@5.0.4
│ │ │ ├── abstract-leveldown@5.0.0 deduped
│ │ │ ├── inherits@2.0.4 deduped
│ │ │ ├─┬ level-codec@9.0.2
│ │ │ │ └─┬ buffer@5.7.1
│ │ │ │   ├── base64-js@1.5.1 deduped
│ │ │ │   └── ieee754@1.2.1 deduped
│ │ │ ├─┬ level-errors@2.0.1
│ │ │ │ └─┬ errno@0.1.8
│ │ │ │   └── prr@1.0.1
│ │ │ └── xtend@4.0.2 deduped
│ │ └─┬ levelup@3.1.1
│ │   ├─┬ deferred-leveldown@4.0.2
│ │   │ ├── abstract-leveldown@5.0.0 deduped
│ │   │ └── inherits@2.0.4 deduped
│ │   ├── level-errors@2.0.1 deduped
│ │   ├─┬ level-iterator-stream@3.0.1
│ │   │ ├── inherits@2.0.4 deduped
│ │   │ ├─┬ readable-stream@2.3.7
│ │   │ │ ├── core-util-is@1.0.3
│ │   │ │ ├── inherits@2.0.4 deduped
│ │   │ │ ├── isarray@1.0.0
│ │   │ │ ├── process-nextick-args@2.0.1
│ │   │ │ ├── safe-buffer@5.1.2
│ │   │ │ ├─┬ string_decoder@1.1.1
│ │   │ │ │ └── safe-buffer@5.1.2 deduped
│ │   │ │ └── util-deprecate@1.0.2 deduped
│ │   │ └── xtend@4.0.2 deduped
│ │   └── xtend@4.0.2 deduped
│ ├─┬ leveldown@4.0.2
│ │ ├─┬ abstract-leveldown@5.0.0
│ │ │ └── xtend@4.0.2 deduped
│ │ ├── bindings@1.3.1
│ │ ├── fast-future@1.0.2
│ │ ├── nan@2.12.1
│ │ └─┬ prebuild-install@5.2.5
│ │   ├── detect-libc@1.0.3
│ │   ├── expand-template@2.0.3
│ │   ├── github-from-package@0.0.0
│ │   ├── minimist@1.2.7
│ │   ├─┬ mkdirp@0.5.6
│ │   │ └── minimist@1.2.7 deduped
│ │   ├── napi-build-utils@1.0.2
│ │   ├─┬ node-abi@2.30.1
│ │   │ └── semver@5.7.1
│ │   ├── noop-logger@0.1.1
│ │   ├─┬ npmlog@4.1.2
│ │   │ ├─┬ are-we-there-yet@1.1.7
│ │   │ │ ├── delegates@1.0.0
│ │   │ │ └─┬ readable-stream@2.3.7
│ │   │ │   ├── core-util-is@1.0.3 deduped
│ │   │ │   ├── inherits@2.0.4 deduped
│ │   │ │   ├── isarray@1.0.0 deduped
│ │   │ │   ├── process-nextick-args@2.0.1 deduped
│ │   │ │   ├── safe-buffer@5.1.2
│ │   │ │   ├─┬ string_decoder@1.1.1
│ │   │ │   │ └── safe-buffer@5.1.2 deduped
│ │   │ │   └── util-deprecate@1.0.2 deduped
│ │   │ ├── console-control-strings@1.1.0
│ │   │ ├─┬ gauge@2.7.4
│ │   │ │ ├── aproba@1.2.0
│ │   │ │ ├── console-control-strings@1.1.0 deduped
│ │   │ │ ├── has-unicode@2.0.1
│ │   │ │ ├── object-assign@4.1.1
│ │   │ │ ├── signal-exit@3.0.7
│ │   │ │ ├─┬ string-width@1.0.2
│ │   │ │ │ ├── code-point-at@1.1.0
│ │   │ │ │ ├─┬ is-fullwidth-code-point@1.0.0
│ │   │ │ │ │ └── number-is-nan@1.0.1
│ │   │ │ │ └── strip-ansi@3.0.1 deduped
│ │   │ │ ├─┬ strip-ansi@3.0.1
│ │   │ │ │ └── ansi-regex@2.1.1
│ │   │ │ └─┬ wide-align@1.1.5
│ │   │ │   └── string-width@1.0.2 deduped
│ │   │ └── set-blocking@2.0.0
│ │   ├── os-homedir@1.0.2
│ │   ├─┬ pump@2.0.1
│ │   │ ├─┬ end-of-stream@1.4.4
│ │   │ │ └── once@1.4.0 deduped
│ │   │ └─┬ once@1.4.0
│ │   │   └── wrappy@1.0.2
│ │   ├─┬ rc@1.2.8
│ │   │ ├── deep-extend@0.6.0
│ │   │ ├── ini@1.3.8
│ │   │ ├── minimist@1.2.7 deduped
│ │   │ └── strip-json-comments@2.0.1
│ │   ├─┬ simple-get@2.8.2
│ │   │ ├─┬ decompress-response@3.3.0
│ │   │ │ └── mimic-response@1.0.1
│ │   │ ├── once@1.4.0 deduped
│ │   │ └── simple-concat@1.0.1
│ │   ├─┬ tar-fs@1.16.3
│ │   │ ├── chownr@1.1.4
│ │   │ ├── mkdirp@0.5.6 deduped
│ │   │ ├─┬ pump@1.0.3
│ │   │ │ ├── end-of-stream@1.4.4 deduped
│ │   │ │ └── once@1.4.0 deduped
│ │   │ └─┬ tar-stream@1.6.2
│ │   │   ├─┬ bl@1.2.3
│ │   │   │ ├─┬ readable-stream@2.3.7
│ │   │   │ │ ├── core-util-is@1.0.3 deduped
│ │   │   │ │ ├── inherits@2.0.4 deduped
│ │   │   │ │ ├── isarray@1.0.0 deduped
│ │   │   │ │ ├── process-nextick-args@2.0.1 deduped
│ │   │   │ │ ├── safe-buffer@5.1.2
│ │   │   │ │ ├─┬ string_decoder@1.1.1
│ │   │   │ │ │ └── safe-buffer@5.1.2
│ │   │   │ │ └── util-deprecate@1.0.2 deduped
│ │   │   │ └── safe-buffer@5.2.1 deduped
│ │   │   ├─┬ buffer-alloc@1.2.0
│ │   │   │ ├── buffer-alloc-unsafe@1.1.0
│ │   │   │ └── buffer-fill@1.0.0
│ │   │   ├── end-of-stream@1.4.4 deduped
│ │   │   ├── fs-constants@1.0.0
│ │   │   ├─┬ readable-stream@2.3.7
│ │   │   │ ├── core-util-is@1.0.3 deduped
│ │   │   │ ├── inherits@2.0.4 deduped
│ │   │   │ ├── isarray@1.0.0 deduped
│ │   │   │ ├── process-nextick-args@2.0.1 deduped
│ │   │   │ ├── safe-buffer@5.1.2
│ │   │   │ ├─┬ string_decoder@1.1.1
│ │   │   │ │ └── safe-buffer@5.1.2 deduped
│ │   │   │ └── util-deprecate@1.0.2 deduped
│ │   │   ├── to-buffer@1.1.1
│ │   │   └── xtend@4.0.2 deduped
│ │   ├─┬ tunnel-agent@0.6.0
│ │   │ └── safe-buffer@5.2.1 deduped
│ │   └── which-pm-runs@1.1.0
│ └── opencollective-postinstall@2.0.3
├─┬ leveldown@6.1.1
│ ├─┬ abstract-leveldown@7.2.0
│ │ ├─┬ buffer@6.0.3
│ │ │ ├── base64-js@1.5.1
│ │ │ └── ieee754@1.2.1
│ │ ├── catering@2.1.1 deduped
│ │ ├── is-buffer@2.0.5
│ │ ├─┬ level-concat-iterator@3.1.0
│ │ │ └── catering@2.1.1 deduped
│ │ ├── level-supports@2.1.0 deduped
│ │ └── queue-microtask@1.2.3 deduped
│ ├── napi-macros@2.0.0
│ └── node-gyp-build@4.5.0
├─┬ levelup@5.1.1
│ ├── catering@2.1.1
│ ├─┬ deferred-leveldown@7.0.0
│ │ ├─┬ abstract-leveldown@7.2.0
│ │ │ ├─┬ buffer@6.0.3
│ │ │ │ ├── base64-js@1.5.1 deduped
│ │ │ │ └── ieee754@1.2.1 deduped
│ │ │ ├── catering@2.1.1 deduped
│ │ │ ├── is-buffer@2.0.5 deduped
│ │ │ ├── level-concat-iterator@3.1.0 deduped
│ │ │ ├── level-supports@2.1.0 deduped
│ │ │ └── queue-microtask@1.2.3 deduped
│ │ └── inherits@2.0.4 deduped
│ ├── level-errors@3.0.1
│ ├─┬ level-iterator-stream@5.0.0
│ │ ├── inherits@2.0.4 deduped
│ │ └── readable-stream@3.6.0 deduped
│ ├── level-supports@2.1.0
│ └── queue-microtask@1.2.3
├─┬ merkle-patricia-tree@4.2.4
│ ├─┬ @types/levelup@4.3.3
│ │ ├── @types/abstract-leveldown@7.2.0
│ │ ├── @types/level-errors@3.0.0
│ │ └── @types/node@18.11.17 deduped
│ ├─┬ ethereumjs-util@7.1.5
│ │ ├─┬ @types/bn.js@5.1.1
│ │ │ └── @types/node@18.11.17 deduped
│ │ ├── bn.js@5.2.1
│ │ ├── create-hash@1.2.0 deduped
│ │ ├── ethereum-cryptography@0.1.3 deduped
│ │ └── rlp@2.2.7 deduped
│ ├─┬ level-mem@5.0.1
│ │ ├─┬ level-packager@5.1.1
│ │ │ ├─┬ encoding-down@6.3.0
│ │ │ │ ├─┬ abstract-leveldown@6.3.0
│ │ │ │ │ ├── buffer@5.7.1 deduped
│ │ │ │ │ ├── immediate@3.3.0
│ │ │ │ │ ├── level-concat-iterator@2.0.1
│ │ │ │ │ ├── level-supports@1.0.1 deduped
│ │ │ │ │ └── xtend@4.0.2 deduped
│ │ │ │ ├── inherits@2.0.4 deduped
│ │ │ │ ├── level-codec@9.0.2 deduped
│ │ │ │ └── level-errors@2.0.1 deduped
│ │ │ └─┬ levelup@4.4.0
│ │ │   ├─┬ deferred-leveldown@5.3.0
│ │ │   │ ├─┬ abstract-leveldown@6.2.3
│ │ │   │ │ ├── buffer@5.7.1 deduped
│ │ │   │ │ ├── immediate@3.3.0 deduped
│ │ │   │ │ ├── level-concat-iterator@2.0.1 deduped
│ │ │   │ │ ├── level-supports@1.0.1 deduped
│ │ │   │ │ └── xtend@4.0.2 deduped
│ │ │   │ └── inherits@2.0.4 deduped
│ │ │   ├── level-errors@2.0.1 deduped
│ │ │   ├─┬ level-iterator-stream@4.0.2
│ │ │   │ ├── inherits@2.0.4 deduped
│ │ │   │ ├── readable-stream@3.6.0 deduped
│ │ │   │ └── xtend@4.0.2 deduped
│ │ │   ├─┬ level-supports@1.0.1
│ │ │   │ └── xtend@4.0.2 deduped
│ │ │   └── xtend@4.0.2 deduped
│ │ └─┬ memdown@5.1.0
│ │   ├─┬ abstract-leveldown@6.2.3
│ │   │ ├── buffer@5.7.1 deduped
│ │   │ ├── immediate@3.2.3 deduped
│ │   │ ├── level-concat-iterator@2.0.1
│ │   │ ├─┬ level-supports@1.0.1
│ │   │ │ └── xtend@4.0.2 deduped
│ │   │ └── xtend@4.0.2 deduped
│ │   ├── functional-red-black-tree@1.0.1
│ │   ├── immediate@3.2.3
│ │   ├── inherits@2.0.4 deduped
│ │   ├── ltgt@2.2.1
│ │   └── safe-buffer@5.2.1 deduped
│ ├─┬ level-ws@2.0.0
│ │ ├── inherits@2.0.4 deduped
│ │ ├── readable-stream@3.6.0 deduped
│ │ └── xtend@4.0.2
│ ├─┬ readable-stream@3.6.0
│ │ ├── inherits@2.0.4 deduped
│ │ ├─┬ string_decoder@1.3.0
│ │ │ └── safe-buffer@5.2.1 deduped
│ │ └── util-deprecate@1.0.2
│ └── semaphore-async-await@1.5.1
└─┬ rlp@2.2.7
  └── bn.js@5.2.1

Is there anything that I am doing wrong? Please help me get this working. Here are the versions of Node and NPM that I am using: Node version: v10.24.1 NPM version: 6.14.12

I had to downgrade my version of my Node and NPM as some of the packages had trouble getting installed

0

Your Answer

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