Class: DefaultElectrsClient
electrs.DefaultElectrsClient
Implements
Constructors
constructor
• new DefaultElectrsClient(networkOrUrl?
)
Parameters
Name | Type | Default value |
---|---|---|
networkOrUrl | string | "mainnet" |
Defined in
electrs.ts:107
Properties
basePath
• Private
basePath: string
Defined in
electrs.ts:105
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
Name | Type | Description |
---|---|---|
height | number | The height of the Bitcoin block. |
Returns
Promise
<string
>
A promise that resolves to the block hash of the Bitcoin block.
Example
const electrsClient = new DefaultElectrsClient(BITCOIN_NETWORK);
const blockHeight = 123456;
electrs.getBlockHash(blockHeight)
.then((blockHash) => {
console.log(`Block hash at height ${blockHeight}: ${blockHash}`);
})
.catch((error) => {
console.error(`Error: ${error}`);
});
Implementation of
Defined in
electrs.ts:123
getBlockHeader
▸ getBlockHeader(hash
): Promise
<string
>
Get the raw block header, represented as a hex string, for a Bitcoin block with a given hash.
Parameters
Name | Type | Description |
---|---|---|
hash | string | The hash of the Bitcoin block. |
Returns
Promise
<string
>
A promise that resolves to the raw block header as a hex string.
Example
const electrsClient = new DefaultElectrsClient(BITCOIN_NETWORK);
const blockHash = 'your_block_hash_here';
electrs.getBlockHeader(blockHash)
.then((blockHeader) => {
console.log(`Raw block header for block with hash ${blockHash}: ${blockHeader}`);
})
.catch((error) => {
console.error(`Error: ${error}`);
});
Implementation of
Defined in
electrs.ts:127
getJson
▸ getJson<T
>(url
): Promise
<T
>
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
url | string |
Returns
Promise
<T
>
Defined in
electrs.ts:148
getMerkleProof
▸ getMerkleProof(txId
): Promise
<MerkleProof
>
Get the encoded merkle inclusion proof for a Bitcoin transaction with a given ID (txId).
Parameters
Name | Type | Description |
---|---|---|
txId | string | The ID of a Bitcoin transaction. |
Returns
Promise
<MerkleProof
>
A promise that resolves to the encoded merkle inclusion proof.
Example
const electrsClient = new DefaultElectrsClient(BITCOIN_NETWORK);
const transactionId = 'your_transaction_id_here';
electrs.getMerkleProof(transactionId)
.then((merkleProof) => {
console.log(`Merkle inclusion proof for transaction with ID ${transactionId}: ${merkleProof}`);
})
.catch((error) => {
console.error(`Error: ${error}`);
});
Implementation of
Defined in
electrs.ts:135
getText
▸ getText(url
): Promise
<string
>
Parameters
Name | Type |
---|---|
url | string |
Returns
Promise
<string
>
Defined in
electrs.ts:156
getTransactionHex
▸ getTransactionHex(txId
): Promise
<string
>
Get the transaction data, represented as a hex string, for a Bitcoin transaction with a given ID (txId).
Parameters
Name | Type | Description |
---|---|---|
txId | string | The ID of a Bitcoin transaction. |
Returns
Promise
<string
>
A promise that resolves to the transaction data as a hex string.
Example
const electrsClient = new DefaultElectrsClient(BITCOIN_NETWORK);
const transactionId = 'your_transaction_id_here';
electrs.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:131