# BitcoinWallet

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:71](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L71)

Abstract base class for Bitcoin wallet implementations, using bitcoin rpc with address index as a backend for fetching balances, UTXOs, etc.

## Extended by

* [`SingleAddressBitcoinWallet`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/SingleAddressBitcoinWallet.md)

## Implements

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

## Constructors

### Constructor

```
new BitcoinWallet(

   mempoolApi, 

   network, 

   feeMultiplier, 

   feeOverride?): BitcoinWallet;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:78](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L78)

#### Parameters

| Parameter       | Type                                                                                                                                          | Default value |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
| `mempoolApi`    | [`BitcoinRpcWithAddressIndex`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpcWithAddressIndex.md)<`any`> | `undefined`   |
| `network`       | `any`                                                                                                                                         | `undefined`   |
| `feeMultiplier` | `number`                                                                                                                                      | `1.25`        |
| `feeOverride?`  | `number`                                                                                                                                      | `undefined`   |

#### Returns

`BitcoinWallet`

## Properties

### feeMultiplier

```
protected feeMultiplier: number;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:75](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L75)

***

### feeOverride?

```
protected optional feeOverride: number;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:76](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L76)

***

### network

```
protected readonly network: BTC_NETWORK;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:74](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L74)

***

### rpc

```
protected readonly rpc: BitcoinRpcWithAddressIndex<any>;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:73](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L73)

## Methods

### bitcoinNetworkToObject()

```
static bitcoinNetworkToObject(network): BTC_NETWORK;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:424](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L424)

#### Parameters

| Parameter | Type                                                                                                             |
| --------- | ---------------------------------------------------------------------------------------------------------------- |
| `network` | [`BitcoinNetwork`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/enumerations/BitcoinNetwork.md) |

#### Returns

`BTC_NETWORK`

***

### fundPsbt()

```
abstract fundPsbt(psbt, feeRate?): Promise<Transaction>;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:407](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L407)

Funds (populates the inputs) for a given PSBT from wallet's UTXO set

#### Parameters

| Parameter  | Type          | Description                                             |
| ---------- | ------------- | ------------------------------------------------------- |
| `psbt`     | `Transaction` | PSBT to add the inputs to                               |
| `feeRate?` | `number`      | Optional fee rate in sats/vB to use for the transaction |

#### Returns

`Promise`<`Transaction`>

#### Implementation of

[`IBitcoinWallet`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md).[`fundPsbt`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md#fundpsbt)

***

### getBalance()

```
abstract getBalance(): Promise<{

  confirmedBalance: bigint;

  unconfirmedBalance: bigint;

}>;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:414](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L414)

Returns confirmed and unconfirmed balance in satoshis of the wallet

#### Returns

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

#### Implementation of

[`IBitcoinWallet`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md).[`getBalance`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md#getbalance)

***

### getFeeRate()

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

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:92](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L92)

Returns the current fee rate in sats/vB

#### Returns

`Promise`<`number`>

#### Implementation of

[`IBitcoinWallet`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md).[`getFeeRate`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md#getfeerate)

***

### getFundedPsbtFee()

```
abstract getFundedPsbtFee(psbt, feeRate?): Promise<number>;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:411](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L411)

Estimates a total fee in satoshis for a given transaction as identified by the PSBT

#### Parameters

| Parameter  | Type          | Description                                                                              |
| ---------- | ------------- | ---------------------------------------------------------------------------------------- |
| `psbt`     | `Transaction` | A PSBT to which additional inputs from wallet's UTXO set will be added and fee estimated |
| `feeRate?` | `number`      | Optional fee rate in sats/vB to use for the transaction                                  |

#### Returns

`Promise`<`number`>

#### Implementation of

[`IBitcoinWallet`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md).[`getFundedPsbtFee`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md#getfundedpsbtfee)

***

### getReceiveAddress()

```
abstract getReceiveAddress(): string;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:413](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L413)

Returns the bitcoin address suitable for receiving funds

#### Returns

`string`

#### Implementation of

[`IBitcoinWallet`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md).[`getReceiveAddress`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md#getreceiveaddress)

***

### getSpendableBalance()

```
abstract getSpendableBalance(psbt?, feeRate?): Promise<{

  balance: bigint;

  feeRate: number;

  totalFee: number;

}>;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:418](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L418)

Returns the maximum spendable balance in satoshis given a specific PSBT that should be funded

#### Parameters

| Parameter  | Type          | Description                                                                              |
| ---------- | ------------- | ---------------------------------------------------------------------------------------- |
| `psbt?`    | `Transaction` | A PSBT to which additional inputs from wallet's UTXO set will be added and fee estimated |
| `feeRate?` | `number`      | Optional fee rate in sats/vB to use for the transaction                                  |

#### Returns

`Promise`<{ `balance`: `bigint`; `feeRate`: `number`; `totalFee`: `number`; }>

#### Implementation of

[`IBitcoinWallet`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md).[`getSpendableBalance`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md#getspendablebalance)

***

### getTransactionFee()

```
abstract getTransactionFee(

   address, 

   amount, 

feeRate?): Promise<number>;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:410](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L410)

Estimates a total fee in satoshis for a given transaction

#### Parameters

