Skip to main content

Class: DefaultElectrsClient

electrs.DefaultElectrsClient

Implements

Constructors

constructor

new DefaultElectrsClient(networkOrUrl?)

Parameters

NameTypeDefault value
networkOrUrlstring"mainnet"

Defined in

electrs.ts:111

Properties

basePath

Private basePath: string

Defined in

electrs.ts:109

Methods

getBlockHash

getBlockHash(height): Promise<string>

Get the block hash of the Bitcoin block at a specific height.

This function retrieves the block hash for the Bitcoin block at the given height.

Parameters

NameTypeDescription
heightnumberThe height of the Bitcoin block.

Returns

Promise<string>

A promise that resolves to the block hash of the Bitcoin block.

Example

const BITCOIN_NETWORK = "regtest";
const electrsClient = new DefaultElectrsClient(BITCOIN_NETWORK);
const blockHeight = 123456;
electrsClient.getBlockHash(blockHeight)
.then((blockHash) => {
console.log(`Block hash at height ${blockHeight}: ${blockHash}`);
})
.catch((error) => {
console.error(`Error: ${error}`);
});

Implementation of

ElectrsClient.getBlockHash

Defined in

electrs.ts:127


getBlockHeader

getBlockHeader(hash): Promise<string>

Get the raw block header, represented as a hex string, for a Bitcoin block with a given hash.

Parameters

NameTypeDescription
hashstringThe hash of the Bitcoin block.

Returns

Promise<string>

A promise that resolves to the raw block header as a hex string.

Example

const BITCOIN_NETWORK = "regtest";
const electrsClient = new DefaultElectrsClient(BITCOIN_NETWORK);
const blockHash = 'your_block_hash_here';
electrsClient.getBlockHeader(blockHash)
.then((blockHeader) => {
console.log(`Raw block header for block with hash ${blockHash}: ${blockHeader}`);
})
.catch((error) => {
console.error(`Error: ${error}`);
});

Implementation of

ElectrsClient.getBlockHeader

Defined in

electrs.ts:131


getJson

getJson<T>(url): Promise<T>

Type parameters

Name
T

Parameters

NameType
urlstring

Returns

Promise<T>

Defined in

electrs.ts:152


getMerkleProof

getMerkleProof(txId): Promise<MerkleProof>

Get the encoded merkle inclusion proof for a Bitcoin transaction with a given ID (txId).

Parameters

NameTypeDescription
txIdstringThe ID of a Bitcoin transaction.

Returns

Promise<MerkleProof>

A promise that resolves to the encoded merkle inclusion proof.

Example

const BITCOIN_NETWORK = "regtest";
const electrsClient = new DefaultElectrsClient(BITCOIN_NETWORK);
const transactionId = 'your_transaction_id_here';
electrsClient.getMerkleProof(transactionId)
.then((merkleProof) => {
console.log(`Merkle inclusion proof for transaction with ID ${transactionId}: ${merkleProof}`);
})
.catch((error) => {
console.error(`Error: ${error}`);
});

Implementation of

ElectrsClient.getMerkleProof

Defined in

electrs.ts:139


getText

getText(url): Promise<string>

Parameters

NameType
urlstring

Returns

Promise<string>

Defined in

electrs.ts:160


getTransactionHex

getTransactionHex(txId): Promise<string>

Get the transaction data, represented as a hex string, for a Bitcoin transaction with a given ID (txId).

Parameters

NameTypeDescription
txIdstringThe ID of a Bitcoin transaction.

Returns

Promise<string>

A promise that resolves to the transaction data as a hex string.

Example

const BITCOIN_NETWORK = "regtest";
const electrsClient = new DefaultElectrsClient(BITCOIN_NETWORK);
const transactionId = 'your_transaction_id_here';
electrsClient.getTransactionHex(transactionId)
.then((transactionHex) => {
console.log(`Transaction hex for transaction with ID ${transactionId}: ${transactionHex}`);
})
.catch((error) => {
console.error(`Error: ${error}`);
});

Implementation of

ElectrsClient.getTransactionHex

Defined in

electrs.ts:135