Skip to main content

Interface: ElectrsClient

electrs.ElectrsClient

Implemented by

Methods

broadcastTx

broadcastTx(txHex): Promise\<string>

Broadcast a raw transaction to the network.

Parameters

NameTypeDescription
txHexstringThe hex encoded transaction.

Returns

Promise\<string>

A promise that resolves to the txid.

Defined in

electrs.ts:150


getAddressUtxos

getAddressUtxos(address): Promise\<UTXO[]>

Get the Unspent Transaction Outputs (UTXOs) for an address.

Parameters

NameTypeDescription
addressstringThe Bitcoin address to check.

Returns

Promise\<UTXO[]>

A promise that resolves to an array of UTXOs.

Defined in

electrs.ts:142


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}`);
});

Defined in

electrs.ts:60


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}`);
});

Defined in

electrs.ts:82


getFeeEstimate

getFeeEstimate(confirmationTarget): Promise\<number>

Get the fee estimate (in sat/vB) for the given confirmation target.

Parameters

NameTypeDescription
confirmationTargetnumberThe number of blocks to be included in.

Returns

Promise\<number>

A promise that resolves to the fee rate.

Defined in

electrs.ts:134


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}`);
});

Defined in

electrs.ts:126


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}`);
});

Defined in

electrs.ts:104