Last active
February 13, 2022 18:48
-
-
Save nodech/add7ed928e3dc2948e3673af78cde4ff to your computer and use it in GitHub Desktop.
BCOIN - Example: Get Entry, Block, Tx from chain
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
'use strict'; | |
const bcoin = require('bcoin'); | |
const Chain = bcoin.chain; | |
const Logger = bcoin.logger; | |
const util = bcoin.util; | |
let logger = new Logger({ | |
level: 'debug', | |
}); | |
const chain = new Chain({ | |
logger: logger, | |
network: 'testnet', | |
db: 'leveldb', | |
prefix: '/path/to/.bcoin/testnet', | |
indexTX: true, | |
indexAddress: true | |
}); | |
let main = (async () => { | |
await logger.open(); | |
await chain.open(); | |
console.log('Current height:', chain.height); | |
const entry = await chain.getEntry(50000); | |
console.log('Block at 50k:', entry); | |
const txhash = '7f5990b008a2d0fc006d13b15e25d05ff30fadab656d49a5c6afea0e0d0b458c'; | |
let txmeta = await chain.db.getMeta(util.revHex(txhash)); | |
console.log(`Tx with hash ${txhash}:`, txmeta); | |
const blockhash = '00000000077eacdd2c803a742195ba430a6d9545e43128ba55ec3c80beea6c0c'; | |
let block = await chain.db.getBlock(util.revHex(blockhash)); | |
console.log(`Block with hash ${blockhash}:`, block); | |
}); | |
main().then(() => { | |
console.log('Finished'); | |
}).catch((err) => { | |
console.error('err', err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment