JavaScript access to the blockchain
blockchain service
This page describes the functions made available in the blockchain service.
FloweeJS ships with several services, each of which have specialized functions
that make it easy to access the information. The blockchain service contains functions
that can be used to investigate the historical blocks and naturally the methods
like getBlockCount
.
Where the name Flowee
is used, this is the variable which results from a call similar to:
const FloweeServices = require('floweejs');
var Flowee = new FloweeServices();`
Functions
-
Flowee.getBlockCount()
Returns a number indicating the number of blocks, or blockHeight on the chain. -
Flowee.getBlock(blockId)
, or alternativelyFlowee.getBlock(blockHeight)
Takes an argument of either blockHeight or blockHash.
Returns an object with the blockHeight, blockId andoffset in block
to get the transactions using a function like getRawTransaction. Example output:{ blockId: '0000000068e1ce37e6d50d1e960255c00047d9c808146b77df2dc186ab1bc92a', blockHash: Uint8Array(32) [ /* binary blockId */ ], blockHeight: 120, transactions: [ { offset: 81 } ] }
-
Flowee.getBlockChainInfo()
Returns an object with blockchain Information. Example output:{ difficulty: 285033601765.4279, medianTime: 1613387505, chainWork: '0000000000000000000000000000000000000000015ea1128340112f4b3a0bca', chain: 'main', blocks: 674976, headers: 674976, bestBlockHash: Uint8Array(32) [ 70, 147, 96, 213, 103, 8, 141, 218, 37, 51, 175, 188, 120, 245, 198, 179, 57, 86, 145, 183, 105, 205, 169, 2, 0, 0, 0, 0, 0, 0, 0, 0 ], bestBlockId: '000000000000000002a9cd69b7915639b3c6f578bcaf3325da8d0867d5609346' }
-
Flowee.getBestBlockHash()
Returns an object with theblockId
(string) /blockHash
(Uint8Array). -
Flowee.getRawTransaction(blockHeight, offsetInBlock)
Returns a Uint8Array of a transaction. -
Flowee.getRawTransaction(TXID)
Returns a Uint8Array of a transaction. -
Flowee.getBlockHeader(blockId)
or alternativelyFlowee.getBlockHeader(blockHeight)
Returns an object with the header data. Example output:{ blockId: '00000000ce2780c9640fde662ffbb07a10c9e96a226718875225a9a0fe6ac337', blockHash: Uint8Array(32) [ /* binary data */ ], confirmations: 674869, blockHeight: 112, version: 1, merkleRoot: Uint8Array(32) [ /* binary data */ ], merkleRootHex: '3438117001eedca26a917571b11e684ab3a4b1ca172fdc0ccaa3cc439b211ead', time: 1231670137, medianTime: 1231666285, nonce: 2067062792, bits: 486604799, difficulty: 1, prevBlockHash: '000000004d6a6dd8b882deec7b54421949dddd2c166bd51ee7f62a52091a6c35', nextBlockHash: '00000000019176838de40606d70738084f2fbc48a50548eeeac3ceb857677c6d' }
-
Flowee.getTransaction(blockHeight, offsetInBlock, filters)
or -
Flowee.getTransaction(txid, filters)
Returns an object describing the transaction and many of its properties. Which parts of the transaction that are fetched are described in the filters enum. Example output:raw: Uint8Array(226) [ bytes ], txid: Uint8Array(20) [ bytes ], offsetInBlock: 260, inputs: [ { prevTxid: [Uint8Array], outIndex: 1, script: [Uint8Array] } ], outputs: [ { value: 1000, script: [Uint8Array], p2pkhAddress: [Uint8Array], scriptHashed: [Uint8Array] }, { value: 85565, script: [Uint8Array], p2pkhAddress: [Uint8Array], scriptHashed: [Uint8Array] } ] }