| Parameter  | Type     | Description                                             |
| ---------- | -------- | ------------------------------------------------------- |
| `address`  | `string` | Destination address of the transaction                  |
| `amount`   | `bigint` | Amount of satoshis to send (1 BTC = 100,000,000 sats)   |
| `feeRate?` | `number` | Optional fee rate in sats/vB to use for the transaction |

#### Returns

`Promise`<`number`>

#### Implementation of

[`IBitcoinWallet`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md).[`getTransactionFee`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md#gettransactionfee)

***

### sendTransaction()

```
abstract sendTransaction(

   address, 

   amount, 

feeRate?): Promise<string>;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:406](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L406)

Signs and broadcasts a transaction sending `amount` of sats to `address`, optionally with the `feeRate` sats/vB fee rate.

#### Parameters

| Parameter  | Type     | Description                                             |
| ---------- | -------- | ------------------------------------------------------- |
| `address`  | `string` | Destination address of the transaction                  |
| `amount`   | `bigint` | Amount of satoshis to send (1 BTC = 100,000,000 sats)   |
| `feeRate?` | `number` | Optional fee rate in sats/vB to use for the transaction |

#### Returns

`Promise`<`string`>

#### Implementation of

[`IBitcoinWallet`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md).[`sendTransaction`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md#sendtransaction)

***

### signPsbt()

```
abstract signPsbt(psbt, signInputs): Promise<Transaction>;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:408](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L408)

Signs inputs in the provided PSBT

#### Parameters

| Parameter    | Type          | Description                   |
| ------------ | ------------- | ----------------------------- |
| `psbt`       | `Transaction` | A PSBT to sign                |
| `signInputs` | `number`\[]   | Indices of the inputs to sign |

#### Returns

`Promise`<`Transaction`>

#### Implementation of

[`IBitcoinWallet`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md).[`signPsbt`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IBitcoinWallet.md#signpsbt)

***

### \_fundPsbt()

```
protected _fundPsbt(

   sendingAccounts, 

   psbt, 

   feeRate?): Promise<{

  fee: number;

  inputAddressIndexes?: {

   [address: string]: number[];

  };

  psbt?: Transaction;

}>;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:196](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L196)

#### Parameters

| Parameter         | Type          |
| ----------------- | ------------- |
| `sendingAccounts` | `object`\[]   |
| `psbt`            | `Transaction` |
| `feeRate?`        | `number`      |

#### Returns

`Promise`<{ `fee`: `number`; `inputAddressIndexes?`: { \[`address`: `string`]: `number`\[]; }; `psbt?`: `Transaction`; }>

***

### \_getBalance()

```
protected _getBalance(address): Promise<{

  confirmedBalance: bigint;

  unconfirmedBalance: bigint;

}>;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:117](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L117)

Internal helper function for fetching the balance of the wallet given a specific bitcoin wallet address

#### Parameters

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

#### Returns

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

***

### \_getPsbt()

```
protected _getPsbt(

   sendingAccounts, 

   recipient, 

   amount, 

   feeRate?): Promise<{

  fee: number;

  inputAddressIndexes?: {

   [address: string]: number[];

  };

  psbt?: Transaction;

}>;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:174](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L174)

#### Parameters

| Parameter         | Type        | Description |
| ----------------- | ----------- | ----------- |
| `sendingAccounts` | `object`\[] |             |
| `recipient`       | `string`    |             |
| `amount`          | `number`    |             |
| `feeRate?`        | `number`    |             |

#### Returns

`Promise`<{ `fee`: `number`; `inputAddressIndexes?`: { \[`address`: `string`]: `number`\[]; }; `psbt?`: `Transaction`; }>

***

### \_getSpendableBalance()

```
protected _getSpendableBalance(

   sendingAccounts, 

   psbt?, 

   feeRate?): Promise<{

  balance: bigint;

  feeRate: number;

  totalFee: number;

}>;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:343](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L343)

#### Parameters

| Parameter         | Type          |
| ----------------- | ------------- |
| `sendingAccounts` | `object`\[]   |
| `psbt?`           | `Transaction` |
| `feeRate?`        | `number`      |

#### Returns

`Promise`<{ `balance`: `bigint`; `feeRate`: `number`; `totalFee`: `number`; }>

***

### \_getUtxoPool()

```
protected _getUtxoPool(sendingAddress, sendingAddressType): Promise<BitcoinWalletUtxo[]>;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:128](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L128)

Internal helper function for fetching the UTXO set of a given wallet address

#### Parameters

| Parameter            | Type                                                                                                                             | Description |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `sendingAddress`     | `string`                                                                                                                         |             |
| `sendingAddressType` | [`CoinselectAddressTypes`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/CoinselectAddressTypes.md) |             |

#### Returns

`Promise`<[`BitcoinWalletUtxo`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/BitcoinWalletUtxo.md)\[]>

***

### \_sendTransaction()

```
protected _sendTransaction(rawHex): Promise<string>;
```

Defined in: [atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:107](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/bitcoin/wallet/BitcoinWallet.ts#L107)

Internal helper function for sending a raw transaction through the underlying RPC

#### Parameters

| Parameter | Type     | Description                                          |
| --------- | -------- | ---------------------------------------------------- |
| `rawHex`  | `string` | Serialized bitcoin transaction in hexadecimal format |

#### Returns

`Promise`<`string`>

txId Transaction ID of the submitted bitcoin transaction
