interbtc-api

@interlay/interbtc-api / Exports / DefaultElectrsAPI

Class: DefaultElectrsAPI

Bitcoin Core API

Implements

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new DefaultElectrsAPI(network?): DefaultElectrsAPI

Parameters

Name Type Default value
network string "mainnet"

Returns

DefaultElectrsAPI

Defined in

src/external/electrs.ts:167

Properties

addressApi

Private addressApi: AddressApi

Defined in

src/external/electrs.ts:165


blockApi

Private blockApi: BlockApi

Defined in

src/external/electrs.ts:162


scripthashApi

Private scripthashApi: ScripthashApi

Defined in

src/external/electrs.ts:164


txApi

Private txApi: TxApi

Defined in

src/external/electrs.ts:163

Methods

broadcastRawTransaction

broadcastRawTransaction(hex): Promise<AxiosResponse<string>>

Broadcasts a transaction to the Bitcoin network configured in the constructor

Parameters

Name Type Description
hex string A hex-encoded raw transaction to be broadcast to the Bitcoin blockchain

Returns

Promise<AxiosResponse<string>>

The txid of the transaction

Defined in

src/external/electrs.ts:390


getCoinbaseTxId

getCoinbaseTxId(userTxId): Promise<undefined | string>

Returns tx id of the coinbase tx of block in which userTxId was included.

Parameters

Name Type Description
userTxId string User tx ID which block’s txId will be returned.

Returns

Promise<undefined | string>

Tx ID of coinbase transaction or undefined if block was not found.

Implementation of

ElectrsAPI.getCoinbaseTxId

Defined in

src/external/electrs.ts:432


getData

getData<T>(response): Promise<T>

Parse an AxiosResponse Promise

Type parameters

Name
T

Parameters

Name Type Description
response Promise<AxiosResponse<T>> A generic AxiosResponse Promise

Returns

Promise<T>

The data in the response

Defined in

src/external/electrs.ts:456


getEarliestPaymentToRecipientAddressTxId

getEarliestPaymentToRecipientAddressTxId(recipientAddress, amount?): Promise<string>

Fetch the earliest/oldest bitcoin transaction ID based on the recipient address and amount. Throw an error if no such transaction is found.

Parameters

Name Type Description
recipientAddress string Match the receiving address of a transaction output
amount? BitcoinAmount Match the amount (in BTC) of a transaction output that contains said recipientAddress.

Returns

Promise<string>

A Bitcoin transaction ID

Remarks

Performs the lookup using an external service, Esplora

Deprecated

For most cases where this is used today, getLargestPaymentToRecipientAddressTxId is better suited.

Implementation of

ElectrsAPI.getEarliestPaymentToRecipientAddressTxId

Defined in

src/external/electrs.ts:252


getLargestPaymentToRecipientAddressTxId

getLargestPaymentToRecipientAddressTxId(recipientAddress): Promise<string>

Fetch the bitcoin transaction ID with the largest payment based on the recipient address. Throw an error if no transactions are found.

Parameters

Name Type Description
recipientAddress string Match the receiving address of a transaction output

Returns

Promise<string>

A Bitcoin transaction ID

Remarks

Performs the lookup using an external service, Esplora

Implementation of

ElectrsAPI.getLargestPaymentToRecipientAddressTxId

Defined in

src/external/electrs.ts:222


getLatestBlock

getLatestBlock(): Promise<string>

Returns

Promise<string>

The block hash of the latest Bitcoin block

Implementation of

ElectrsAPI.getLatestBlock

Defined in

src/external/electrs.ts:189


getLatestBlockHeight

getLatestBlockHeight(): Promise<number>

Returns

Promise<number>

The height of the latest Bitcoin block

Implementation of

ElectrsAPI.getLatestBlockHeight

Defined in

src/external/electrs.ts:193


getMerkleProof

getMerkleProof(txid): Promise<string>

Parameters

Name Type Description
txid string The ID of a Bitcoin transaction

Returns

Promise<string>

The merkle inclusion proof for the transaction using bitcoind’s merkleblock format.

Implementation of

ElectrsAPI.getMerkleProof

Defined in

src/external/electrs.ts:197


getParsedExecutionParameters

getParsedExecutionParameters(txid): Promise<[BitcoinMerkleProof, Transaction]>

Get the parsed (as Bytes) merkle proof and raw transaction

Parameters

Name Type Description
txid string A Bitcoin transaction ID

Returns

Promise<[BitcoinMerkleProof, Transaction]>

A tuple representing [merkleProof, transaction]

Remarks

Performs the lookup using an external service, Esplora

Implementation of

ElectrsAPI.getParsedExecutionParameters

Defined in

src/external/electrs.ts:422


getRawTransaction

getRawTransaction(txid): Promise<string>

Parameters

Name Type Description
txid string The ID of a Bitcoin transaction

Returns

Promise<string>

