Module: relay
Interfaces
Functions
getBitcoinHeaders
▸ getBitcoinHeaders(electrsClient
, startHeight
, numBlocks
): Promise
<string
>
Retrieves Bitcoin block headers using an Electrs client.
Parameters
Name | Type | Description |
---|---|---|
electrsClient | ElectrsClient | The ElectrsClient instance used to interact with the Esplora API. |
startHeight | number | The starting block height from which to fetch headers. |
numBlocks | number | The number of consecutive block headers to retrieve. |
Returns
Promise
<string
>
A Promise that resolves to a concatenated string of Bitcoin block headers.
Throws
If there is an issue with fetching block headers.
Example
const BITCOIN_NETWORK = "regtest";
const electrsClient = new DefaultElectrsClient(BITCOIN_NETWORK);
const startHeight = 0;
const numBlocks = 10;
getBitcoinHeaders(electrsClient, startHeight, numBlocks)
.then(headers => {
console.log(headers); // Concatenated block headers as a string.
})
.catch(error => {
console.error(`Error: ${error.message}`);
});
Defined in
relay.ts:153
getBitcoinTxInfo
▸ getBitcoinTxInfo(electrsClient
, txId
, forWitness?
, forWitness?
): Promise
<BitcoinTxInfo
>
Retrieves information about a Bitcoin transaction, such as version, input vector, output vector, and locktime.
Parameters
Name | Type | Description |
---|---|---|
electrsClient | ElectrsClient | An ElectrsClient instance for interacting with the Electrum server. |
txId | string | The ID of the Bitcoin transaction. |
forWitness? | boolean | - |
forWitness? | boolean | - |
Returns
Promise
<BitcoinTxInfo
>
A promise that resolves to a BitcoinTxInfo object.
Example
const BITCOIN_NETWORK = "regtest";
const electrsClient = new DefaultElectrsClient(BITCOIN_NETWORK);
const txId = "279121610d9575d132c95312c032116d6b8a58a3a31f69adf9736b493de96a16"; //enter the transaction id here
const info = await getBitcoinTxInfo(electrsClient, txId);
Defined in
relay.ts:56
getBitcoinTxProof
▸ getBitcoinTxProof(electrsClient
, txId
, txProofDifficultyFactor
): Promise
<BitcoinTxProof
>
Retrieves a proof for a Bitcoin transaction, including the merkle proof, transaction index in the block, and Bitcoin headers.
Parameters
Name | Type | Description |
---|---|---|
electrsClient | ElectrsClient | An ElectrsClient instance for interacting with the Electrum server. |
txId | string | The ID of the Bitcoin transaction. |
txProofDifficultyFactor | number | The number of block headers to retrieve for proof verification. |
Returns
Promise
<BitcoinTxProof
>
Example
const BITCOIN_NETWORK = "regtest";
const electrsClient = new DefaultElectrsClient(BITCOIN_NETWORK);
const txId = "279121610d9575d132c95312c032116d6b8a58a3a31f69adf9736b493de96a16";//enter the transaction id here
const txProofDifficultyFactor = "1";//enter the difficulty factor
const info = await getBitcoinTxProof(electrsClient, txId, txProofDifficultyFactor);
Defined in
relay.ts:114