Skip to main content

BitcoinWallet

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:53

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

Extended by

Implements

Constructors

Constructor

new BitcoinWallet(
mempoolApi,
network,
feeMultiplier,
feeOverride?): BitcoinWallet;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:60

Parameters

ParameterTypeDefault value
mempoolApiBitcoinRpcWithAddressIndex<any>undefined
networkanyundefined
feeMultipliernumber1.25
feeOverride?numberundefined

Returns

BitcoinWallet

Properties

feeMultiplier

protected feeMultiplier: number;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:57


feeOverride?

protected optional feeOverride: number;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:58


network

protected readonly network: BTC_NETWORK;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:56


rpc

protected readonly rpc: BitcoinRpcWithAddressIndex<any>;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:55

Methods

bitcoinNetworkToObject()

static bitcoinNetworkToObject(network): BTC_NETWORK;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:385

Parameters

ParameterType
networkBitcoinNetwork

Returns

BTC_NETWORK


fundPsbt()

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

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:368

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

Parameters

ParameterTypeDescription
psbtTransactionPSBT to add the inputs to
feeRate?numberOptional fee rate in sats/vB to use for the transaction
utxos?BitcoinWalletUtxo[]Pre-fetched list of UTXOs to spend from
spendFully?booleanInstructs the wallet to spend all the passed UTXOs in the transaction without creating any change output, if the feeRate is passed, it will also enforce that the feeRate in sats/vB for the resulting transaction is not more than 50% and 10 sats/vB larger (considering also the CPFP adjustments)

Returns

Promise<Transaction>

Implementation of

IBitcoinWallet.fundPsbt


getBalance()

abstract getBalance(): Promise<{
confirmedBalance: bigint;
unconfirmedBalance: bigint;
}>;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:375

Returns confirmed and unconfirmed balance in satoshis of the wallet

Returns

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

Implementation of

IBitcoinWallet.getBalance


getFeeRate()

getFeeRate(): Promise<number>;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:74

Returns the current fee rate in sats/vB

Returns

Promise<number>

Implementation of

IBitcoinWallet.getFeeRate


getFundedPsbtFee()

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

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:372

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

Parameters

ParameterTypeDescription
psbtTransactionA PSBT to which additional inputs from wallet's UTXO set will be added and fee estimated
feeRate?numberOptional fee rate in sats/vB to use for the transaction

Returns

Promise<number>

Implementation of

IBitcoinWallet.getFundedPsbtFee


getReceiveAddress()

abstract getReceiveAddress(): string;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:374

Returns the bitcoin address suitable for receiving funds

Returns

string

Implementation of

IBitcoinWallet.getReceiveAddress


getSpendableBalance()

static getSpendableBalance(
utxoPool,
feeRate,
psbt?,
outputAddressType?): object;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:389

Parameters

ParameterType
utxoPoolBitcoinWalletUtxoBase[]
feeRatenumber
psbt?Transaction
outputAddressType?CoinselectAddressTypes

Returns

object

NameTypeDefined in
balancebigintatomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:395
totalFeenumberatomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:396

getSpendableBalance()

abstract getSpendableBalance(psbt?, feeRate?): Promise<{
balance: bigint;
feeRate: number;
totalFee: number;
}>;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:379

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

Parameters

ParameterTypeDescription
psbt?TransactionA PSBT to which additional inputs from wallet's UTXO set will be added and fee estimated
feeRate?numberOptional fee rate in sats/vB to use for the transaction

Returns

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

Implementation of

IBitcoinWallet.getSpendableBalance


getTransactionFee()

abstract getTransactionFee(
address,
amount,
feeRate?): Promise<number>;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:371

Estimates a total fee in satoshis for a given transaction

Parameters

ParameterTypeDescription
addressstringDestination address of the transaction
amountbigintAmount of satoshis to send (1 BTC = 100,000,000 sats)
feeRate?numberOptional fee rate in sats/vB to use for the transaction

Returns

Promise<number>

Implementation of

IBitcoinWallet.getTransactionFee


sendTransaction()

abstract sendTransaction(
address,
amount,
feeRate?): Promise<string>;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:367

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

Parameters

ParameterTypeDescription
addressstringDestination address of the transaction
amountbigintAmount of satoshis to send (1 BTC = 100,000,000 sats)
feeRate?numberOptional fee rate in sats/vB to use for the transaction

Returns

Promise<string>

Implementation of

IBitcoinWallet.sendTransaction


signPsbt()

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

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:369

Signs inputs in the provided PSBT

Parameters

ParameterTypeDescription
psbtTransactionA PSBT to sign
signInputsnumber[]Indices of the inputs to sign

Returns

Promise<Transaction>

Implementation of

IBitcoinWallet.signPsbt


_fundPsbt()

protected _fundPsbt(
sendingAccounts,
psbt,
_feeRate?,
utxos?,
spendFully?): Promise<{
fee: number;
inputAddressIndexes?: {
[address: string]: number[];
};
psbt?: Transaction;
}>;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:178

Parameters

ParameterType
sendingAccountsobject[]
psbtTransaction
_feeRate?number
utxos?BitcoinWalletUtxo[]
spendFully?boolean

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:99

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

Parameters

ParameterTypeDescription
addressstring

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:156

Parameters

ParameterTypeDescription
sendingAccountsobject[]
recipientstring
amountnumber
feeRate?number

Returns

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


_getSpendableBalance()

protected _getSpendableBalance(
sendingAccounts,
psbt?,
feeRate?,
outputAddressType?,
utxoPool?): Promise<{
balance: bigint;
feeRate: number;
totalFee: number;
}>;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:339

Parameters

ParameterType
sendingAccountsobject[]
psbt?Transaction
feeRate?number
outputAddressType?CoinselectAddressTypes
utxoPool?BitcoinWalletUtxoBase[]

Returns

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


_getUtxoPool()

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

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:110

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

Parameters

ParameterTypeDescription
sendingAddressstring
sendingAddressTypeCoinselectAddressTypes

Returns

Promise<BitcoinWalletUtxo[]>


_sendTransaction()

protected _sendTransaction(rawHex): Promise<string>;

Defined in: atomiq-sdk/src/bitcoin/wallet/BitcoinWallet.ts:89

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

Parameters

ParameterTypeDescription
rawHexstringSerialized bitcoin transaction in hexadecimal format

Returns

Promise<string>

txId Transaction ID of the submitted bitcoin transaction