The raw transaction data, represented as a hex string

Implementation of

ElectrsAPI.getRawTransaction

Defined in

src/external/electrs.ts:428


getTransactionBlockHeight

getTransactionBlockHeight(txid): Promise<undefined | number>

Parameters

Name Type Description
txid string The ID of a Bitcoin transaction

Returns

Promise<undefined | number>

The height of the block the transaction was included in. If the block has not been confirmed, returns undefined.

Implementation of

ElectrsAPI.getTransactionBlockHeight

Defined in

src/external/electrs.ts:418


getTransactionStatus

getTransactionStatus(txid): Promise<TxStatus>

Parameters

Name Type Description
txid string The ID of a Bitcoin transaction

Returns

Promise<TxStatus>

A TxStatus object, containing the confirmation status and number of confirmations, plus block height if the tx is included in the blockchain

Implementation of

ElectrsAPI.getTransactionStatus

Defined in

src/external/electrs.ts:394


getTx

getTx(txid): Promise<Transaction>

Fetch the Bitcoin transaction that matches the given TxId

Parameters

Name Type Description
txid string A Bitcoin transaction ID

Returns

Promise<Transaction>

A Bitcoin Transaction object

Remarks

Performs the lookup using an external service, Esplora

Implementation of

ElectrsAPI.getTx

Defined in

src/external/electrs.ts:201


getTxIdByOpReturn

getTxIdByOpReturn(opReturn, recipientAddress?, amount?): Promise<string>

Fetch the first bitcoin transaction ID based on the OP_RETURN field, recipient and amount. Throw an error unless there is exactly one transaction with the given opcode.

Parameters

Name Type Description
opReturn string Data string used for matching the OP_CODE of Bitcoin transactions
recipientAddress? string Match the receiving address of a transaction that contains said op_return
amount? BitcoinAmount Match the amount (in BTC) of a transaction that contains said op_return and recipientAddress. This parameter is only considered if recipientAddress is defined.

Returns

Promise<string>

A Bitcoin transaction ID

Remarks

Performs the lookup using an external service, Esplora. Requires the input string to be a hex

Implementation of

ElectrsAPI.getTxIdByOpReturn

Defined in

src/external/electrs.ts:297


getTxStatus

getTxStatus(txid): Promise<Status>

Use the TxAPI to get the confirmationation

Parameters

Name Type Description
txid string The ID of a Bitcoin transaction

Returns

Promise<Status>

A Status object, containing transaction settlement information

Defined in

src/external/electrs.ts:447


getUtxoAmount

getUtxoAmount(txid, recipient): Promise<number>

Fetch the Bitcoin UTXO amount that matches the given TxId and recipient

Parameters

Name Type Description
txid string A Bitcoin transaction ID
recipient string A Bitcoin scriptpubkey address

Returns

Promise<number>

A UTXO amount if found, 0 otherwise

Remarks

Performs the lookup using an external service, Esplora

Implementation of

ElectrsAPI.getUtxoAmount

Defined in

src/external/electrs.ts:205


txOutputHasRecipientAndAmount

txOutputHasRecipientAndAmount(vout, recipientAddress?, amount?): boolean

Check if a given UTXO sends at least amountAsBTC to a certain recipientAddress

Parameters

Name Type Description
vout VOut UTXO object
recipientAddress? string (Optional) Address of recipient
amount? BitcoinAmount -

Returns

boolean

Boolean value

Defined in

src/external/electrs.ts:375


txoHasAtLeastAmount

txoHasAtLeastAmount(txo, amount?): boolean

Check if a given UTXO has at least amountAsBTC

Parameters

Name Type
txo VOut | UTXO
amount? BitcoinAmount

Returns

boolean

Boolean value

Defined in

src/external/electrs.ts:284


waitForOpreturn

waitForOpreturn(data, timeoutMs, retryIntervalMs): Promise<string>

Return a promise that either resolves to the first txid with the given opreturn data, or rejects if the timeout has elapsed.

Parameters

Name Type Description
data string The opReturn of the bitcoin transaction
timeoutMs number The duration until the Promise times out (in milliseconds)
retryIntervalMs number The time to wait (in milliseconds) between retries

Returns

Promise<string>

The Bitcoin txid

Remarks

Every 5 seconds, performs the lookup using an external service, Esplora

Implementation of

ElectrsAPI.waitForOpreturn

Defined in

src/external/electrs.ts:326


waitForTxInclusion

waitForTxInclusion(txid, timeoutMs, retryIntervalMs): Promise<TxStatus>

Parameters

Name Type Description
txid string The ID of a Bitcoin transaction
timeoutMs number -
retryIntervalMs number -

Returns

Promise<TxStatus>

A TxStatus object, containing the confirmation status and number of confirmations, plus block height if the tx is included in the blockchain

Implementation of

ElectrsAPI.waitForTxInclusion

Defined in

src/external/electrs.ts:345