Created
February 23, 2021 18:34
-
-
Save AdvaithD/d97c0d0da91bb8badad1f1724da24655 to your computer and use it in GitHub Desktop.
state-dissector.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Mozilla Public License 2.0 | |
//As per https://github.com/ethereumjs/ethereumjs-vm/blob/master/LICENSE | |
//Requires the following packages to run as nodejs file https://gist.github.com/tpmccallum/0e58fc4ba9061a2e634b7a877e60143a | |
// NOTE: Ported from a medium.com article (https://medium.com/cybermiles/diving-into-ethereums-world-state-c893102030ed) | |
//Getting the requirements | |
var Trie = require('merkle-patricia-tree/secure'); | |
var levelup = require('levelup'); | |
var leveldown = require('leveldown'); | |
var utils = require('ethereumjs-util'); | |
var BN = utils.BN; | |
var Account = require('ethereumjs-account'); | |
//Connecting to the leveldb database | |
var db = levelup(leveldown('/home/timothymccallum/gethDataDir/geth/chaindata')); | |
//Adding the "stateRoot" value from the block so that we can inspect the state root at that block height. | |
var root = '0x9369577baeb7c4e971ebe76f5d5daddba44c2aa42193248245cf686d20a73028'; | |
//Creating a trie object of the merkle-patricia-tree library | |
var trie = new Trie(db, root); | |
var address = '0xccc6b46fa5606826ce8c18fece6f519064e6130b'; | |
trie.get(address, function (err, raw) { | |
if (err) return cb(err) | |
//Using ethereumjs-account to create an instance of an account | |
var account = new Account(raw) | |
console.log('Account Address: ' + address); | |
//Using ethereumjs-util to decode and present the account balance | |
console.log('Balance: ' + (new BN(account.balance)).toString()); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment