-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexample.js
More file actions
29 lines (22 loc) · 887 Bytes
/
example.js
File metadata and controls
29 lines (22 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var Trie = require('merkle-patricia-tree');
var rlp = require('rlp');
var levelup = require('levelup');
var leveldown = require('leveldown');
var db = levelup(leveldown('/your_home_dir/Library/Ethereum/rinkeby/geth/chaindata'));
// the block state root, rinkeby, block number 1775804
// the block state root can be obtained by invoking web3.eth.getBlock(<blockNumber>) in `stateRoot` field
var root = '0xe4a6ff741ec2e0d0cd274a745756028df27312161bdb4557b6da434349f716a9';
var trie = new Trie(db, root);
trie.checkRoot(root, function (err, val) {
console.log('Root exists:', val);
});
var stream = trie.createReadStream();
stream.on('data', function (data) {
console.log('key:', data.key.toString('hex'));
// values are rlp encoded
var decodedVal = rlp.decode(data.value);
console.log(decodedVal);
});
stream.on('end', function (val) {
console.log('done reading!');
});