# BitcoinRpcWithAddressIndex\<T>

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpcWithAddressIndex.ts:36](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpcWithAddressIndex.ts#L36)

An extended interface for Bitcoin, that allows querying balances and UTXOs of any address + other utilities

## Extends

* [`BitcoinRpc`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md)<`T`>

## Type Parameters

| Type Parameter           |
| ------------------------ |
| `T` *extends* `BtcBlock` |

## Methods

### checkAddressTxos()

```
checkAddressTxos(address, txoHash): Promise<{

  tx: Omit<BtcTxWithBlockheight, "hex" | "raw">;

  vout: number;

}>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpcWithAddressIndex.ts:111](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpcWithAddressIndex.ts#L111)

Checks if an address received the transaction with the required txoHash, returns info about that specific transaction if found, or null if not found

#### Parameters

| Parameter | Type     | Description                                 |
| --------- | -------- | ------------------------------------------- |
| `address` | `string` | Address that should receive the transaction |
| `txoHash` | `Buffer` | Required output txoHash                     |

#### Returns

`Promise`<{ `tx`: `Omit`<`BtcTxWithBlockheight`, `"hex"` | `"raw"`>; `vout`: `number`; }>

***

### getAddressBalances()

```
getAddressBalances(address): Promise<{

  confirmedBalance: bigint;

  unconfirmedBalance: bigint;

}>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpcWithAddressIndex.ts:48](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpcWithAddressIndex.ts#L48)

Returns confirmed & unconfirmed balances for a given wallet address

#### Parameters

| Parameter | Type     | Description |
| --------- | -------- | ----------- |
| `address` | `string` |             |

#### Returns

`Promise`<{ `confirmedBalance`: `bigint`; `unconfirmedBalance`: `bigint`; }>

***

### getAddressUTXOs()

```
getAddressUTXOs(address): Promise<BtcAddressUtxo[]>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpcWithAddressIndex.ts:57](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpcWithAddressIndex.ts#L57)

Returns UTXOs owned by the given wallet address

#### Parameters

| Parameter | Type     | Description |
| --------- | -------- | ----------- |
| `address` | `string` |             |

#### Returns

`Promise`<`BtcAddressUtxo`\[]>

***

### getBlockhash()

```
getBlockhash(height): Promise<string>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpc.ts:188](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpc.ts#L188)

Returns blockhash of a block at a given block height

#### Parameters

| Parameter | Type     | Description |
| --------- | -------- | ----------- |
| `height`  | `number` |             |

#### Returns

`Promise`<`string`>

#### Inherited from

[`BitcoinRpc`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md).[`getBlockhash`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md#getblockhash)

***

### getBlockHeader()

```
getBlockHeader(blockhash): Promise<T>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpc.ts:161](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpc.ts#L161)

Gets the bitcoin blockheader as identifier by the passed blockhash

#### Parameters

| Parameter   | Type     | Description |
| ----------- | -------- | ----------- |
| `blockhash` | `string` |             |

#### Returns

`Promise`<`T`>

#### Inherited from

[`BitcoinRpc`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md).[`getBlockHeader`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md#getblockheader)

***

### getBlockWithTransactions()

```
getBlockWithTransactions(blockhash): Promise<BtcBlockWithTxs>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpc.ts:195](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpc.ts#L195)

Returns Bitcoin block with all the transactions based on blockhash

#### Parameters

| Parameter   | Type     | Description |
| ----------- | -------- | ----------- |
| `blockhash` | `string` |             |

#### Returns

`Promise`<`BtcBlockWithTxs`>

#### Inherited from

[`BitcoinRpc`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md).[`getBlockWithTransactions`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md#getblockwithtransactions)

***

### getConfirmationDelay()

```
getConfirmationDelay(tx, requiredConfirmations): Promise<number>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpcWithAddressIndex.ts:102](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpcWithAddressIndex.ts#L102)

Returns an estimate after which time the tx will confirm with the required amount of confirmations, confirmationDelay of -1 means the transaction won't confirm in the near future

#### Parameters

| Parameter               | Type     | Description |
| ----------------------- | -------- | ----------- |
| `tx`                    | `BtcTx`  |             |
| `requiredConfirmations` | `number` |             |

#### Returns

`Promise`<`number`>

estimated confirmation delay, -1 if the transaction won't confirm in the near future, null if the transaction was replaced or was confirmed in the meantime

***

### getCPFPData()

```
getCPFPData(txId): Promise<{

  adjustedVsize: number;

  effectiveFeePerVsize: number;

}>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpcWithAddressIndex.ts:65](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpcWithAddressIndex.ts#L65)

Returns CPFP (children-pay-for-parent) data for a given transaction, or null if transaction is not found or already confirmed

#### Parameters

| Parameter | Type     | Description |
| --------- | -------- | ----------- |
| `txId`    | `string` |             |

#### Returns

`Promise`<{ `adjustedVsize`: `number`; `effectiveFeePerVsize`: `number`; }>

***

### getEffectiveFeeRate()

```
getEffectiveFeeRate(btcTx): Promise<{

  fee: number;

  feeRate: number;

  vsize: number;

}>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpc.ts:243](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpc.ts#L243)

Returns an effective fee rate of the provided bitcoin transaction, this takes into consideration the current fee rates of the potential unconfirmed inputs of the transaction that are already in the mempool

#### Parameters

| Parameter | Type    | Description |
| --------- | ------- | ----------- |
| `btcTx`   | `BtcTx` |             |

#### Returns

`Promise`<{ `fee`: `number`; `feeRate`: `number`; `vsize`: `number`; }>

#### Inherited from

[`BitcoinRpc`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md).[`getEffectiveFeeRate`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md#geteffectivefeerate)

***

### getFeeRate()

```
getFeeRate(): Promise<number>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpcWithAddressIndex.ts:41](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpcWithAddressIndex.ts#L41)

Returns the current fee rate required for submitted bitcoin transactions in sats/vB

#### Returns

`Promise`<`number`>

***

### getMerkleProof()

```
getMerkleProof(txId, blockhash): Promise<{

  blockheight: number;

  merkle: Buffer<ArrayBufferLike>[];

  pos: number;

  reversedTxId: Buffer;

}>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpc.ts:169](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpc.ts#L169)

Returns a merkle proof for a given transaction

#### Parameters

| Parameter   | Type     | Description                                         |
| ----------- | -------- | --------------------------------------------------- |
| `txId`      | `string` | Identifies the transaction                          |
| `blockhash` | `string` | The blockhash in which the transaction was included |

#### Returns

`Promise`<{ `blockheight`: `number`; `merkle`: `Buffer`<`ArrayBufferLike`>\[]; `pos`: `number`; `reversedTxId`: `Buffer`; }>

#### Inherited from

[`BitcoinRpc`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md).[`getMerkleProof`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md#getmerkleproof)

***

### getSyncInfo()

```
getSyncInfo(): Promise<BtcSyncInfo>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpc.ts:219](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpc.ts#L219)

Returns the synchronization information of the underlying bitcoin RPC

#### Returns

`Promise`<`BtcSyncInfo`>

#### Inherited from

[`BitcoinRpc`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md).[`getSyncInfo`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md#getsyncinfo)

***

### getTipHeight()

```
getTipHeight(): Promise<number>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpc.ts:214](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpc.ts#L214)

Returns the current tip blockheight of bitcoin

#### Returns

`Promise`<`number`>

#### Inherited from

[`BitcoinRpc`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md).[`getTipHeight`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md#gettipheight)

***

### getTransaction()

```
getTransaction(txId): Promise<BtcTxWithBlockheight>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpcWithAddressIndex.ts:73](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpcWithAddressIndex.ts#L73)

Returns the bitcoin transaction as identified by its txId

#### Parameters

| Parameter | Type     | Description |
| --------- | -------- | ----------- |
| `txId`    | `string` |             |

#### Returns

`Promise`<`BtcTxWithBlockheight`>

#### Overrides

[`BitcoinRpc`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md).[`getTransaction`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md#gettransaction)

***

### isInMainChain()

```
isInMainChain(blockhash): Promise<boolean>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpc.ts:154](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpc.ts#L154)

Checks whether a given blockhash is part of the canonical chain

#### Parameters

| Parameter   | Type     | Description |
| ----------- | -------- | ----------- |
| `blockhash` | `string` |             |

#### Returns

`Promise`<`boolean`>

#### Inherited from

[`BitcoinRpc`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md).[`isInMainChain`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md#isinmainchain)

***

### isSpent()

```
isSpent(utxo, confirmed?): Promise<boolean>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpc.ts:234](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpc.ts#L234)

Returns whether a given UTXO is spent or not, returns `false` for non-existing UTXOs

#### Parameters

| Parameter    | Type      | Description                                                         |
| ------------ | --------- | ------------------------------------------------------------------- |
| `utxo`       | `string`  | The UTXO to check, should be in format \[txId]:\[vout]              |
| `confirmed?` | `boolean` | Whether the spent has to be confirmed or can also be in the mempool |

#### Returns

`Promise`<`boolean`>

#### Inherited from

[`BitcoinRpc`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md).[`isSpent`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md#isspent)

***

### outputScriptToAddress()?

```
optional outputScriptToAddress(outputScriptHex): Promise<string>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpc.ts:250](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpc.ts#L250)

Parses a bitcoin address from the passed output script in hexadecimal format

#### Parameters

| Parameter         | Type     | Description |
| ----------------- | -------- | ----------- |
| `outputScriptHex` | `string` |             |

#### Returns

`Promise`<`string`>

#### Inherited from

[`BitcoinRpc`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md).[`outputScriptToAddress`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md#outputscripttoaddress)

***

### parseTransaction()

```
parseTransaction(rawTx): Promise<BtcTx>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpc.ts:226](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpc.ts#L226)

Parses a raw bitcoin transaction

#### Parameters

| Parameter | Type     | Description                             |
| --------- | -------- | --------------------------------------- |
| `rawTx`   | `string` | Hexadecimal-encoded bitcoin transaction |

#### Returns

`Promise`<`BtcTx`>

#### Inherited from

[`BitcoinRpc`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md).[`parseTransaction`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md#parsetransaction)

***

### sendRawPackage()

```
sendRawPackage(rawTx): Promise<string[]>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpc.ts:209](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpc.ts#L209)

Sends a Bitcoin transaction package composed of multiple individual transactions at the same time

#### Parameters

| Parameter | Type        | Description                                          |
| --------- | ----------- | ---------------------------------------------------- |
| `rawTx`   | `string`\[] | An array of hexadecimal-encoded bitcoin transactions |

#### Returns

`Promise`<`string`\[]>

#### Inherited from

[`BitcoinRpc`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md).[`sendRawPackage`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md#sendrawpackage)

***

### sendRawTransaction()

```
sendRawTransaction(rawTx): Promise<string>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpc.ts:202](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpc.ts#L202)

Sends a single raw transaction

#### Parameters

| Parameter | Type     | Description                               |
| --------- | -------- | ----------------------------------------- |
| `rawTx`   | `string` | A hexadecimal-encoded bitcoin transaction |

#### Returns

`Promise`<`string`>

#### Inherited from

[`BitcoinRpc`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md).[`sendRawTransaction`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpc.md#sendrawtransaction)

***

### waitForAddressTxo()

```
waitForAddressTxo(

   address, 

   txoHash, 

   requiredConfirmations, 

   stateUpdateCbk, 

   abortSignal?, 

   intervalSeconds?): Promise<{

  tx: Omit<BtcTxWithBlockheight, "hex" | "raw">;

  vout: number;

}>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpcWithAddressIndex.ts:126](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpcWithAddressIndex.ts#L126)

Waits till the address receives a transaction containing a specific txoHash

#### Parameters

| Parameter               | Type                                      | Description                                 |
| ----------------------- | ----------------------------------------- | ------------------------------------------- |
| `address`               | `string`                                  | Address that should receive the transaction |
| `txoHash`               | `Buffer`                                  | Required output txoHash                     |
| `requiredConfirmations` | `number`                                  | Required confirmations of the transaction   |
| `stateUpdateCbk`        | (`btcTx?`, `vout?`, `txEtaMS?`) => `void` | Callback for transaction state updates      |
| `abortSignal?`          | `AbortSignal`                             | Abort signal                                |
| `intervalSeconds?`      | `number`                                  | How often to check new transaction          |

#### Returns

`Promise`<{ `tx`: `Omit`<`BtcTxWithBlockheight`, `"hex"` | `"raw"`>; `vout`: `number`; }>

***

### waitForTransaction()

```
waitForTransaction(

   txId, 

   requiredConfirmations, 

   stateUpdateCbk?, 

   abortSignal?, 

intervalSeconds?): Promise<BtcTxWithBlockheight>;
```

Defined in: [atomiq-base/src/btc/rpc/BitcoinRpcWithAddressIndex.ts:84](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/btc/rpc/BitcoinRpcWithAddressIndex.ts#L84)

Awaits till the given transaction gets confirmed

#### Parameters

| Parameter               | Type                             | Description                                                                        |
| ----------------------- | -------------------------------- | ---------------------------------------------------------------------------------- |
| `txId`                  | `string`                         | Transaction ID to monitor                                                          |
| `requiredConfirmations` | `number`                         | Required number of confirmations                                                   |
| `stateUpdateCbk?`       | (`btcTx?`, `txEtaMS?`) => `void` | Optional update callback called with the current status of the bitcoin transaction |
| `abortSignal?`          | `AbortSignal`                    |                                                                                    |
| `intervalSeconds?`      | `number`                         | How often to poll                                                                  |

#### Returns

`Promise`<`BtcTxWithBlockheight`>
