@interlay/interbtc-api / Exports / DefaultElectrsAPI
Bitcoin Core API
• new DefaultElectrsAPI(network?): DefaultElectrsAPI
| Name | Type | Default value |
|---|---|---|
network |
string |
"mainnet" |
• Private addressApi: AddressApi
• Private blockApi: BlockApi
• Private scripthashApi: ScripthashApi
• Private txApi: TxApi
▸ broadcastRawTransaction(hex): Promise<AxiosResponse<string>>
Broadcasts a transaction to the Bitcoin network configured in the constructor
| Name | Type | Description |
|---|---|---|
hex |
string |
A hex-encoded raw transaction to be broadcast to the Bitcoin blockchain |
Promise<AxiosResponse<string>>
The txid of the transaction
▸ getCoinbaseTxId(userTxId): Promise<undefined | string>
Returns tx id of the coinbase tx of block in which userTxId was included.
| Name | Type | Description |
|---|---|---|
userTxId |
string |
User tx ID which block’s txId will be returned. |
Promise<undefined | string>
Tx ID of coinbase transaction or undefined if block was not found.
▸ getData<T>(response): Promise<T>
Parse an AxiosResponse Promise
| Name |
|---|
T |
| Name | Type | Description |
|---|---|---|
response |
Promise<AxiosResponse<T>> |
A generic AxiosResponse Promise |
Promise<T>
The data in the response
▸ 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.
| 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. |
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.
ElectrsAPI.getEarliestPaymentToRecipientAddressTxId
▸ 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.
| Name | Type | Description |
|---|---|---|
recipientAddress |
string |
Match the receiving address of a transaction output |
Promise<string>
A Bitcoin transaction ID
Remarks
Performs the lookup using an external service, Esplora
ElectrsAPI.getLargestPaymentToRecipientAddressTxId
▸ getLatestBlock(): Promise<string>
Promise<string>
The block hash of the latest Bitcoin block
▸ getLatestBlockHeight(): Promise<number>
Promise<number>
The height of the latest Bitcoin block
ElectrsAPI.getLatestBlockHeight
▸ getMerkleProof(txid): Promise<string>
| Name | Type | Description |
|---|---|---|
txid |
string |
The ID of a Bitcoin transaction |
Promise<string>
The merkle inclusion proof for the transaction using bitcoind’s merkleblock format.
▸ getParsedExecutionParameters(txid): Promise<[BitcoinMerkleProof, Transaction]>
Get the parsed (as Bytes) merkle proof and raw transaction
| Name | Type | Description |
|---|---|---|
txid |
string |
A Bitcoin transaction ID |
Promise<[BitcoinMerkleProof, Transaction]>
A tuple representing [merkleProof, transaction]
Remarks
Performs the lookup using an external service, Esplora
ElectrsAPI.getParsedExecutionParameters
▸ getRawTransaction(txid): Promise<string>
| Name | Type | Description |
|---|---|---|
txid |
string |
The ID of a Bitcoin transaction |
Promise<string>
The raw transaction data, represented as a hex string
▸ getTransactionBlockHeight(txid): Promise<undefined | number>
| Name | Type | Description |
|---|---|---|
txid |
string |
The ID of a Bitcoin transaction |
Promise<undefined | number>
The height of the block the transaction was included in. If the block has not been confirmed, returns undefined.
ElectrsAPI.getTransactionBlockHeight
▸ getTransactionStatus(txid): Promise<TxStatus>
| Name | Type | Description |
|---|---|---|
txid |
string |
The ID of a Bitcoin transaction |
Promise<TxStatus>
A TxStatus object, containing the confirmation status and number of confirmations, plus block height if the tx is included in the blockchain
ElectrsAPI.getTransactionStatus
▸ getTx(txid): Promise<Transaction>
Fetch the Bitcoin transaction that matches the given TxId
| Name | Type | Description |
|---|---|---|
txid |
string |
A Bitcoin transaction ID |
Promise<Transaction>
A Bitcoin Transaction object
Remarks
Performs the lookup using an external service, Esplora
▸ 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.
| 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. |
Promise<string>
A Bitcoin transaction ID
Remarks
Performs the lookup using an external service, Esplora. Requires the input string to be a hex
▸ getTxStatus(txid): Promise<Status>
Use the TxAPI to get the confirmationation
| Name | Type | Description |
|---|---|---|
txid |
string |
The ID of a Bitcoin transaction |
Promise<Status>
A Status object, containing transaction settlement information
▸ getUtxoAmount(txid, recipient): Promise<number>
Fetch the Bitcoin UTXO amount that matches the given TxId and recipient
| Name | Type | Description |
|---|---|---|
txid |
string |
A Bitcoin transaction ID |
recipient |
string |
A Bitcoin scriptpubkey address |
Promise<number>
A UTXO amount if found, 0 otherwise
Remarks
Performs the lookup using an external service, Esplora
▸ txOutputHasRecipientAndAmount(vout, recipientAddress?, amount?): boolean
Check if a given UTXO sends at least amountAsBTC to a certain recipientAddress
| Name | Type | Description |
|---|---|---|
vout |
VOut |
UTXO object |
recipientAddress? |
string |
(Optional) Address of recipient |
amount? |
BitcoinAmount |
- |
boolean
Boolean value
▸ txoHasAtLeastAmount(txo, amount?): boolean
Check if a given UTXO has at least amountAsBTC
| Name | Type |
|---|---|
txo |
VOut | UTXO |
amount? |
BitcoinAmount |
boolean
Boolean value
▸ 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.
| 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 |
Promise<string>
The Bitcoin txid
Remarks
Every 5 seconds, performs the lookup using an external service, Esplora
▸ waitForTxInclusion(txid, timeoutMs, retryIntervalMs): Promise<TxStatus>
| Name | Type | Description |
|---|---|---|
txid |
string |
The ID of a Bitcoin transaction |
timeoutMs |
number |
- |
retryIntervalMs |
number |
- |
Promise<TxStatus>
A TxStatus object, containing the confirmation status and number of confirmations, plus block height if the tx is included in the blockchain