Skip to main content

Module: relay

Interfaces

Functions

getBitcoinHeaders

getBitcoinHeaders(electrsClient, startHeight, numBlocks): Promise<string>

Retrieves Bitcoin block headers using an Electrs client.

Parameters

NameTypeDescription
electrsClientElectrsClientThe ElectrsClient instance used to interact with the Esplora API.
startHeightnumberThe starting block height from which to fetch headers.
numBlocksnumberThe 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:152


getBitcoinTxInfo

getBitcoinTxInfo(electrsClient, txId, forWitness?): Promise<BitcoinTxInfo>

Retrieves information about a Bitcoin transaction, such as version, input vector, output vector, and locktime.

Parameters

NameTypeDescription
electrsClientElectrsClientAn ElectrsClient instance for interacting with the Electrum server.
txIdstringThe ID of the Bitcoin transaction.
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

NameTypeDescription
electrsClientElectrsClientAn ElectrsClient instance for interacting with the Electrum server.
txIdstringThe ID of the Bitcoin transaction.
txProofDifficultyFactornumberThe 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:113