Skip to content

Latest commit

 

History

History
309 lines (178 loc) · 8.32 KB

BitcoinClient.md

File metadata and controls

309 lines (178 loc) · 8.32 KB

Interface: BitcoinClient

Represents a Bitcoin client.

Implemented by

Table of contents

Methods

Methods

broadcast

broadcast(transaction): Promise<void>

Broadcasts the given transaction over the network.

Parameters

Name Type Description
transaction BitcoinRawTx Transaction to broadcast.

Returns

Promise<void>

Defined in

src/lib/bitcoin/client.ts:103


findAllUnspentTransactionOutputs

findAllUnspentTransactionOutputs(address): Promise<BitcoinUtxo[]>

Finds all unspent transaction outputs (UTXOs) for given Bitcoin address. The list includes UTXOs from both the blockchain and the mempool, sorted by age with the newest ones first. Mempool UTXOs are listed at the beginning.

Parameters

Name Type Description
address string Bitcoin address UTXOs should be determined for.

Returns

Promise<BitcoinUtxo[]>

List of UTXOs.

Defined in

src/lib/bitcoin/client.ts:23


getCoinbaseTxHash

getCoinbaseTxHash(blockHeight): Promise<BitcoinTxHash>

Gets the hash of the coinbase transaction for the given block height.

Parameters

Name Type Description
blockHeight number Height of the block.

Returns

Promise<BitcoinTxHash>

Defined in

src/lib/bitcoin/client.ts:109


getHeadersChain

getHeadersChain(blockHeight, chainLength): Promise<Hex>

Gets concatenated chunk of block headers built on a starting block.

Parameters

Name Type Description
blockHeight number Starting block height.
chainLength number Number of subsequent blocks built on the starting block.

Returns

Promise<Hex>

Concatenation of block headers in a hexadecimal format.

Defined in

src/lib/bitcoin/client.ts:86


getNetwork

getNetwork(): Promise<BitcoinNetwork>

Gets the network supported by the server the client connected to.

Returns

Promise<BitcoinNetwork>

Bitcoin network.

Defined in

src/lib/bitcoin/client.ts:14


getRawTransaction

getRawTransaction(transactionHash): Promise<BitcoinRawTx>

Gets the raw transaction data for given transaction hash.

Parameters

Name Type Description
transactionHash BitcoinTxHash Hash of the transaction.

Returns

Promise<BitcoinRawTx>

Raw transaction.

Defined in

src/lib/bitcoin/client.ts:49


getTransaction

getTransaction(transactionHash): Promise<BitcoinTx>

Gets the full transaction object for given transaction hash.

Parameters

Name Type Description
transactionHash BitcoinTxHash Hash of the transaction.

Returns

Promise<BitcoinTx>

Transaction object.

Defined in

src/lib/bitcoin/client.ts:42


getTransactionConfirmations

getTransactionConfirmations(transactionHash): Promise<number>

Gets the number of confirmations that a given transaction has accumulated so far.

Parameters

Name Type Description
transactionHash BitcoinTxHash Hash of the transaction.

Returns

Promise<number>

The number of confirmations.

Defined in

src/lib/bitcoin/client.ts:57


getTransactionHistory

getTransactionHistory(address, limit?): Promise<BitcoinTx[]>

Gets the history of confirmed transactions for given Bitcoin address. Returned transactions are sorted from oldest to newest. The returned result does not contain unconfirmed transactions living in the mempool at the moment of request.

Parameters

Name Type Description
address string Bitcoin address transaction history should be determined for.
limit? number Optional parameter that can limit the resulting list to a specific number of last transaction. For example, limit = 5 will return only the last 5 transactions for the given address.

Returns

Promise<BitcoinTx[]>

Defined in

src/lib/bitcoin/client.ts:35


getTransactionMerkle

getTransactionMerkle(transactionHash, blockHeight): Promise<BitcoinTxMerkleBranch>

Get Merkle branch for a given transaction.

Parameters

Name Type Description
transactionHash BitcoinTxHash Hash of a transaction.
blockHeight number Height of the block where transaction was confirmed.

Returns

Promise<BitcoinTxMerkleBranch>

Merkle branch.

Defined in

src/lib/bitcoin/client.ts:94


getTxHashesForPublicKeyHash

getTxHashesForPublicKeyHash(publicKeyHash): Promise<BitcoinTxHash[]>

Gets hashes of confirmed transactions that pay the given public key hash using either a P2PKH or P2WPKH script. The returned transactions hashes are ordered by block height in the ascending order, i.e. the latest transaction hash is at the end of the list. The returned list does not contain unconfirmed transactions hashes living in the mempool at the moment of request.

Parameters

Name Type Description
publicKeyHash Hex Hash of the public key for which to find corresponding transaction hashes.

Returns

Promise<BitcoinTxHash[]>

Array of confirmed transaction hashes related to the provided public key hash.

Defined in

src/lib/bitcoin/client.ts:71


latestBlockHeight

latestBlockHeight(): Promise<number>

Gets height of the latest mined block.

Returns

Promise<number>

Height of the last mined block.

Defined in

src/lib/bitcoin/client.ts:77