Skip to content

Instantly share code, notes, and snippets.

@kallewoof
Created May 11, 2021 10:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kallewoof/cff9aa73c6e73bc2a180cfae1e0ab640 to your computer and use it in GitHub Desktop.
Save kallewoof/cff9aa73c6e73bc2a180cfae1e0ab640 to your computer and use it in GitHub Desktop.
Typescript bindings for Bitcoin Core's RPC command
export type Dict<T> = { [type: string]: T };
const Do = async <Retval>(cmd: string, ...args: (string | boolean | number | object | null | undefined)[])
: Promise<Retval> => Promise.reject();
// The above Do command should asynchronously call Bitcoin's RPC interface, e.g. like the bcrpc package.
/////////////////////////////////////////
// RPC: abandontransaction
//
/**
* Mark in-wallet transaction <txid> as abandoned
*
* This will mark this transaction and all its in-wallet descendants as abandoned which will allow
* for their inputs to be respent. It can be used to replace "stuck" or evicted transactions.
* It only works on transactions which are not included in a block and are not currently in the mempool.
* It has no effect on transactions which are already abandoned.
*
* @param {string} txid The transaction id
*/
export const Abandontransaction = (
txid: string
): Promise<void> => Do("Abandontransaction", txid);
/////////////////////////////////////////
// RPC: abortrescan
//
/**
* Stops current wallet rescan triggered by an RPC call, e
*
* g. by an importprivkey call.
* Note: Use "getwalletinfo" to query the scanning progress.
*/
export const Abortrescan = (): Promise<boolean> => Do("Abortrescan");
/////////////////////////////////////////
// RPC: addconnection
//
export interface AddconnectionResult {
/** Address of newly added connection. */
address: string;
/** Type of connection opened. */
connection_type: string;
}
/**
* Open an outbound connection to a specified node
*
* This RPC is for testing only.
*
* @param {string} address The IP address and port to attempt connecting to.
* @param {string} connectionType Type of connection to open, either "outbound-full-relay" or "block-relay-only".
*/
export const Addconnection = (
address: string,
connectionType: string
): Promise<AddconnectionResult> => Do("Addconnection", address, connectionType);
/////////////////////////////////////////
// RPC: addmultisigaddress
//
export interface AddmultisigaddressResult {
/** The value of the new multisig address */
address: string;
/** The string value of the hex-encoded redemption script */
redeemScript: string;
/** The descriptor for this multisig */
descriptor: string;
}
/**
* Add an nrequired-to-sign multisignature address to the wallet
*
* Requires a new wallet backup.
* Each key is a Bitcoin address or hex-encoded public key.
* This functionality is only intended for use with non-watchonly addresses.
* See `importaddress` for watchonly p2sh address support.
* If 'label' is specified, assign address to that label.
*
* @param {number} nrequired The number of required signatures out of the n keys or addresses.
* @param {string[]} keys The bitcoin addresses or hex-encoded public keys
* @param {string} label A label to assign the addresses to.
* @param {string} addressType The address type to use. Options are "legacy", "p2sh-segwit", and "bech32".
*/
export const Addmultisigaddress = (
nrequired: number,
keys: string[],
label?: string,
addressType?: string
): Promise<AddmultisigaddressResult> => Do("Addmultisigaddress", nrequired, keys, label, addressType);
/////////////////////////////////////////
// RPC: addnode
//
/**
* Attempts to add or remove a node from the addnode list
*
* Or try a connection to a node once.
* Nodes added using addnode (or -connect) are protected from DoS disconnection and are not required
* to be
* full nodes/support SegWit as other outbound peers are (though such peers will not be synced from).
* Addnode connections are limited to 8 at a time and are counted separately from the -maxconnections
* limit.
*
* @param {string} node The node (see getpeerinfo for nodes)
* @param {string} command 'add' to add a node to the list, 'remove' to remove a node from the list,
* 'onetry'
* to try a connection to the node once
*/
export const Addnode = (
node: string,
command: string
): Promise<void> => Do("Addnode", node, command);
/////////////////////////////////////////
// RPC: addpeeraddress
//
export interface AddpeeraddressResult {
/** whether the peer address was successfully added to the address manager */
success: boolean;
}
/**
* Add the address of a potential peer to the address manager
*
* This RPC is for testing only.
*
* @param {string} address The IP address of the peer
* @param {number} port The port of the peer
*/
export const Addpeeraddress = (
address: string,
port: number
): Promise<AddpeeraddressResult> => Do("Addpeeraddress", address, port);
/////////////////////////////////////////
// RPC: analyzepsbt
//
/**
* Things that are missing that are required to complete this input
*/
export interface AnalyzepsbtInputMissing {
pubkeys?: string[];
signatures?: string[];
/** Hash160 of the redeemScript that is missing */
redeemscript?: string;
/** SHA256 of the witnessScript that is missing */
witnessscript?: string;
}
export interface AnalyzepsbtInput {
/** Whether a UTXO is provided */
has_utxo: boolean;
/** Whether the input is finalized */
is_final: boolean;
/** Things that are missing that are required to complete this input */
missing?: AnalyzepsbtInputMissing;
/** Role of the next person that this input needs to go to */
next?: string;
}
export interface AnalyzepsbtResult {
inputs: AnalyzepsbtInput[];
/** Estimated vsize of the final signed transaction */
estimated_vsize?: number;
/**
* Estimated feerate of the final signed transaction in BTC/kB. Shown only if all UTXO slots in the
* PSBT have been filled
*/
estimated_feerate?: string;
/** The transaction fee paid. Shown only if all UTXO slots in the PSBT have been filled */
fee?: string;
/** Role of the next person that this psbt needs to go to */
next: string;
/** Error message (if there is one) */
error?: string;
}
/**
* Analyzes and provides information about the current status of a PSBT and its inputs
*
* @param {string} psbt A base64 string of a PSBT
*/
export const Analyzepsbt = (
psbt: string
): Promise<AnalyzepsbtResult> => Do("Analyzepsbt", psbt);
/////////////////////////////////////////
// RPC: backupwallet
//
/**
* Safely copies current wallet file to destination, which can be a directory or a path with filename
*
*
* @param {string} destination The destination directory or file
*/
export const Backupwallet = (
destination: string
): Promise<void> => Do("Backupwallet", destination);
/////////////////////////////////////////
// RPC: bumpfee
//
export interface BumpfeeResult {
/** The base64-encoded unsigned PSBT of the new transaction. */
psbt: string;
/** The id of the new transaction. Only returned when wallet private keys are enabled. */
txid: string;
/** The fee of the replaced transaction. */
origfee: string;
/** The fee of the new transaction. */
fee: string;
/** Errors encountered during processing (may be empty). */
errors: string[];
}
export interface BumpfeeOptions {
/**
* Confirmation target in blocks
*/
conf_target?: number;
/**
* Specify a fee rate in sat/vB instead of relying on the built-in fee estimator.
* Must be at least 1.000 sat/vB higher than the current transaction fee rate.
* WARNING: before version 0.21, fee_rate was in BTC/kvB. As of 0.21, fee_rate is in sat/vB.
*/
fee_rate?: number | string;
/**
* Whether the new transaction should still be
* marked bip-125 replaceable. If true, the sequence numbers in the transaction will
* be left unchanged from the original. If false, any input sequence numbers in the
* original transaction that were less than 0xfffffffe will be increased to 0xfffffffe
* so the new transaction will not be explicitly bip-125 replaceable (though it may
* still be replaceable in practice, for example if it has unconfirmed ancestors which
* are replaceable).
*/
replaceable?: boolean;
/**
* The fee estimate mode, must be one of (case insensitive):
* "unset"
* "economical"
* "conservative"
*/
estimate_mode?: string;
}
/**
* Bumps the fee of an opt-in-RBF transaction T, replacing it with a new transaction B
*
* An opt-in RBF transaction with the given txid must be in the wallet.
* The command will pay the additional fee by reducing change outputs or adding inputs when necessary.
* It may add a new change output if one does not already exist.
* All inputs in the original transaction will be included in the replacement transaction.
* The command will fail if the wallet or mempool contains a transaction that spends one of T's outputs.
* By default, the new fee will be calculated automatically using the estimatesmartfee RPC.
* The user can specify a confirmation target for estimatesmartfee.
* Alternatively, the user can specify a fee rate in sat/vB for the new transaction.
* At a minimum, the new fee rate must be high enough to pay an additional new relay fee (incrementalfee
* returned by getnetworkinfo) to enter the node's mempool.
* * WARNING: before version 0.21, fee_rate was in BTC/kvB. As of 0.21, fee_rate is in sat/vB. *
*
* @param {string} txid The txid to be bumped
* @param {BumpfeeOptions} options
*/
export const Bumpfee = (
txid: string,
options?: BumpfeeOptions
): Promise<BumpfeeResult> => Do("Bumpfee", txid, options);
/////////////////////////////////////////
// RPC: clearbanned
//
/**
* Clear all banned IPs
*
*/
export const Clearbanned = (): Promise<void> => Do("Clearbanned");
/////////////////////////////////////////
// RPC: combinepsbt
//
/**
* Combine multiple partially signed Bitcoin transactions into one transaction
*
* Implements the Combiner role.
*
* @param {string[]} txs The base64 strings of partially signed transactions
*/
export const Combinepsbt = (
txs: string[]
): Promise<string> => Do("Combinepsbt", txs);
/////////////////////////////////////////
// RPC: combinerawtransaction
//
/**
* Combine multiple partially signed transactions into one transaction
*
* The combined transaction may be another partially signed transaction or a
* fully signed transaction.
* @param {string[]} txs The hex strings of partially signed transactions
*/
export const Combinerawtransaction = (
txs: string[]
): Promise<string> => Do("Combinerawtransaction", txs);
/////////////////////////////////////////
// RPC: converttopsbt
//
/**
* Converts a network serialized transaction to a PSBT
*
* This should be used only with createrawtransaction and fundrawtransaction
* createpsbt and walletcreatefundedpsbt should be used for new applications.
*
* @param {string} hexstring The hex string of a raw transaction
* @param {boolean} permitsigdata If true, any signatures in the input will be discarded and conversion
* will continue. If false, RPC will fail if any signatures are present.
* @param {boolean} iswitness Whether the transaction hex is a serialized witness transaction.
* If iswitness is not present, heuristic tests will be used in decoding.
* If true, only witness deserialization will be tried.
* If false, only non-witness deserialization will be tried.
* This boolean should reflect whether the transaction has inputs
* (e.g. fully valid, or on-chain transactions), if known by the caller.
*/
export const Converttopsbt = (
hexstring: string,
permitsigdata?: boolean,
iswitness?: boolean
): Promise<string> => Do("Converttopsbt", hexstring, permitsigdata, iswitness);
/////////////////////////////////////////
// RPC: createmultisig
//
export interface CreatemultisigResult {
/** The value of the new multisig address. */
address: string;
/** The string value of the hex-encoded redemption script. */
redeemScript: string;
/** The descriptor for this multisig */
descriptor: string;
}
/**
* Creates a multi-signature address with n signature of m keys required
*
* It returns a json object with the address and redeemScript.
*
* @param {number} nrequired The number of required signatures out of the n keys.
* @param {string[]} keys The hex-encoded public keys.
* @param {string} addressType The address type to use. Options are "legacy", "p2sh-segwit", and "bech32".
*/
export const Createmultisig = (
nrequired: number,
keys: string[],
addressType?: string
): Promise<CreatemultisigResult> => Do("Createmultisig", nrequired, keys, addressType);
/////////////////////////////////////////
// RPC: createpsbt
//
export interface CreatepsbtInput {
/** The transaction id */
txid: string;
/** The output number */
vout: number;
/** The sequence number */
sequence?: number;
}
export interface CreatepsbtOutputAlt {
/** A key-value pair. The key must be "data", the value is hex-encoded data */
data: string;
}
/**
* The outputs (key-value pairs), where none of the keys are duplicated
*
* That is, each address can only appear once and there can only be one 'data' object.
* For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also
* accepted as second parameter.
*/
export type CreatepsbtOutput = Dict<number | string> | CreatepsbtOutputAlt;
/**
* Creates a transaction in the Partially Signed Transaction format
*
* Implements the Creator role.
*
* @param {CreatepsbtInput[]} inputs The json objects
* @param {CreatepsbtOutput} outputs The outputs (key-value pairs), where none of the keys are duplicated.
* That is, each address can only appear once and there can only be one 'data' object.
* For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also
* accepted as second parameter.
* @param {number} locktime Raw locktime. Non-0 value also locktime-activates inputs
* @param {boolean} replaceable Marks this transaction as BIP125 replaceable.
* Allows this transaction to be replaced by a transaction with higher
* fees. If provided, it is an error if explicit sequence numbers are incompatible.
*/
export const Createpsbt = (
inputs: CreatepsbtInput[],
outputs: CreatepsbtOutput,
locktime?: number,
replaceable?: boolean
): Promise<string> => Do("Createpsbt", inputs, outputs, locktime, replaceable);
/////////////////////////////////////////
// RPC: createrawtransaction
//
export interface CreaterawtransactionInput {
/** The transaction id */
txid: string;
/** The output number */
vout: number;
/** The sequence number */
sequence?: number;
}
export interface CreaterawtransactionOutputAlt {
/** A key-value pair. The key must be "data", the value is hex-encoded data */
data: string;
}
/**
* The outputs (key-value pairs), where none of the keys are duplicated
*
* That is, each address can only appear once and there can only be one 'data' object.
* For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also
* accepted as second parameter.
*/
export type CreaterawtransactionOutput = Dict<number | string> | CreaterawtransactionOutputAlt;
/**
* Create a transaction spending the given inputs and creating new outputs
*
* Outputs can be addresses or data.
* Returns hex-encoded raw transaction.
* Note that the transaction's inputs are not signed, and
* it is not stored in the wallet or transmitted to the network.
*
* @param {CreaterawtransactionInput[]} inputs The inputs
* @param {CreaterawtransactionOutput} outputs The outputs (key-value pairs), where none of the keys
* are
* duplicated.
* That is, each address can only appear once and there can only be one 'data' object.
* For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also
* accepted as second parameter.
* @param {number} locktime Raw locktime. Non-0 value also locktime-activates inputs
* @param {boolean} replaceable Marks this transaction as BIP125-replaceable.
* Allows this transaction to be replaced by a transaction with higher
* fees. If provided, it is an error if explicit sequence numbers are incompatible.
*/
export const Createrawtransaction = (
inputs: CreaterawtransactionInput[],
outputs: CreaterawtransactionOutput,
locktime?: number,
replaceable?: boolean
): Promise<string> => Do("Createrawtransaction", inputs, outputs, locktime, replaceable);
/////////////////////////////////////////
// RPC: createwallet
//
export interface CreatewalletResult {
/**
* The wallet name if created successfully. If the wallet was created using a full path, the wallet_name
* will be the full path.
*/
name: string;
/** Warning message if wallet was not loaded cleanly. */
warning: string;
}
/**
* Creates and loads a new wallet
*
*
* @param {string} walletName The name for the new wallet. If this is a path, the wallet will be created
* at the path location.
* @param {boolean} disablePrivateKeys Disable the possibility of private keys (only watchonlys are possible
* in this mode).
* @param {boolean} blank Create a blank wallet. A blank wallet has no keys or HD seed. One can be set
* using
* sethdseed.
* @param {string} passphrase Encrypt the wallet with this passphrase.
* @param {boolean} avoidReuse Keep track of coin reuse, and treat dirty and clean coins differently
* with
* privacy considerations in mind.
* @param {boolean} descriptors Create a native descriptor wallet. The wallet will use descriptors internally
* to handle address creation
* @param {boolean} loadOnStartup Save wallet name to persistent settings and load on startup. True to
* add
* wallet to startup list, false to remove, null to leave unchanged.
* @param {boolean} externalSigner Use an external signer such as a hardware wallet. Requires -signer
* to
* be configured. Wallet creation will fail if keys cannot be fetched. Requires disable_private_keys
* and descriptors set to true.
*/
export const Createwallet = (
walletName: string,
disablePrivateKeys?: boolean,
blank?: boolean,
passphrase?: string,
avoidReuse?: boolean,
descriptors?: boolean,
loadOnStartup?: boolean,
externalSigner?: boolean
): Promise<CreatewalletResult> => Do("Createwallet", walletName, disablePrivateKeys, blank, passphrase,
avoidReuse, descriptors, loadOnStartup, externalSigner);
/////////////////////////////////////////
// RPC: decodepsbt
//
export interface DecodepsbtInputWitnessUtxoScriptPubKey {
/** The asm */
asm: string;
/** The hex */
hex: string;
/** The type, eg 'pubkeyhash' */
type: string;
/** Bitcoin address if there is one */
address: string;
}
/**
* Transaction output for witness UTXOs
*/
export interface DecodepsbtInputWitnessUtxo {
/** The value in BTC */
amount: number;
scriptPubKey: DecodepsbtInputWitnessUtxoScriptPubKey;
}
export interface DecodepsbtInputRedeemScript {
/** The asm */
asm: string;
/** The hex */
hex: string;
/** The type, eg 'pubkeyhash' */
type: string;
}
export interface DecodepsbtInputWitnessScript {
/** The asm */
asm: string;
/** The hex */
hex: string;
/** The type, eg 'pubkeyhash' */
type: string;
}
/**
* The public key with the derivation path as the value
*/
export interface DecodepsbtInputBip32DerivPubkey {
/** The fingerprint of the master key */
master_fingerprint: string;
/** The path */
path: string;
}
export interface DecodepsbtInputFinalScriptsig {
/** The asm */
asm: string;
/** The hex */
hex: string;
}
export interface DecodepsbtInput {
/** Decoded network transaction for non-witness UTXOs */
non_witness_utxo?: Dict<string | boolean | number | object>;
/** Transaction output for witness UTXOs */
witness_utxo?: DecodepsbtInputWitnessUtxo;
partial_signatures?: Dict<string>;
/** The sighash type to be used */
sighash?: string;
redeem_script?: DecodepsbtInputRedeemScript;
witness_script?: DecodepsbtInputWitnessScript;
bip32_derivs?: DecodepsbtInputBip32DerivPubkey[];
final_scriptsig?: DecodepsbtInputFinalScriptsig;
final_scriptwitness: string[];
/** The unknown global fields */
unknown: Dict<string>;
}
export interface DecodepsbtOutputRedeemScript {
/** The asm */
asm: string;
/** The hex */
hex: string;
/** The type, eg 'pubkeyhash' */
type: string;
}
export interface DecodepsbtOutputWitnessScript {
/** The asm */
asm: string;
/** The hex */
hex: string;
/** The type, eg 'pubkeyhash' */
type: string;
}
export interface DecodepsbtOutputBip32Deriv {
/** The public key this path corresponds to */
pubkey: string;
/** The fingerprint of the master key */
master_fingerprint: string;
/** The path */
path: string;
}
export interface DecodepsbtOutput {
redeem_script?: DecodepsbtOutputRedeemScript;
witness_script?: DecodepsbtOutputWitnessScript;
bip32_derivs?: DecodepsbtOutputBip32Deriv[];
/** The unknown global fields */
unknown: Dict<string>;
}
export interface DecodepsbtResult {
/** The decoded network-serialized unsigned transaction. */
tx: Dict<string | boolean | number | object>;
/** The unknown global fields */
unknown: Dict<string>;
inputs: DecodepsbtInput[];
outputs: DecodepsbtOutput[];
/** The transaction fee paid if all UTXOs slots in the PSBT have been filled. */
fee?: string;
}
/**
* Return a JSON object representing the serialized, base64-encoded partially signed Bitcoin transaction
*
*
* @param {string} psbt The PSBT base64 string
*/
export const Decodepsbt = (
psbt: string
): Promise<DecodepsbtResult> => Do("Decodepsbt", psbt);
/////////////////////////////////////////
// RPC: decoderawtransaction
//
/**
* The script
*/
export interface DecoderawtransactionVinScriptSig {
/** asm */
asm: string;
/** hex */
hex: string;
}
export interface DecoderawtransactionVin {
/** The transaction id */
txid: string;
/** The output number */
vout: number;
/** The script */
scriptSig: DecoderawtransactionVinScriptSig;
txinwitness: string[];
/** The script sequence number */
sequence: number;
}
export interface DecoderawtransactionVoutScriptPubKey {
/** the asm */
asm: string;
/** the hex */
hex: string;
/**
* (DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required
* signatures
*/
reqSigs?: number;
/** The type, eg 'pubkeyhash' */
type: string;
/** bitcoin address (only if a well-defined address exists) */
address?: string;
/**
* (DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin
* addresses
*/
addresses?: string[];
}
export interface DecoderawtransactionVout {
/** The value in BTC */
value: number;
/** index */
n: number;
scriptPubKey: DecoderawtransactionVoutScriptPubKey;
}
export interface DecoderawtransactionResult {
/** The transaction id */
txid: string;
/** The transaction hash (differs from txid for witness transactions) */
hash: string;
/** The transaction size */
size: number;
/** The virtual transaction size (differs from size for witness transactions) */
vsize: number;
/** The transaction's weight (between vsize*4 - 3 and vsize*4) */
weight: number;
/** The version */
version: number;
/** The lock time */
locktime: number;
vin: DecoderawtransactionVin[];
vout: DecoderawtransactionVout[];
}
/**
* Return a JSON object representing the serialized, hex-encoded transaction
*
*
* @param {string} hexstring The transaction hex string
* @param {boolean} iswitness Whether the transaction hex is a serialized witness transaction.
* If iswitness is not present, heuristic tests will be used in decoding.
* If true, only witness deserialization will be tried.
* If false, only non-witness deserialization will be tried.
* This boolean should reflect whether the transaction has inputs
* (e.g. fully valid, or on-chain transactions), if known by the caller.
*/
export const Decoderawtransaction = (
hexstring: string,
iswitness?: boolean
): Promise<DecoderawtransactionResult> => Do("Decoderawtransaction", hexstring, iswitness);
/////////////////////////////////////////
// RPC: decodescript
//
/**
* Result of a witness script public key wrapping this redeem script (not returned if the script is a
*
* P2SH or witness)
*/
export interface DecodescriptSegwit {
/** String representation of the script public key */
asm: string;
/** Hex string of the script public key */
hex: string;
/** The type of the script public key (e.g. witness_v0_keyhash or witness_v0_scripthash) */
type: string;
/** bitcoin address (only if a well-defined address exists) */
address?: string;
/**
* (DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required
* signatures
*/
reqSigs?: number;
/**
* (DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin
* addresses
*/
addresses?: string[];
/** address of the P2SH script wrapping this witness redeem script */
"p2sh-segwit": string;
}
export interface DecodescriptResult {
/** Script public key */
asm: string;
/**
* The output type (e.g. nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_scripthash,
* witness_v0_keyhash, witness_v1_taproot, witness_unknown)
*/
type: string;
/** bitcoin address (only if a well-defined address exists) */
address?: string;
/**
* (DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required
* signatures
*/
reqSigs?: number;
/**
* (DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin
* addresses
*/
addresses?: string[];
/**
* address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH)
*/
p2sh: string;
/**
* Result of a witness script public key wrapping this redeem script (not returned if the script
* is a P2SH or witness)
*/
segwit: DecodescriptSegwit;
}
/**
* Decode a hex-encoded script
*
*
* @param {string} hexstring the hex-encoded script
*/
export const Decodescript = (
hexstring: string
): Promise<DecodescriptResult> => Do("Decodescript", hexstring);
/////////////////////////////////////////
// RPC: deriveaddresses
//
/**
* Derives one or more addresses corresponding to an output descriptor
*
* Examples of output descriptors are:
* pkh(<pubkey>) P2PKH outputs for the given pubkey
* wpkh(<pubkey>) Native segwit P2PKH outputs for the given pubkey
* sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys
* raw(<hex script>) Outputs whose scriptPubKey equals the specified hex scripts
*
* In the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv
* optionally followed by one
* or more path elements separated by "/", where "h" represents a hardened child key.
* For more information on output descriptors, see the documentation in the doc/descriptors.md file.
*
* @param {string} descriptor The descriptor.
* @param {number | [number, number]} range If a ranged descriptor is used, this specifies the end or
* the
* range (in [begin,end] notation) to derive.
*/
export const Deriveaddresses = (
descriptor: string,
range?: number | [number, number]
): Promise<string[]> => Do("Deriveaddresses", descriptor, range);
/////////////////////////////////////////
// RPC: disconnectnode
//
/**
* Immediately disconnects from the specified peer node
*
*
* Strictly one out of 'address' and 'nodeid' can be provided to identify the node.
*
* To disconnect by nodeid, either set 'address' to the empty string, or call using the named 'nodeid'
* argument only.
*
* @param {string} address The IP address/port of the node
* @param {number} nodeid The node ID (see getpeerinfo for node IDs)
*/
export const Disconnectnode = (
address?: string,
nodeid?: number
): Promise<void> => Do("Disconnectnode", address, nodeid);
/////////////////////////////////////////
// RPC: dumpprivkey
//
/**
* Reveals the private key corresponding to 'address'
*
* Then the importprivkey can be used with this output
*
* @param {string} address The bitcoin address for the private key
*/
export const Dumpprivkey = (
address: string
): Promise<string> => Do("Dumpprivkey", address);
/////////////////////////////////////////
// RPC: dumptxoutset
//
export interface DumptxoutsetResult {
/** the number of coins written in the snapshot */
coins_written: number;
/** the hash of the base of the snapshot */
base_hash: string;
/** the height of the base of the snapshot */
base_height: number;
/** the absolute path that the snapshot was written to */
path: string;
}
/**
* Write the serialized UTXO set to disk
*
*/
export const Dumptxoutset = (
path: string
): Promise<DumptxoutsetResult> => Do("Dumptxoutset", path);
/////////////////////////////////////////
// RPC: dumpwallet
//
export interface DumpwalletResult {
/** The filename with full absolute path */
filename: string;
}
/**
* Dumps all wallet keys in a human-readable format to a server-side file
*
* This does not allow overwriting existing files.
* Imported scripts are included in the dumpfile, but corresponding BIP173 addresses, etc. may not be
* added automatically by importwallet.
* Note that if your wallet contains keys which are not derived from your HD seed (e.g. imported keys),
* these are not covered by
* only backing up the seed itself, and must be backed up too (e.g. ensure you back up the whole dumpfile).
*
* @param {string} filename The filename with path (absolute path recommended)
*/
export const Dumpwallet = (
filename: string
): Promise<DumpwalletResult> => Do("Dumpwallet", filename);
/////////////////////////////////////////
// RPC: echo
//
/**
* Simply echo back the input arguments
*
* This command is for testing.
*
* It will return an internal bug report when arg9='trigger_internal_bug' is passed.
*
* The difference between echo and echojson is that echojson has argument conversion enabled in the client-side
* table in bitcoin-cli and the GUI. There is no server-side difference.
*/
export const Echo = (
arg0?: string,
arg1?: string,
arg2?: string,
arg3?: string,
arg4?: string,
arg5?: string,
arg6?: string,
arg7?: string,
arg8?: string,
arg9?: string
): Promise<Dict<string | boolean | number | object>> => Do("Echo", arg0, arg1, arg2, arg3, arg4, arg5,
arg6, arg7, arg8, arg9);
/////////////////////////////////////////
// RPC: echoipc
//
/**
* Echo back the input argument, passing it through a spawned process in a multiprocess build
*
* This command is for testing.
*
* @param {string} arg The string to echo
*/
export const Echoipc = (
arg: string
): Promise<string> => Do("Echoipc", arg);
/////////////////////////////////////////
// RPC: echojson
//
/**
* Simply echo back the input arguments
*
* This command is for testing.
*
* It will return an internal bug report when arg9='trigger_internal_bug' is passed.
*
* The difference between echo and echojson is that echojson has argument conversion enabled in the client-side
* table in bitcoin-cli and the GUI. There is no server-side difference.
*/
export const Echojson = (
arg0?: string,
arg1?: string,
arg2?: string,
arg3?: string,
arg4?: string,
arg5?: string,
arg6?: string,
arg7?: string,
arg8?: string,
arg9?: string
): Promise<Dict<string | boolean | number | object>> => Do("Echojson", arg0, arg1, arg2, arg3, arg4,
arg5, arg6, arg7, arg8, arg9);
/////////////////////////////////////////
// RPC: encryptwallet
//
/**
* Encrypts the wallet with 'passphrase'
*
* This is for first time encryption.
* After this, any calls that interact with private keys such as sending or signing
* will require the passphrase to be set prior the making these calls.
* Use the walletpassphrase call for this, and then walletlock call.
* If the wallet is already encrypted, use the walletpassphrasechange call.
*
* @param {string} passphrase The pass phrase to encrypt the wallet with. It must be at least 1 character,
* but should be long.
*/
export const Encryptwallet = (
passphrase: string
): Promise<string> => Do("Encryptwallet", passphrase);
/////////////////////////////////////////
// RPC: estimaterawfee
//
/**
* information about the lowest range of feerates to succeed in meeting the threshold
*/
export interface EstimaterawfeeShortPass {
/** start of feerate range */
startrange: number;
/** end of feerate range */
endrange: number;
/**
* number of txs over history horizon in the feerate range that were confirmed within target
*/
withintarget: number;
/** number of txs over history horizon in the feerate range that were confirmed at any point */
totalconfirmed: number;
/**
* current number of txs in mempool in the feerate range unconfirmed for at least target blocks
*/
inmempool: number;
/**
* number of txs over history horizon in the feerate range that left mempool unconfirmed after target
*/
leftmempool: number;
}
/**
* estimate for short time horizon
*/
export interface EstimaterawfeeShort {
/** estimate fee rate in BTC/kB */
feerate?: number;
/** exponential decay (per block) for historical moving average of confirmation data */
decay: number;
/** The resolution of confirmation targets at this time horizon */
scale: number;
/** information about the lowest range of feerates to succeed in meeting the threshold */
pass?: EstimaterawfeeShortPass;
/** information about the highest range of feerates to fail to meet the threshold */
fail?: Dict<string | boolean | number | object>;
/** Errors encountered during processing (if there are any) */
errors?: string[];
}
/**
* Results are returned for any horizon which tracks blocks up to the confirmation target
*/
export interface EstimaterawfeeResult {
/** estimate for short time horizon */
short?: EstimaterawfeeShort;
/** estimate for medium time horizon */
medium?: Dict<string | boolean | number | object>;
/** estimate for long time horizon */
long?: Dict<string | boolean | number | object>;
}
/**
* WARNING: This interface is unstable and may disappear or change!
*
* WARNING: This is an advanced API call that is tightly coupled to the specific
* implementation of fee estimation. The parameters it can be called with
* and the results it returns will change if the internal implementation changes.
*
* Estimates the approximate fee per kilobyte needed for a transaction to begin
* confirmation within conf_target blocks if possible. Uses virtual transaction size as
* defined in BIP 141 (witness data is discounted).
*
* @param {number} confTarget Confirmation target in blocks (1 - 1008)
* @param {number} threshold The proportion of transactions in a given feerate range that must have been
* confirmed within conf_target in order to consider those feerates as high enough
* and
* proceed to check
* lower buckets.
*/
export const Estimaterawfee = (
confTarget: number,
threshold?: number
): Promise<EstimaterawfeeResult> => Do("Estimaterawfee", confTarget, threshold);
/////////////////////////////////////////
// RPC: estimatesmartfee
//
export interface EstimatesmartfeeResult {
/** estimate fee rate in BTC/kB (only present if no errors were encountered) */
feerate?: number;
/** Errors encountered during processing (if there are any) */
errors?: string[];
/**
* block number where estimate was found
* The request target will be clamped between 2 and the highest target
* fee estimation is able to return based on how long it has been running.
* An error is returned if not enough transactions and blocks
* have been observed to make an estimate for any number of blocks.
*/
blocks: number;
}
/**
* Estimates the approximate fee per kilobyte needed for a transaction to begin
*
* confirmation within conf_target blocks if possible and return the number of blocks
* for which the estimate is valid. Uses virtual transaction size as defined
* in BIP 141 (witness data is discounted).
*
* @param {number} confTarget Confirmation target in blocks (1 - 1008)
* @param {string} estimateMode The fee estimate mode.
* Whether to return a more conservative estimate which also satisfies
* a longer history. A conservative estimate potentially returns a
* higher feerate and is more likely to be sufficient for the desired
* target, but is not as responsive to short term drops in the
* prevailing fee market. Must be one of (case insensitive):
* "unset"
* "economical"
* "conservative"
*/
export const Estimatesmartfee = (
confTarget: number,
estimateMode?: string
): Promise<EstimatesmartfeeResult> => Do("Estimatesmartfee", confTarget, estimateMode);
/////////////////////////////////////////
// RPC: finalizepsbt
//
export interface FinalizepsbtResult {
/** The base64-encoded partially signed transaction if not extracted */
psbt: string;
/** The hex-encoded network transaction if extracted */
hex: string;
/** If the transaction has a complete set of signatures */
complete: boolean;
}
/**
* Finalize the inputs of a PSBT
*
* If the transaction is fully signed, it will produce a
* network serialized transaction which can be broadcast with sendrawtransaction. Otherwise a PSBT will
* be
* created which has the final_scriptSig and final_scriptWitness fields filled for inputs that are complete.
* Implements the Finalizer and Extractor roles.
*
* @param {string} psbt A base64 string of a PSBT
* @param {boolean} extract If true and the transaction is complete,
* extract and return the complete transaction in normal network serialization
* instead of the PSBT.
*/
export const Finalizepsbt = (
psbt: string,
extract?: boolean
): Promise<FinalizepsbtResult> => Do("Finalizepsbt", psbt, extract);
/////////////////////////////////////////
// RPC: fundrawtransaction
//
export interface FundrawtransactionResult {
/** The resulting raw transaction (hex-encoded string) */
hex: string;
/** Fee in BTC the resulting transaction pays */
fee: string;
/** The position of the added change output, or -1 */
changepos: number;
}
/**
* for backward compatibility: passing in a true instead of an object will result in {"includeWatching":true}
*/
export interface FundrawtransactionOptions {
/**
* For a transaction with existing inputs, automatically include more if they are not enough.
*/
add_inputs?: boolean;
/** The bitcoin address to receive the change */
changeAddress?: string;
/** The index of the change output */
changePosition?: number;
/**
* The output type to use. Only valid if changeAddress is not specified. Options are "legacy", "p2sh-segwit",
* and "bech32".
*/
change_type?: string;
/**
* Also select inputs which are watch only.
* Only solvable inputs can be used. Watch-only destinations are solvable if the public key and/or
* output script was imported,
* e.g. with 'importpubkey' or 'importmulti' with the 'pubkeys' or 'desc' field.
*/
includeWatching?: boolean;
/** Lock selected unspent outputs */
lockUnspents?: boolean;
/** Specify a fee rate in sat/vB. */
fee_rate?: number | string;
/** Specify a fee rate in BTC/kvB. */
feeRate?: number | string;
/**
* The integers.
* The fee will be equally deducted from the amount of each specified output.
* Those recipients will receive less bitcoins than you enter in their corresponding amount field.
* If no outputs are specified here, the sender pays the fee.
*/
subtractFeeFromOutputs?: number[];
/**
* Marks this transaction as BIP125 replaceable.
* Allows this transaction to be replaced by a transaction with higher fees
*/
replaceable?: boolean;
/** Confirmation target in blocks */
conf_target?: number;
/**
* The fee estimate mode, must be one of (case insensitive):
* "unset"
* "economical"
* "conservative"
*/
estimate_mode?: string;
}
/**
* If the transaction has no inputs, they will be automatically selected to meet its out value
*
* It will add at most one change output to the outputs.
* No existing outputs will be modified unless "subtractFeeFromOutputs" is specified.
* Note that inputs which were signed may need to be resigned after completion since in/outputs have
* been added.
* The inputs added will not be signed, use signrawtransactionwithkey
* or signrawtransactionwithwallet for that.
* Note that all existing inputs must have their previous output transaction be in the wallet.
* Note that all inputs selected must be of standard form and P2SH scripts must be
* in the wallet using importaddress or addmultisigaddress (to calculate fees).
* You can see whether this is the case by checking the "solvable" field in the listunspent output.
* Only pay-to-pubkey, multisig, and P2SH versions thereof are currently supported for watch-only
*
* @param {string} hexstring The hex string of the raw transaction
* @param {FundrawtransactionOptions} options for backward compatibility: passing in a true instead of
* an
* object will result in {"includeWatching":true}
* @param {boolean} iswitness Whether the transaction hex is a serialized witness transaction.
* If iswitness is not present, heuristic tests will be used in decoding.
* If true, only witness deserialization will be tried.
* If false, only non-witness deserialization will be tried.
* This boolean should reflect whether the transaction has inputs
* (e.g. fully valid, or on-chain transactions), if known by the caller.
*/
export const Fundrawtransaction = (
hexstring: string,
options?: FundrawtransactionOptions,
iswitness?: boolean
): Promise<FundrawtransactionResult> => Do("Fundrawtransaction", hexstring, options, iswitness);
/////////////////////////////////////////
// RPC: generate
//
/**
* has been replaced by the -generate cli option
*
* Refer to -help for more information.
*/
export const Generate = (): Promise<void> => Do("Generate");
/////////////////////////////////////////
// RPC: generateblock
//
export interface GenerateblockResult {
/** hash of generated block */
hash: string;
}
/**
* Mine a block with a set of ordered transactions immediately to a specified address or descriptor (before
*
* the RPC call returns)
*
* @param {string} output The address or descriptor to send the newly generated bitcoin to.
* @param {string[]} transactions An array of hex strings which are either txids or raw transactions.
* Txids must reference transactions currently in the mempool.
* All transactions must be valid and in valid order, otherwise the block will be rejected.
*/
export const Generateblock = (
output: string,
transactions: string[]
): Promise<GenerateblockResult> => Do("Generateblock", output, transactions);
/////////////////////////////////////////
// RPC: generatetoaddress
//
/**
* Mine blocks immediately to a specified address (before the RPC call returns)
*
* @param {number} nblocks How many blocks are generated immediately.
* @param {string} address The address to send the newly generated bitcoin to.
* @param {number} maxtries How many iterations to try.
*/
export const Generatetoaddress = (
nblocks: number,
address: string,
maxtries?: number
): Promise<string[]> => Do("Generatetoaddress", nblocks, address, maxtries);
/////////////////////////////////////////
// RPC: generatetodescriptor
//
/**
* Mine blocks immediately to a specified descriptor (before the RPC call returns)
*
* @param {number} numBlocks How many blocks are generated immediately.
* @param {string} descriptor The descriptor to send the newly generated bitcoin to.
* @param {number} maxtries How many iterations to try.
*/
export const Generatetodescriptor = (
numBlocks: number,
descriptor: string,
maxtries?: number
): Promise<string[]> => Do("Generatetodescriptor", numBlocks, descriptor, maxtries);
/////////////////////////////////////////
// RPC: getaddednodeinfo
//
export interface GetaddednodeinfoAddress {
/** The bitcoin server IP and port we're connected to */
address: string;
/** connection, inbound or outbound */
connected: string;
}
export interface GetaddednodeinfoResult {
/** The node IP address or name (as provided to addnode) */
addednode: string;
/** If connected */
connected: boolean;
/** Only when connected = true */
addresses: GetaddednodeinfoAddress[];
}
/**
* Returns information about the given added node, or all added nodes
*
* (note that onetry addnodes are not listed here)
*
* @param {string} node If provided, return information about this specific node, otherwise all nodes
* are
* returned.
*/
export const Getaddednodeinfo = (
node?: string
): Promise<GetaddednodeinfoResult[]> => Do("Getaddednodeinfo", node);
/////////////////////////////////////////
// RPC: getaddressesbylabel
//
/**
* json object with information about address
*/
export interface GetaddressesbylabelAddress {
/** Purpose of address ("send" for sending address, "receive" for receiving address) */
purpose: string;
}
/**
* Returns the list of addresses assigned the specified label
*
*
* @param {string} label The label.
*/
export const Getaddressesbylabel = (
label: string
): Promise<Dict<GetaddressesbylabelAddress>> => Do("Getaddressesbylabel", label);
/////////////////////////////////////////
// RPC: getaddressinfo
//
export interface GetaddressinfoResult {
/** The bitcoin address validated. */
address: string;
/** The hex-encoded scriptPubKey generated by the address. */
scriptPubKey: string;
/** If the address is yours. */
ismine: boolean;
/** If the address is watchonly. */
iswatchonly: boolean;
/**
* If we know how to spend coins sent to this address, ignoring the possible lack of private keys.
*/
solvable: boolean;
/** A descriptor for spending coins sent to this address (only when solvable). */
desc?: string;
/** The descriptor used to derive this address if this is a descriptor wallet */
parent_desc?: string;
/** If the key is a script. */
isscript: boolean;
/** If the address was used for change output. */
ischange: boolean;
/** If the address is a witness address. */
iswitness: boolean;
/** The version number of the witness program. */
witness_version?: number;
/** The hex value of the witness program. */
witness_program?: string;
/**
* The output script type. Only if isscript is true and the redeemscript is known. Possible
* types: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_keyhash,
* witness_v0_scripthash, witness_unknown.
*/
script?: string;
/** The redeemscript for the p2sh address. */
hex?: string;
/** Array of pubkeys associated with the known redeemscript (only if script is multisig). */
pubkeys?: string[];
/** The number of signatures required to spend multisig output (only if script is multisig). */
sigsrequired?: number;
/**
* The hex value of the raw public key for single-key addresses (possibly embedded in P2SH or P2WSH).
*/
pubkey?: string;
/** Information about the address embedded in P2SH or P2WSH, if relevant and known. */
embedded?: Dict<string | boolean | number | object>;
/** If the pubkey is compressed. */
iscompressed?: boolean;
/** The creation time of the key, if available, expressed in UNIX epoch time. */
timestamp?: number;
/** The HD keypath, if the key is HD and available. */
hdkeypath?: string;
/** The Hash160 of the HD seed. */
hdseedid?: string;
/** The fingerprint of the master key. */
hdmasterfingerprint?: string;
/**
* Array of labels associated with the address. Currently limited to one label but returned
* as an array to keep the API stable if multiple labels are enabled in the future.
*/
labels: string[];
}
/**
* Return information about the given bitcoin address
*
* Some of the information will only be present if the address is in the active wallet.
*
* @param {string} address The bitcoin address for which to get information.
*/
export const Getaddressinfo = (
address: string
): Promise<GetaddressinfoResult> => Do("Getaddressinfo", address);
/////////////////////////////////////////
// RPC: getbalance
//
/**
* Returns the total available balance
*
* The available balance is what the wallet considers currently spendable, and is
* thus affected by options which limit spendability such as -spendzeroconfchange.
*
* @param {string} dummy Remains for backward compatibility. Must be excluded or set to "*".
* @param {number} minconf Only include transactions confirmed at least this many times.
* @param {boolean} includeWatchonly Also include balance in watch-only addresses (see 'importaddress')
* @param {boolean} avoidReuse (only available if avoid_reuse wallet flag is set) Do not include balance
* in dirty outputs; addresses are considered dirty if they have previously been used in a transaction.
*/
export const Getbalance = (
dummy?: string,
minconf?: number,
includeWatchonly?: boolean,
avoidReuse?: boolean
): Promise<string> => Do("Getbalance", dummy, minconf, includeWatchonly, avoidReuse);
/////////////////////////////////////////
// RPC: getbalances
//
/**
* balances from outputs that the wallet can sign
*/
export interface GetbalancesMine {
/** trusted balance (outputs created by the wallet or confirmed outputs) */
trusted: string;
/** untrusted pending balance (outputs created by others that are in the mempool) */
untrusted_pending: string;
/** balance from immature coinbase outputs */
immature: string;
/**
* (only present if avoid_reuse is set) balance from coins sent to addresses that were previously
* spent from (potentially privacy violating)
*/
used: string;
}
/**
* watchonly balances (not present if wallet does not watch anything)
*/
export interface GetbalancesWatchonly {
/** trusted balance (outputs created by the wallet or confirmed outputs) */
trusted: string;
/** untrusted pending balance (outputs created by others that are in the mempool) */
untrusted_pending: string;
/** balance from immature coinbase outputs */
immature: string;
}
export interface GetbalancesResult {
/** balances from outputs that the wallet can sign */
mine: GetbalancesMine;
/** watchonly balances (not present if wallet does not watch anything) */
watchonly: GetbalancesWatchonly;
}
/**
* Returns an object with all balances in BTC
*
*/
export const Getbalances = (): Promise<GetbalancesResult> => Do("Getbalances");
/////////////////////////////////////////
// RPC: getbestblockhash
//
/**
* Returns the hash of the best (tip) block in the most-work fully-validated chain
*
*/
export const Getbestblockhash = (): Promise<string> => Do("Getbestblockhash");
/////////////////////////////////////////
// RPC: getblock
//
export interface GetblockAlt {
/** the block hash (same as provided) */
hash: string;
/** The number of confirmations, or -1 if the block is not on the main chain */
confirmations: number;
/** The block size */
size: number;
/** The block size excluding witness data */
strippedsize: number;
/** The block weight as defined in BIP 141 */
weight: number;
/** The block height or index */
height: number;
/** The block version */
version: number;
/** The block version formatted in hexadecimal */
versionHex: string;
/** The merkle root */
merkleroot: string;
/** The transaction ids */
tx: string[];
/** The block time expressed in UNIX epoch time */
time: number;
/** The median block time expressed in UNIX epoch time */
mediantime: number;
/** The nonce */
nonce: number;
/** The bits */
bits: string;
/** The difficulty */
difficulty: number;
/** Expected number of hashes required to produce the chain up to this block (in hex) */
chainwork: string;
/** The number of transactions in the block */
nTx: number;
/** The hash of the previous block (if available) */
previousblockhash?: string;
/** The hash of the next block (if available) */
nextblockhash?: string;
}
/**
* If verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'
*
* If verbosity is 1, returns an Object with information about block <hash>.
* If verbosity is 2, returns an Object with information about block <hash> and information about each
* transaction.
*
* @param {string} blockhash The block hash
* @param {number} verbosity 0 for hex-encoded data, 1 for a json object, and 2 for json object with
* transaction
* data
*/
export const Getblock = (
blockhash: string,
verbosity?: number
): Promise<string | GetblockAlt | {
tx: ({
/** The transaction fee in BTC, omitted if block undo data is not available */
fee: number;
} | Dict<string | boolean | number | object>)[];
} | Dict<string | boolean | number | object>> => Do("Getblock", blockhash, verbosity);
/////////////////////////////////////////
// RPC: getblockchaininfo
//
/**
* numeric statistics about BIP9 signalling for a softfork (only for "started" status)
*/
export interface GetblockchaininfoSoftforksXxxxBip9Statistics {
/** the length in blocks of the BIP9 signalling period */
period: number;
/** the number of blocks with the version bit set required to activate the feature */
threshold: number;
/** the number of blocks elapsed since the beginning of the current period */
elapsed: number;
/** the number of blocks with the version bit set in the current period */
count: number;
/**
* returns false if there are not enough blocks left in this period to pass activation threshold
*/
possible: boolean;
}
/**
* status of bip9 softforks (only for "bip9" type)
*/
export interface GetblockchaininfoSoftforksXxxxBip9 {
/** one of "defined", "started", "locked_in", "active", "failed" */
status: string;
/**
* the bit (0-28) in the block version field used to signal this softfork (only for "started" status)
*/
bit: number;
/** the minimum median time past of a block at which the bit gains its meaning */
start_time: number;
/**
* the median time past of a block at which the deployment is considered failed if not yet locked
* in
*/
timeout: number;
/** height of the first block to which the status applies */
since: number;
/** minimum height of blocks for which the rules may be enforced */
min_activation_height: number;
/** numeric statistics about BIP9 signalling for a softfork (only for "started" status) */
statistics: GetblockchaininfoSoftforksXxxxBip9Statistics;
}
/**
* name of the softfork
*/
export interface GetblockchaininfoSoftforksXxxx {
/** one of "buried", "bip9" */
type: string;
/** status of bip9 softforks (only for "bip9" type) */
bip9: GetblockchaininfoSoftforksXxxxBip9;
/**
* height of the first block which the rules are or will be enforced (only for "buried" type, or
* "bip9" type with "active" status)
*/
height: number;
/** true if the rules are enforced for the mempool and the next block */
active: boolean;
}
export interface GetblockchaininfoResult {
/** current network name (main, test, signet, regtest) */
chain: string;
/** the height of the most-work fully-validated chain. The genesis block has height 0 */
blocks: number;
/** the current number of headers we have validated */
headers: number;
/** the hash of the currently best block */
bestblockhash: string;
/** the current difficulty */
difficulty: number;
/** median time for the current best block */
mediantime: number;
/** estimate of verification progress [0..1] */
verificationprogress: number;
/** (debug information) estimate of whether this node is in Initial Block Download mode */
initialblockdownload: boolean;
/** total amount of work in active chain, in hexadecimal */
chainwork: string;
/** the estimated size of the block and undo files on disk */
size_on_disk: number;
/** if the blocks are subject to pruning */
pruned: boolean;
/** lowest-height complete block stored (only present if pruning is enabled) */
pruneheight: number;
/** whether automatic pruning is enabled (only present if pruning is enabled) */
automatic_pruning: boolean;
/** the target size used by pruning (only present if automatic pruning is enabled) */
prune_target_size: number;
/** status of softforks */
softforks: Dict<GetblockchaininfoSoftforksXxxx>;
/** any network and blockchain warnings */
warnings: string;
}
/**
* Returns an object containing various state info regarding blockchain processing
*
*/
export const Getblockchaininfo = (): Promise<GetblockchaininfoResult> => Do("Getblockchaininfo");
/////////////////////////////////////////
// RPC: getblockcount
//
/**
* Returns the height of the most-work fully-validated chain
*
* The genesis block has height 0.
*/
export const Getblockcount = (): Promise<number> => Do("Getblockcount");
/////////////////////////////////////////
// RPC: getblockfilter
//
export interface GetblockfilterResult {
/** the hex-encoded filter data */
filter: string;
/** the hex-encoded filter header */
header: string;
}
/**
* Retrieve a BIP 157 content filter for a particular block
*
*
* @param {string} blockhash The hash of the block
* @param {string} filtertype The type name of the filter
*/
export const Getblockfilter = (
blockhash: string,
filtertype?: string
): Promise<GetblockfilterResult> => Do("Getblockfilter", blockhash, filtertype);
/////////////////////////////////////////
// RPC: getblockhash
//
/**
* Returns hash of block in best-block-chain at height provided
*
*
* @param {number} height The height index
*/
export const Getblockhash = (
height: number
): Promise<string> => Do("Getblockhash", height);
/////////////////////////////////////////
// RPC: getblockheader
//
export interface GetblockheaderAlt {
/** the block hash (same as provided) */
hash: string;
/** The number of confirmations, or -1 if the block is not on the main chain */
confirmations: number;
/** The block height or index */
height: number;
/** The block version */
version: number;
/** The block version formatted in hexadecimal */
versionHex: string;
/** The merkle root */
merkleroot: string;
/** The block time expressed in UNIX epoch time */
time: number;
/** The median block time expressed in UNIX epoch time */
mediantime: number;
/** The nonce */
nonce: number;
/** The bits */
bits: string;
/** The difficulty */
difficulty: number;
/** Expected number of hashes required to produce the current chain */
chainwork: string;
/** The number of transactions in the block */
nTx: number;
/** The hash of the previous block (if available) */
previousblockhash?: string;
/** The hash of the next block (if available) */
nextblockhash?: string;
}
/**
* If verbose is false, returns a string that is serialized, hex-encoded data for blockheader 'hash'
*
* If verbose is true, returns an Object with information about blockheader <hash>.
*
* @param {string} blockhash The block hash
* @param {boolean} verbose true for a json object, false for the hex-encoded data
*/
export const Getblockheader = (
blockhash: string,
verbose?: boolean
): Promise<GetblockheaderAlt | string> => Do("Getblockheader", blockhash, verbose);
/////////////////////////////////////////
// RPC: getblockstats
//
/**
* Feerates at the 10th, 25th, 50th, 75th, and 90th percentile weight unit (in satoshis per virtual byte)
*/
export type GetblockstatsFeeratePercentile = [number, number, number, number, number];
export interface GetblockstatsResult {
/** Average fee in the block */
avgfee: number;
/** Average feerate (in satoshis per virtual byte) */
avgfeerate: number;
/** Average transaction size */
avgtxsize: number;
/** The block hash (to check for potential reorgs) */
blockhash: string;
/**
* Feerates at the 10th, 25th, 50th, 75th, and 90th percentile weight unit (in satoshis per virtual
* byte)
*/
feerate_percentiles: GetblockstatsFeeratePercentile;
/** The height of the block */
height: number;
/** The number of inputs (excluding coinbase) */
ins: number;
/** Maximum fee in the block */
maxfee: number;
/** Maximum feerate (in satoshis per virtual byte) */
maxfeerate: number;
/** Maximum transaction size */
maxtxsize: number;
/** Truncated median fee in the block */
medianfee: number;
/** The block median time past */
mediantime: number;
/** Truncated median transaction size */
mediantxsize: number;
/** Minimum fee in the block */
minfee: number;
/** Minimum feerate (in satoshis per virtual byte) */
minfeerate: number;
/** Minimum transaction size */
mintxsize: number;
/** The number of outputs */
outs: number;
/** The block subsidy */
subsidy: number;
/** Total size of all segwit transactions */
swtotal_size: number;
/** Total weight of all segwit transactions */
swtotal_weight: number;
/** The number of segwit transactions */
swtxs: number;
/** The block time */
time: number;
/** Total amount in all outputs (excluding coinbase and thus reward [ie subsidy + totalfee]) */
total_out: number;
/** Total size of all non-coinbase transactions */
total_size: number;
/** Total weight of all non-coinbase transactions */
total_weight: number;
/** The fee total */
totalfee: number;
/** The number of transactions (including coinbase) */
txs: number;
/** The increase/decrease in the number of unspent outputs */
utxo_increase: number;
/** The increase/decrease in size for the utxo index (not discounting op_return and similar) */
utxo_size_inc: number;
}
/**
* Compute per block statistics for a given window
*
* All amounts are in satoshis.
* It won't work for some heights with pruning.
*
* @param {number} hashOrHeight The block hash or height of the target block
* @param {string[]} stats Values to plot (see result below)
*/
export const Getblockstats = (
hashOrHeight: number,
stats?: string[]
): Promise<GetblockstatsResult> => Do("Getblockstats", hashOrHeight, stats);
/////////////////////////////////////////
// RPC: getblocktemplate
//
export interface GetblocktemplateTransaction {
/** transaction data encoded in hexadecimal (byte-for-byte) */
data: string;
/** transaction id encoded in little-endian hexadecimal */
txid: string;
/** hash encoded in little-endian hexadecimal (including witness data) */
hash: string;
/** array of numbers */
depends: number[];
/**
* difference in value between transaction inputs and outputs (in satoshis); for coinbase transactions,
* this is a negative Number of the total collected block fees (ie, not including the block subsidy);
* if key is not present, fee is unknown and clients MUST NOT assume there isn't one
*/
fee: number;
/**
* total SigOps cost, as counted for purposes of block limits; if key is not present, sigop cost
* is unknown and clients MUST NOT assume it is zero
*/
sigops: number;
/** total transaction weight, as counted for purposes of block limits */
weight: number;
}
export interface GetblocktemplateAlt {
/** The preferred block version */
version: number;
/** specific block rules that are to be enforced */
rules: string[];
/** set of pending, supported versionbit (BIP 9) softfork deployments */
vbavailable: Dict<number>;
/** bit mask of versionbits the server requires set in submissions */
vbrequired: number;
/** The hash of current highest block */
previousblockhash: string;
/** contents of non-coinbase transactions that should be included in the next block */
transactions: GetblocktemplateTransaction[];
/** data that should be included in the coinbase's scriptSig content */
coinbaseaux: Dict<string>;
/**
* maximum allowable input to coinbase transaction, including the generation award and transaction
* fees (in satoshis)
*/
coinbasevalue: number;
/** an id to include with a request to longpoll on an update to this template */
longpollid: string;
/** The hash target */
target: string;
/** The minimum timestamp appropriate for the next block time, expressed in UNIX epoch time */
mintime: number;
/** list of ways the block template may be changed */
mutable: string[];
/** A range of valid nonces */
noncerange: string;
/** limit of sigops in blocks */
sigoplimit: number;
/** limit of block size */
sizelimit: number;
/** limit of block weight */
weightlimit: number;
/** current timestamp in UNIX epoch time */
curtime: number;
/** compressed target of next block */
bits: string;
/** The height of the next block */
height: number;
/** a valid witness commitment for the unmodified block template */
default_witness_commitment?: string;
}
/**
* Format of the template
*/
export interface GetblocktemplateTemplateRequest {
/** This must be set to "template", "proposal" (see BIP 23), or omitted */
mode?: string;
/** A list of strings */
capabilities?: string[];
/** A list of strings */
rules: string[];
}
/**
* If the request parameters include a 'mode' key, that is used to explicitly select between the default
*
* 'template' request or a 'proposal'.
* It returns data needed to construct a block to work on.
* For full specification, see BIPs 22, 23, 9, and 145:
* https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki
* https://github.com/bitcoin/bips/blob/master/bip-0023.mediawiki
* https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes
* https://github.com/bitcoin/bips/blob/master/bip-0145.mediawiki
*
* @param {GetblocktemplateTemplateRequest} templateRequest Format of the template
*/
export const Getblocktemplate = (
templateRequest?: GetblocktemplateTemplateRequest
): Promise<void | string | GetblocktemplateAlt> => Do("Getblocktemplate", templateRequest);
/////////////////////////////////////////
// RPC: getchaintips
//
export interface GetchaintipsResult {
/** height of the chain tip */
height: number;
/** block hash of the tip */
hash: string;
/** zero for main chain, otherwise length of branch connecting the tip to the main chain */
branchlen: number;
/**
* status of the chain, "active" for the main chain
* Possible values for status:
* 1. "invalid" This branch contains at least one invalid block
* 2. "headers-only" Not all blocks for this branch are available, but the headers are
* valid
* 3. "valid-headers" All blocks are available for this branch, but they were never fully
* validated
* 4. "valid-fork" This branch is not part of the active chain, but is fully validated
* 5. "active" This is the tip of the active main chain, which is certainly valid
*/
status: string;
}
/**
* Return information about all known tips in the block tree, including the main chain as well as orphaned
*
* branches.
*/
export const Getchaintips = (): Promise<GetchaintipsResult[]> => Do("Getchaintips");
/////////////////////////////////////////
// RPC: getchaintxstats
//
export interface GetchaintxstatsResult {
/** The timestamp for the final block in the window, expressed in UNIX epoch time */
time: number;
/** The total number of transactions in the chain up to that point */
txcount: number;
/** The hash of the final block in the window */
window_final_block_hash: string;
/** The height of the final block in the window. */
window_final_block_height: number;
/** Size of the window in number of blocks */
window_block_count: number;
/** The number of transactions in the window. Only returned if "window_block_count" is > 0 */
window_tx_count?: number;
/** The elapsed time in the window in seconds. Only returned if "window_block_count" is > 0 */
window_interval?: number;
/**
* The average rate of transactions per second in the window. Only returned if "window_interval"
* is > 0
*/
txrate?: number;
}
/**
* Compute statistics about the total number and rate of transactions in the chain
*
*
* @param {number} nblocks Size of the window in number of blocks
* @param {string} blockhash The hash of the block that ends the window.
*/
export const Getchaintxstats = (
nblocks?: number,
blockhash?: string
): Promise<GetchaintxstatsResult> => Do("Getchaintxstats", nblocks, blockhash);
/////////////////////////////////////////
// RPC: getconnectioncount
//
/**
* Returns the number of connections to other nodes
*
*/
export const Getconnectioncount = (): Promise<number> => Do("Getconnectioncount");
/////////////////////////////////////////
// RPC: getdescriptorinfo
//
export interface GetdescriptorinfoResult {
/** The descriptor in canonical form, without private keys */
descriptor: string;
/** The checksum for the input descriptor */
checksum: string;
/** Whether the descriptor is ranged */
isrange: boolean;
/** Whether the descriptor is solvable */
issolvable: boolean;
/** Whether the input descriptor contained at least one private key */
hasprivatekeys: boolean;
}
/**
* Analyses a descriptor
*
*
* @param {string} descriptor The descriptor.
*/
export const Getdescriptorinfo = (
descriptor: string
): Promise<GetdescriptorinfoResult> => Do("Getdescriptorinfo", descriptor);
/////////////////////////////////////////
// RPC: getdifficulty
//
/**
* Returns the proof-of-work difficulty as a multiple of the minimum difficulty
*
*/
export const Getdifficulty = (): Promise<number> => Do("Getdifficulty");
/////////////////////////////////////////
// RPC: getindexinfo
//
/**
* The name of the index
*/
export interface GetindexinfoName {
/** Whether the index is synced or not */
synced: boolean;
/** The block height to which the index is synced */
best_block_height: number;
}
export interface GetindexinfoResult {
/** The name of the index */
name: GetindexinfoName;
}
/**
* Returns the status of one or all available indices currently running in the node
*
*
* @param {string} indexName Filter results for an index with a specific name.
*/
export const Getindexinfo = (
indexName?: string
): Promise<GetindexinfoResult> => Do("Getindexinfo", indexName);
/////////////////////////////////////////
// RPC: getmemoryinfo
//
/**
* Information about locked memory manager
*/
export interface GetmemoryinfoLocked {
/** Number of bytes used */
used: number;
/** Number of bytes available in current arenas */
free: number;
/** Total number of bytes managed */
total: number;
/**
* Amount of bytes that succeeded locking. If this number is smaller than total, locking pages failed
* at some point and key data could be swapped to disk.
*/
locked: number;
/** Number allocated chunks */
chunks_used: number;
/** Number unused chunks */
chunks_free: number;
}
export interface GetmemoryinfoAlt {
/** Information about locked memory manager */
locked: GetmemoryinfoLocked;
}
/**
* Returns an object containing information about memory usage
*
*
* @param {string} mode determines what kind of information is returned.
* - "stats" returns general statistics about memory usage in the daemon.
* - "mallocinfo" returns an XML string describing low-level heap state (only available if compiled
* with glibc 2.10+).
*/
export const Getmemoryinfo = (
mode?: string
): Promise<GetmemoryinfoAlt | string> => Do("Getmemoryinfo", mode);
/////////////////////////////////////////
// RPC: getmempoolancestors
//
export interface GetmempoolancestorsTransactionidFees {
/** transaction fee in BTC */
base: string;
/** transaction fee with fee deltas used for mining priority in BTC */
modified: string;
/** modified fees (see above) of in-mempool ancestors (including this one) in BTC */
ancestor: string;
/** modified fees (see above) of in-mempool descendants (including this one) in BTC */
descendant: string;
}
export interface GetmempoolancestorsTransactionid {
/**
* virtual transaction size as defined in BIP 141. This is different from actual serialized size
* for witness transactions as witness data is discounted.
*/
vsize: number;
/** transaction weight as defined in BIP 141. */
weight: number;
/** transaction fee in BTC (DEPRECATED) */
fee: string;
/** transaction fee with fee deltas used for mining priority (DEPRECATED) */
modifiedfee: string;
/** local time transaction entered pool in seconds since 1 Jan 1970 GMT */
time: number;
/** block height when transaction entered pool */
height: number;
/** number of in-mempool descendant transactions (including this one) */
descendantcount: number;
/** virtual transaction size of in-mempool descendants (including this one) */
descendantsize: number;
/** modified fees (see above) of in-mempool descendants (including this one) (DEPRECATED) */
descendantfees: string;
/** number of in-mempool ancestor transactions (including this one) */
ancestorcount: number;
/** virtual transaction size of in-mempool ancestors (including this one) */
ancestorsize: number;
/** modified fees (see above) of in-mempool ancestors (including this one) (DEPRECATED) */
ancestorfees: string;
/** hash of serialized transaction, including witness data */
wtxid: string;
fees: GetmempoolancestorsTransactionidFees;
/** unconfirmed transactions used as inputs for this transaction */
depends: string[];
/** unconfirmed transactions spending outputs from this transaction */
spentby: string[];
/** Whether this transaction could be replaced due to BIP125 (replace-by-fee) */
"bip125-replaceable": boolean;
/**
* Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by any
* peers)
*/
unbroadcast: boolean;
}
/**
* If txid is in the mempool, returns all in-mempool ancestors
*
*
* @param {string} txid The transaction id (must be in mempool)
* @param {boolean} verbose True for a json object, false for array of transaction ids
*/
export const Getmempoolancestors = (
txid: string,
verbose?: boolean
): Promise<string[] | Dict<GetmempoolancestorsTransactionid>> => Do("Getmempoolancestors", txid, verbose);
/////////////////////////////////////////
// RPC: getmempooldescendants
//
export interface GetmempooldescendantsTransactionidFees {
/** transaction fee in BTC */
base: string;
/** transaction fee with fee deltas used for mining priority in BTC */
modified: string;
/** modified fees (see above) of in-mempool ancestors (including this one) in BTC */
ancestor: string;
/** modified fees (see above) of in-mempool descendants (including this one) in BTC */
descendant: string;
}
export interface GetmempooldescendantsTransactionid {
/**
* virtual transaction size as defined in BIP 141. This is different from actual serialized size
* for witness transactions as witness data is discounted.
*/
vsize: number;
/** transaction weight as defined in BIP 141. */
weight: number;
/** transaction fee in BTC (DEPRECATED) */
fee: string;
/** transaction fee with fee deltas used for mining priority (DEPRECATED) */
modifiedfee: string;
/** local time transaction entered pool in seconds since 1 Jan 1970 GMT */
time: number;
/** block height when transaction entered pool */
height: number;
/** number of in-mempool descendant transactions (including this one) */
descendantcount: number;
/** virtual transaction size of in-mempool descendants (including this one) */
descendantsize: number;
/** modified fees (see above) of in-mempool descendants (including this one) (DEPRECATED) */
descendantfees: string;
/** number of in-mempool ancestor transactions (including this one) */
ancestorcount: number;
/** virtual transaction size of in-mempool ancestors (including this one) */
ancestorsize: number;
/** modified fees (see above) of in-mempool ancestors (including this one) (DEPRECATED) */
ancestorfees: string;
/** hash of serialized transaction, including witness data */
wtxid: string;
fees: GetmempooldescendantsTransactionidFees;
/** unconfirmed transactions used as inputs for this transaction */
depends: string[];
/** unconfirmed transactions spending outputs from this transaction */
spentby: string[];
/** Whether this transaction could be replaced due to BIP125 (replace-by-fee) */
"bip125-replaceable": boolean;
/**
* Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by any
* peers)
*/
unbroadcast: boolean;
}
/**
* If txid is in the mempool, returns all in-mempool descendants
*
*
* @param {string} txid The transaction id (must be in mempool)
* @param {boolean} verbose True for a json object, false for array of transaction ids
*/
export const Getmempooldescendants = (
txid: string,
verbose?: boolean
): Promise<string[] | Dict<GetmempooldescendantsTransactionid>> => Do("Getmempooldescendants", txid,
verbose);
/////////////////////////////////////////
// RPC: getmempoolentry
//
export interface GetmempoolentryFees {
/** transaction fee in BTC */
base: string;
/** transaction fee with fee deltas used for mining priority in BTC */
modified: string;
/** modified fees (see above) of in-mempool ancestors (including this one) in BTC */
ancestor: string;
/** modified fees (see above) of in-mempool descendants (including this one) in BTC */
descendant: string;
}
export interface GetmempoolentryResult {
/**
* virtual transaction size as defined in BIP 141. This is different from actual serialized size
* for witness transactions as witness data is discounted.
*/
vsize: number;
/** transaction weight as defined in BIP 141. */
weight: number;
/** transaction fee in BTC (DEPRECATED) */
fee: string;
/** transaction fee with fee deltas used for mining priority (DEPRECATED) */
modifiedfee: string;
/** local time transaction entered pool in seconds since 1 Jan 1970 GMT */
time: number;
/** block height when transaction entered pool */
height: number;
/** number of in-mempool descendant transactions (including this one) */
descendantcount: number;
/** virtual transaction size of in-mempool descendants (including this one) */
descendantsize: number;
/** modified fees (see above) of in-mempool descendants (including this one) (DEPRECATED) */
descendantfees: string;
/** number of in-mempool ancestor transactions (including this one) */
ancestorcount: number;
/** virtual transaction size of in-mempool ancestors (including this one) */
ancestorsize: number;
/** modified fees (see above) of in-mempool ancestors (including this one) (DEPRECATED) */
ancestorfees: string;
/** hash of serialized transaction, including witness data */
wtxid: string;
fees: GetmempoolentryFees;
/** unconfirmed transactions used as inputs for this transaction */
depends: string[];
/** unconfirmed transactions spending outputs from this transaction */
spentby: string[];
/** Whether this transaction could be replaced due to BIP125 (replace-by-fee) */
"bip125-replaceable": boolean;
/**
* Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by any
* peers)
*/
unbroadcast: boolean;
}
/**
* Returns mempool data for given transaction
*
* @param {string} txid The transaction id (must be in mempool)
*/
export const Getmempoolentry = (
txid: string
): Promise<GetmempoolentryResult> => Do("Getmempoolentry", txid);
/////////////////////////////////////////
// RPC: getmempoolinfo
//
export interface GetmempoolinfoResult {
/** True if the mempool is fully loaded */
loaded: boolean;
/** Current tx count */
size: number;
/**
* Sum of all virtual transaction sizes as defined in BIP 141. Differs from actual serialized size
* because witness data is discounted
*/
bytes: number;
/** Total memory usage for the mempool */
usage: number;
/** Total fees for the mempool in BTC, ignoring modified fees through prioritizetransaction */
total_fee: string;
/** Maximum memory usage for the mempool */
maxmempool: number;
/**
* Minimum fee rate in BTC/kB for tx to be accepted. Is the maximum of minrelaytxfee and minimum
* mempool fee
*/
mempoolminfee: string;
/** Current minimum relay fee for transactions */
minrelaytxfee: string;
/** Current number of transactions that haven't passed initial broadcast yet */
unbroadcastcount: number;
}
/**
* Returns details on the active state of the TX memory pool
*
*/
export const Getmempoolinfo = (): Promise<GetmempoolinfoResult> => Do("Getmempoolinfo");
/////////////////////////////////////////
// RPC: getmininginfo
//
export interface GetmininginfoResult {
/** The current block */
blocks: number;
/**
* The block weight of the last assembled block (only present if a block was ever assembled)
*/
currentblockweight?: number;
/**
* The number of block transactions of the last assembled block (only present if a block was ever
* assembled)
*/
currentblocktx?: number;
/** The current difficulty */
difficulty: number;
/** The network hashes per second */
networkhashps: number;
/** The size of the mempool */
pooledtx: number;
/** current network name (main, test, signet, regtest) */
chain: string;
/** any network and blockchain warnings */
warnings: string;
}
/**
* Returns a json object containing mining-related information
*/
export const Getmininginfo = (): Promise<GetmininginfoResult> => Do("Getmininginfo");
/////////////////////////////////////////
// RPC: getnettotals
//
export interface GetnettotalsUploadtarget {
/** Length of the measuring timeframe in seconds */
timeframe: number;
/** Target in bytes */
target: number;
/** True if target is reached */
target_reached: boolean;
/** True if serving historical blocks */
serve_historical_blocks: boolean;
/** Bytes left in current time cycle */
bytes_left_in_cycle: number;
/** Seconds left in current time cycle */
time_left_in_cycle: number;
}
export interface GetnettotalsResult {
/** Total bytes received */
totalbytesrecv: number;
/** Total bytes sent */
totalbytessent: number;
/** Current UNIX epoch time in milliseconds */
timemillis: number;
uploadtarget: GetnettotalsUploadtarget;
}
/**
* Returns information about network traffic, including bytes in, bytes out,
*
* and current time.
*/
export const Getnettotals = (): Promise<GetnettotalsResult> => Do("Getnettotals");
/////////////////////////////////////////
// RPC: getnetworkhashps
//
/**
* Returns the estimated network hashes per second based on the last n blocks
*
* Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.
* Pass in [height] to estimate the network speed at the time when a certain block was found.
*
* @param {number} nblocks The number of blocks, or -1 for blocks since last difficulty change.
* @param {number} height To estimate at the time of the given height.
*/
export const Getnetworkhashps = (
nblocks?: number,
height?: number
): Promise<number> => Do("Getnetworkhashps", nblocks, height);
/////////////////////////////////////////
// RPC: getnetworkinfo
//
export interface GetnetworkinfoNetwork {
/** network (ipv4, ipv6, onion, i2p) */
name: string;
/** is the network limited using -onlynet? */
limited: boolean;
/** is the network reachable? */
reachable: boolean;
/** ("host:port") the proxy that is used for this network, or empty if none */
proxy: string;
/** Whether randomized credentials are used */
proxy_randomize_credentials: boolean;
}
export interface GetnetworkinfoLocaladdress {
/** network address */
address: string;
/** network port */
port: number;
/** relative score */
score: number;
}
export interface GetnetworkinfoResult {
/** the server version */
version: number;
/** the server subversion string */
subversion: string;
/** the protocol version */
protocolversion: number;
/** the services we offer to the network */
localservices: string;
/** the services we offer to the network, in human-readable form */
localservicesnames: string[];
/** true if transaction relay is requested from peers */
localrelay: boolean;
/** the time offset */
timeoffset: number;
/** the total number of connections */
connections: number;
/** the number of inbound connections */
connections_in: number;
/** the number of outbound connections */
connections_out: number;
/** whether p2p networking is enabled */
networkactive: boolean;
/** information per network */
networks: GetnetworkinfoNetwork[];
/** minimum relay fee for transactions in BTC/kB */
relayfee: number;
/** minimum fee increment for mempool limiting or BIP 125 replacement in BTC/kB */
incrementalfee: number;
/** list of local addresses */
localaddresses: GetnetworkinfoLocaladdress[];
/** any network and blockchain warnings */
warnings: string;
}
/**
* Returns an object containing various state info regarding P2P networking
*
*/
export const Getnetworkinfo = (): Promise<GetnetworkinfoResult> => Do("Getnetworkinfo");
/////////////////////////////////////////
// RPC: getnewaddress
//
/**
* Returns a new Bitcoin address for receiving payments
*
* If 'label' is specified, it is added to the address book
* so payments received with the address will be associated with 'label'.
*
* @param {string} label The label name for the address to be linked to. It can also be set to the empty
* string "" to represent the default label. The label does not need to exist, it will be created
* if
* there is no label by the given name.
* @param {string} addressType The address type to use. Options are "legacy", "p2sh-segwit", and "bech32".
*/
export const Getnewaddress = (
label?: string,
addressType?: string
): Promise<string> => Do("Getnewaddress", label, addressType);
/////////////////////////////////////////
// RPC: getnodeaddresses
//
export interface GetnodeaddressesResult {
/** The UNIX epoch time when the node was last seen */
time: number;
/** The services offered by the node */
services: number;
/** The address of the node */
address: string;
/** The port number of the node */
port: number;
/** The network (ipv4, ipv6, onion, i2p) the node connected through */
network: string;
}
/**
* Return known addresses, which can potentially be used to find new nodes in the network
*
*
* @param {number} count The maximum number of addresses to return. Specify 0 to return all known addresses.
*/
export const Getnodeaddresses = (
count?: number
): Promise<GetnodeaddressesResult[]> => Do("Getnodeaddresses", count);
/////////////////////////////////////////
// RPC: getpeerinfo
//
export interface GetpeerinfoResult {
/** Peer index */
id: number;
/** (host:port) The IP address and port of the peer */
addr: string;
/** (ip:port) Bind address of the connection to the peer */
addrbind: string;
/** (ip:port) Local address as reported by the peer */
addrlocal: string;
/** Network (ipv4, ipv6, onion, i2p, not_publicly_routable) */
network: string;
/**
* The AS in the BGP route to the peer used for diversifying
* peer selection (only available if the asmap config flag is set)
*/
mapped_as: number;
/** The services offered */
services: string;
/** the services offered, in human-readable form */
servicesnames: string[];
/** Whether peer has asked us to relay transactions to it */
relaytxes: boolean;
/** The UNIX epoch time of the last send */
lastsend: number;
/** The UNIX epoch time of the last receive */
lastrecv: number;
/** The UNIX epoch time of the last valid transaction received from this peer */
last_transaction: number;
/** The UNIX epoch time of the last block received from this peer */
last_block: number;
/** The total bytes sent */
bytessent: number;
/** The total bytes received */
bytesrecv: number;
/** The UNIX epoch time of the connection */
conntime: number;
/** The time offset in seconds */
timeoffset: number;
/** ping time (if available) */
pingtime: number;
/** minimum observed ping time (if any at all) */
minping: number;
/** ping wait (if non-zero) */
pingwait: number;
/** The peer version, such as 70001 */
version: number;
/** The string version */
subver: string;
/** Inbound (true) or Outbound (false) */
inbound: boolean;
/** Whether we selected peer as (compact blocks) high-bandwidth peer */
bip152_hb_to: boolean;
/** Whether peer selected us as (compact blocks) high-bandwidth peer */
bip152_hb_from: boolean;
/** The starting height (block) of the peer */
startingheight: number;
/** The last header we have in common with this peer */
synced_headers: number;
/** The last block we have in common with this peer */
synced_blocks: number;
inflight: number[];
/** Any special permissions that have been granted to this peer */
permissions: string[];
/** The minimum fee rate for transactions this peer accepts */
minfeefilter: number;
bytessent_per_msg: Dict<number>;
bytesrecv_per_msg: Dict<number>;
/**
* Type of connection:
* outbound-full-relay (default automatic connections),
* block-relay-only (does not relay transactions or addresses),
* inbound (initiated by the peer),
* manual (added via addnode RPC or -addnode/-connect configuration options),
* addr-fetch (short-lived automatic connection for soliciting addresses),
* feeler (short-lived automatic connection for testing addresses).
* Please note this output is unlikely to be stable in upcoming releases as we iterate to
* best capture connection behaviors.
*/
connection_type: string;
}
/**
* Returns data about each connected network node as a json array of objects
*
*/
export const Getpeerinfo = (): Promise<GetpeerinfoResult[]> => Do("Getpeerinfo");
/////////////////////////////////////////
// RPC: getrawchangeaddress
//
/**
* Returns a new Bitcoin address, for receiving change
*
* This is for use with raw transactions, NOT normal use.
*
* @param {string} addressType The address type to use. Options are "legacy", "p2sh-segwit", and "bech32".
*/
export const Getrawchangeaddress = (
addressType?: string
): Promise<string> => Do("Getrawchangeaddress", addressType);
/////////////////////////////////////////
// RPC: getrawmempool
//
export interface GetrawmempoolTransactionidFees {
/** transaction fee in BTC */
base: string;
/** transaction fee with fee deltas used for mining priority in BTC */
modified: string;
/** modified fees (see above) of in-mempool ancestors (including this one) in BTC */
ancestor: string;
/** modified fees (see above) of in-mempool descendants (including this one) in BTC */
descendant: string;
}
export interface GetrawmempoolTransactionid {
/**
* virtual transaction size as defined in BIP 141. This is different from actual serialized size
* for witness transactions as witness data is discounted.
*/
vsize: number;
/** transaction weight as defined in BIP 141. */
weight: number;
/** transaction fee in BTC (DEPRECATED) */
fee: string;
/** transaction fee with fee deltas used for mining priority (DEPRECATED) */
modifiedfee: string;
/** local time transaction entered pool in seconds since 1 Jan 1970 GMT */
time: number;
/** block height when transaction entered pool */
height: number;
/** number of in-mempool descendant transactions (including this one) */
descendantcount: number;
/** virtual transaction size of in-mempool descendants (including this one) */
descendantsize: number;
/** modified fees (see above) of in-mempool descendants (including this one) (DEPRECATED) */
descendantfees: string;
/** number of in-mempool ancestor transactions (including this one) */
ancestorcount: number;
/** virtual transaction size of in-mempool ancestors (including this one) */
ancestorsize: number;
/** modified fees (see above) of in-mempool ancestors (including this one) (DEPRECATED) */
ancestorfees: string;
/** hash of serialized transaction, including witness data */
wtxid: string;
fees: GetrawmempoolTransactionidFees;
/** unconfirmed transactions used as inputs for this transaction */
depends: string[];
/** unconfirmed transactions spending outputs from this transaction */
spentby: string[];
/** Whether this transaction could be replaced due to BIP125 (replace-by-fee) */
"bip125-replaceable": boolean;
/**
* Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by any
* peers)
*/
unbroadcast: boolean;
}
export interface GetrawmempoolAlt {
txids: string[];
/** The mempool sequence value. */
mempool_sequence: number;
}
/**
* Returns all transaction ids in memory pool as a json array of string transaction ids
*
*
* Hint: use getmempoolentry to fetch a specific transaction from the mempool.
*
* @param {boolean} verbose True for a json object, false for array of transaction ids
* @param {boolean} mempoolSequence If verbose=false, returns a json object with transaction list and
* mempool
* sequence number attached.
*/
export const Getrawmempool = (
verbose?: boolean,
mempoolSequence?: boolean
): Promise<string[] | Dict<GetrawmempoolTransactionid> | GetrawmempoolAlt> => Do("Getrawmempool", verbose,
mempoolSequence);
/////////////////////////////////////////
// RPC: getrawtransaction
//
/**
* The script
*/
export interface GetrawtransactionVinScriptSig {
/** asm */
asm: string;
/** hex */
hex: string;
}
export interface GetrawtransactionVin {
/** The transaction id */
txid: string;
/** The output number */
vout: number;
/** The script */
scriptSig: GetrawtransactionVinScriptSig;
/** The script sequence number */
sequence: number;
txinwitness: string[];
}
export interface GetrawtransactionVoutScriptPubKey {
/** the asm */
asm: string;
/** the hex */
hex: string;
/**
* (DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required
* signatures
*/
reqSigs?: number;
/** The type, eg 'pubkeyhash' */
type: string;
/** bitcoin address (only if a well-defined address exists) */
address?: string;
/**
* (DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin
* addresses
*/
addresses?: string[];
}
export interface GetrawtransactionVout {
/** The value in BTC */
value: number;
/** index */
n: number;
scriptPubKey: GetrawtransactionVoutScriptPubKey;
}
export interface GetrawtransactionAlt {
/**
* Whether specified block is in the active chain or not (only present with explicit "blockhash"
* argument)
*/
in_active_chain: boolean;
/** The serialized, hex-encoded data for 'txid' */
hex: string;
/** The transaction id (same as provided) */
txid: string;
/** The transaction hash (differs from txid for witness transactions) */
hash: string;
/** The serialized transaction size */
size: number;
/** The virtual transaction size (differs from size for witness transactions) */
vsize: number;
/** The transaction's weight (between vsize*4-3 and vsize*4) */
weight: number;
/** The version */
version: number;
/** The lock time */
locktime: number;
vin: GetrawtransactionVin[];
vout: GetrawtransactionVout[];
/** the block hash */
blockhash: string;
/** The confirmations */
confirmations: number;
/** The block time expressed in UNIX epoch time */
blocktime: number;
/** Same as "blocktime" */
time: number;
}
/**
* Return the raw transaction data
*
*
* By default this function only works for mempool transactions. When called with a blockhash
* argument, getrawtransaction will return the transaction if the specified block is available and
* the transaction is found in that block. When called without a blockhash argument, getrawtransaction
* will return the transaction if it is in the mempool, or if -txindex is enabled and the transaction
* is in a block in the blockchain.
*
* Hint: Use gettransaction for wallet transactions.
*
* If verbose is 'true', returns an Object with information about 'txid'.
* If verbose is 'false' or omitted, returns a string that is serialized, hex-encoded data for 'txid'.
*
* @param {string} txid The transaction id
* @param {boolean} verbose If false, return a string, otherwise return a json object
* @param {string} blockhash The block in which to look for the transaction
*/
export const Getrawtransaction = (
txid: string,
verbose?: boolean,
blockhash?: string
): Promise<string | GetrawtransactionAlt> => Do("Getrawtransaction", txid, verbose, blockhash);
/////////////////////////////////////////
// RPC: getreceivedbyaddress
//
/**
* Returns the total amount received by the given address in transactions with at least minconf confirmations
*
*
* @param {string} address The bitcoin address for transactions.
* @param {number} minconf Only include transactions confirmed at least this many times.
*/
export const Getreceivedbyaddress = (
address: string,
minconf?: number
): Promise<string> => Do("Getreceivedbyaddress", address, minconf);
/////////////////////////////////////////
// RPC: getreceivedbylabel
//
/**
* Returns the total amount received by addresses with <label> in transactions with at least [minconf]
*
* confirmations.
*
* @param {string} label The selected label, may be the default label using "".
* @param {number} minconf Only include transactions confirmed at least this many times.
*/
export const Getreceivedbylabel = (
label: string,
minconf?: number
): Promise<string> => Do("Getreceivedbylabel", label, minconf);
/////////////////////////////////////////
// RPC: getrpcinfo
//
/**
* Information about an active command
*/
export interface GetrpcinfoActiveCommand {
/** The name of the RPC command */
method: string;
/** The running time in microseconds */
duration: number;
}
export interface GetrpcinfoResult {
/** All active commands */
active_commands: GetrpcinfoActiveCommand[];
/** The complete file path to the debug log */
logpath: string;
}
/**
* Returns details of the RPC server
*
*/
export const Getrpcinfo = (): Promise<GetrpcinfoResult> => Do("Getrpcinfo");
/////////////////////////////////////////
// RPC: gettransaction
//
export interface GettransactionDetail {
/** Only returns true if imported addresses were involved in transaction. */
involvesWatchonly: boolean;
/** The bitcoin address involved in the transaction. */
address: string;
/**
* The transaction category.
* "send" Transactions sent.
* "receive" Non-coinbase transactions received.
* "generate" Coinbase transactions received with more than 100 confirmations.
* "immature" Coinbase transactions received with 100 or fewer confirmations.
* "orphan" Orphaned coinbase transactions received.
*/
category: string;
/** The amount in BTC */
amount: string;
/** A comment for the address/transaction, if any */
label: string;
/** the vout value */
vout: number;
/**
* The amount of the fee in BTC. This is negative and only available for the
* 'send' category of transactions.
*/
fee: string;
/**
* 'true' if the transaction has been abandoned (inputs are respendable). Only available for the
* 'send' category of transactions.
*/
abandoned: boolean;
}
export interface GettransactionResult {
/** The amount in BTC */
amount: string;
/**
* The amount of the fee in BTC. This is negative and only available for the
* 'send' category of transactions.
*/
fee: string;
/**
* The number of confirmations for the transaction. Negative confirmations means the
* transaction conflicted that many blocks ago.
*/
confirmations: number;
/** Only present if transaction only input is a coinbase one. */
generated: boolean;
/** Only present if we consider transaction to be trusted and so safe to spend from. */
trusted: boolean;
/** The block hash containing the transaction. */
blockhash: string;
/** The block height containing the transaction. */
blockheight: number;
/** The index of the transaction in the block that includes it. */
blockindex: number;
/** The block time expressed in UNIX epoch time. */
blocktime: number;
/** The transaction id. */
txid: string;
/** Conflicting transaction ids. */
walletconflicts: string[];
/** The transaction time expressed in UNIX epoch time. */
time: number;
/** The time received expressed in UNIX epoch time. */
timereceived: number;
/** If a comment is associated with the transaction, only present if not empty. */
comment: string;
/**
* ("yes|no|unknown") Whether this transaction could be replaced due to BIP125 (replace-by-fee);
* may be unknown for unconfirmed transactions not in the mempool
*/
"bip125-replaceable": string;
details: GettransactionDetail[];
/** Raw data for transaction */
hex: string;
/** Optional, the decoded transaction (only present when `verbose` is passed) */
decoded: Dict<string | boolean | number | object>;
}
/**
* Get detailed information about in-wallet transaction <txid>
*
* @param {string} txid The transaction id
* @param {boolean} includeWatchonly Whether to include watch-only addresses in balance calculation and
* details[]
* @param {boolean} verbose Whether to include a `decoded` field containing the decoded transaction (equivalent
* to RPC decoderawtransaction)
*/
export const Gettransaction = (
txid: string,
includeWatchonly?: boolean,
verbose?: boolean
): Promise<GettransactionResult> => Do("Gettransaction", txid, includeWatchonly, verbose);
/////////////////////////////////////////
// RPC: gettxout
//
export interface GettxoutScriptPubKey {
asm: string;
hex: string;
/**
* (DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required
* signatures
*/
reqSigs?: number;
/** The type, eg pubkeyhash */
type: string;
/** bitcoin address (only if a well-defined address exists) */
address?: string;
/**
* (DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin
* addresses
*/
addresses?: string[];
}
export interface GettxoutAlt {
/** The hash of the block at the tip of the chain */
bestblock: string;
/** The number of confirmations */
confirmations: number;
/** The transaction value in BTC */
value: string;
scriptPubKey: GettxoutScriptPubKey;
/** Coinbase or not */
coinbase: boolean;
}
/**
* Returns details about an unspent transaction output
*
*
* @param {string} txid The transaction id
* @param {number} n vout number
* @param {boolean} includeMempool Whether to include the mempool. Note that an unspent output that is
* spent
* in the mempool won't appear.
*/
export const Gettxout = (
txid: string,
n: number,
includeMempool?: boolean
): Promise<void | GettxoutAlt> => Do("Gettxout", txid, n, includeMempool);
/////////////////////////////////////////
// RPC: gettxoutproof
//
/**
* Returns a hex-encoded proof that "txid" was included in a block
*
*
* NOTE: By default this function only works sometimes. This is when there is an
* unspent output in the utxo for this transaction. To make it always work,
* you need to maintain a transaction index, using the -txindex command line option or
* specify the block in which the transaction is included manually (by blockhash).
*
* @param {string[]} txids The txids to filter
* @param {string} blockhash If specified, looks for txid in the block with this hash
*/
export const Gettxoutproof = (
txids: string[],
blockhash?: string
): Promise<string> => Do("Gettxoutproof", txids, blockhash);
/////////////////////////////////////////
// RPC: gettxoutsetinfo
//
/**
* Detailed view of the unspendable categories
*/
export interface GettxoutsetinfoBlockInfoUnspendables {
genesis_block: string;
/** Transactions overridden by duplicates (no longer possible with BIP30) */
bip30: string;
/** Amounts sent to scripts that are unspendable (for example OP_RETURN outputs) */
scripts: string;
/** Fee rewards that miners did not claim in their coinbase transaction */
unclaimed_rewards: string;
}
/**
* Info on amounts in the block at this block height (only available if coinstatsindex is used)
*/
export interface GettxoutsetinfoBlockInfo {
prevout_spent: string;
coinbase: string;
new_outputs_ex_coinbase: string;
unspendable: string;
/** Detailed view of the unspendable categories */
unspendables: GettxoutsetinfoBlockInfoUnspendables;
}
export interface GettxoutsetinfoResult {
/** The block height (index) of the returned statistics */
height: number;
/** The hash of the block at which these statistics are calculated */
bestblock: string;
/** The number of unspent transaction outputs */
txouts: number;
/** Database-independent, meaningless metric indicating the UTXO set size */
bogosize: number;
/** The serialized hash (only present if 'hash_serialized_2' hash_type is chosen) */
hash_serialized_2?: string;
/** The serialized hash (only present if 'muhash' hash_type is chosen) */
muhash?: string;
/**
* The number of transactions with unspent outputs (not available when coinstatsindex is used)
*/
transactions: number;
/** The estimated size of the chainstate on disk (not available when coinstatsindex is used) */
disk_size: number;
/** The total amount of coins in the UTXO set */
total_amount: string;
/**
* The total amount of coins permanently excluded from the UTXO set (only available if coinstatsindex
* is used)
*/
total_unspendable_amount: string;
/**
* Info on amounts in the block at this block height (only available if coinstatsindex is used)
*/
block_info: GettxoutsetinfoBlockInfo;
}
/**
* Returns statistics about the unspent transaction output set
*
* Note this call may take some time if you are not using coinstatsindex.
*
* @param {string} hashType Which UTXO set hash should be calculated. Options: 'hash_serialized_2' (the
* legacy algorithm), 'muhash', 'none'.
* @param {number} hashOrHeight The block hash or height of the target height (only available with coinstatsindex).
* @param {boolean} useIndex Use coinstatsindex, if available.
*/
export const Gettxoutsetinfo = (
hashType?: string,
hashOrHeight?: number,
useIndex?: boolean
): Promise<GettxoutsetinfoResult> => Do("Gettxoutsetinfo", hashType, hashOrHeight, useIndex);
/////////////////////////////////////////
// RPC: getunconfirmedbalance
//
/**
* DEPRECATED
*
* Identical to getbalances().mine.untrusted_pending
*/
export const Getunconfirmedbalance = (): Promise<number> => Do("Getunconfirmedbalance");
/////////////////////////////////////////
// RPC: getwalletinfo
//
/**
* current scanning details, or false if no scan is in progress
*/
export interface GetwalletinfoScanning {
/** elapsed seconds since scan start */
duration: number;
/** scanning progress percentage [0.0, 1.0] */
progress: number;
}
export interface GetwalletinfoResult {
/** the wallet name */
walletname: string;
/** the wallet version */
walletversion: number;
/** the database format (bdb or sqlite) */
format: string;
/** DEPRECATED. Identical to getbalances().mine.trusted */
balance: string;
/** DEPRECATED. Identical to getbalances().mine.untrusted_pending */
unconfirmed_balance: string;
/** DEPRECATED. Identical to getbalances().mine.immature */
immature_balance: string;
/** the total number of transactions in the wallet */
txcount: number;
/**
* the UNIX epoch time of the oldest pre-generated key in the key pool. Legacy wallets only.
*/
keypoololdest: number;
/** how many new keys are pre-generated (only counts external keys) */
keypoolsize: number;
/**
* how many new keys are pre-generated for internal use (used for change outputs, only appears if
* the wallet is using this feature, otherwise external keys are used)
*/
keypoolsize_hd_internal: number;
/**
* the UNIX epoch time until which the wallet is unlocked for transfers, or 0 if the wallet is locked
* (only present for passphrase-encrypted wallets)
*/
unlocked_until?: number;
/** the transaction fee configuration, set in BTC/kvB */
paytxfee: string;
/** the Hash160 of the HD seed (only present when HD is enabled) */
hdseedid?: string;
/** false if privatekeys are disabled for this wallet (enforced watch-only wallet) */
private_keys_enabled: boolean;
/** whether this wallet tracks clean/dirty coins in terms of reuse */
avoid_reuse: boolean;
/** current scanning details, or false if no scan is in progress */
scanning: GetwalletinfoScanning;
/** whether this wallet uses descriptors for scriptPubKey management */
descriptors: boolean;
}
/**
* Returns an object containing various wallet state info
*
*/
export const Getwalletinfo = (): Promise<GetwalletinfoResult> => Do("Getwalletinfo");
/////////////////////////////////////////
// RPC: getzmqnotifications
//
export interface GetzmqnotificationsResult {
/** Type of notification */
type: string;
/** Address of the publisher */
address: string;
/** Outbound message high water mark */
hwm: number;
}
/**
* Returns information about the active ZeroMQ notifications
*
*/
export const Getzmqnotifications = (): Promise<GetzmqnotificationsResult[]> => Do("Getzmqnotifications");
/////////////////////////////////////////
// RPC: help
//
/**
* List all commands, or get help for a specified command
*
*
* @param {string} command The command to get help on
*/
export const Help = (
command?: string
): Promise<string | Dict<string | boolean | number | object>> => Do("Help", command);
/////////////////////////////////////////
// RPC: importaddress
//
/**
* Adds an address or script (in hex) that can be watched as if it were in your wallet but cannot be
*
* used to spend. Requires a new wallet backup.
*
* Note: This call can take over an hour to complete if rescan is true, during that time, other rpc calls
* may report that the imported address exists but related transactions are still missing, leading to
* temporarily incorrect/bogus balances and unspent outputs until rescan completes.
* If you have the full public key, you should call importpubkey instead of this.
* Hint: use importmulti to import more than one address.
*
* Note: If you import a non-standard raw script in hex form, outputs sending to it will be treated
* as change, and not show up in many RPCs.
* Note: Use "getwalletinfo" to query the scanning progress.
*
* @param {string} address The Bitcoin address (or hex-encoded script)
* @param {string} label An optional label
* @param {boolean} rescan Rescan the wallet for transactions
* @param {boolean} p2sh Add the P2SH version of the script as well
*/
export const Importaddress = (
address: string,
label?: string,
rescan?: boolean,
p2sh?: boolean
): Promise<void> => Do("Importaddress", address, label, rescan, p2sh);
/////////////////////////////////////////
// RPC: importdescriptors
//
export interface ImportdescriptorsResult {
success: boolean;
warnings?: string[];
error?: Dict<string | boolean | number | object>;
}
export interface ImportdescriptorsRequest {
/** Descriptor to import. */
desc: string;
/**
* Set this descriptor to be the active descriptor for the corresponding output type/externality
*/
active?: boolean;
/**
* If a ranged descriptor is used, this specifies the end or the range (in the form [begin,end])
* to import
*/
range: number | [number, number];
/**
* If a ranged descriptor is set to active, this specifies the next index to generate addresses from
*/
next_index: number;
/**
* Time from which to start rescanning the blockchain for this descriptor, in UNIX epoch time
* Use the string "now" to substitute
* the current synced blockchain time.
* "now" can be specified to bypass
* scanning, for outputs which are known to never have been used, and
* 0 can be specified to scan the entire
* blockchain. Blocks up to 2 hours before the earliest timestamp
* of all descriptors being imported
* will be scanned.
*/
timestamp: number;
/** Whether matching outputs should be treated as not incoming payments (e.g. change) */
internal?: boolean;
/** Label to assign to the address, only allowed with internal=false */
label?: string;
}
/**
* Import descriptors
*
* This will trigger a rescan of the blockchain based on the earliest timestamp of all descriptors being
* imported. Requires a new wallet backup.
*
* Note: This call can take over an hour to complete if using an early timestamp; during that time, other
* rpc calls
* may report that the imported keys, addresses or scripts exist but related transactions are still missing.
*
* @param {ImportdescriptorsRequest[]} requests Data to be imported
*/
export const Importdescriptors = (
requests: ImportdescriptorsRequest[]
): Promise<ImportdescriptorsResult[]> => Do("Importdescriptors", requests);
/////////////////////////////////////////
// RPC: importmulti
//
export interface ImportmultiResult {
success: boolean;
warnings?: string[];
error?: Dict<string | boolean | number | object>;
}
export interface ImportmultiRequest {
/**
* Descriptor to import. If using descriptor, do not also provide address/scriptPubKey, scripts,
* or pubkeys
*/
desc: string;
/**
* Type of scriptPubKey (string for script, json for address). Should not be provided if using a
* descriptor
*/
scriptPubKey: string;
/**
* Creation time of the key expressed in UNIX epoch time,
* or the string "now" to substitute
* the current synced blockchain time. The timestamp of the oldest
* key will determine how far back
* blockchain rescans need to begin for missing wallet transactions.
* "now" can be specified to bypass
* scanning, for keys which are known to never have been used, and
* 0 can be specified to scan the entire
* blockchain. Blocks up to 2 hours before the earliest key
* creation time of all keys being
* imported by the importmulti call will be scanned.
*/
timestamp: number;
/** Allowed only if the scriptPubKey is a P2SH or P2SH-P2WSH address/scriptPubKey */
redeemscript: string;
/** Allowed only if the scriptPubKey is a P2SH-P2WSH or P2WSH address/scriptPubKey */
witnessscript: string;
/**
* Array of strings giving pubkeys to import. They must occur in P2PKH or P2WPKH scripts. They are
* not required when the private key is also provided (see the "keys" argument).
*/
pubkeys?: string[];
/**
* Array of strings giving private keys to import. The corresponding public keys must occur in the
* output or redeemscript.
*/
keys?: string[];
/**
* If a ranged descriptor is used, this specifies the end or the range (in the form [begin,end])
* to import
*/
range: number | [number, number];
/**
* Stating whether matching outputs should be treated as not incoming payments (also known as change)
*/
internal?: boolean;
/** Stating whether matching outputs should be considered watchonly. */
watchonly?: boolean;
/** Label to assign to the address, only allowed with internal=false */
label?: string;
/**
* Stating whether imported public keys should be added to the keypool for when users request new
* addresses. Only allowed when wallet private keys are disabled
*/
keypool?: boolean;
}
export interface ImportmultiOptions {
/** Stating if should rescan the blockchain after all imports */
rescan?: boolean;
}
/**
* Import addresses/scripts (with private or public keys, redeem script (P2SH)), optionally rescanning
*
* the blockchain from the earliest creation time of the imported scripts. Requires a new wallet backup.
* If an address/script is imported without all of the private keys required to spend from that address,
* it will be watchonly. The 'watchonly' option must be set to true in this case or a warning will be
* returned.
* Conversely, if all the private keys are provided and the address/script is spendable, the watchonly
* option must be set to false, or a warning will be returned.
*
* Note: This call can take over an hour to complete if rescan is true, during that time, other rpc calls
* may report that the imported keys, addresses or scripts exist but related transactions are still missing.
* Note: Use "getwalletinfo" to query the scanning progress.
*
* @param {ImportmultiRequest[]} requests Data to be imported
* @param {ImportmultiOptions} options
*/
export const Importmulti = (
requests: ImportmultiRequest[],
options?: ImportmultiOptions
): Promise<ImportmultiResult[]> => Do("Importmulti", requests, options);
/////////////////////////////////////////
// RPC: importprivkey
//
/**
* Adds a private key (as returned by dumpprivkey) to your wallet
*
* Requires a new wallet backup.
* Hint: use importmulti to import more than one private key.
*
* Note: This call can take over an hour to complete if rescan is true, during that time, other rpc calls
* may report that the imported key exists but related transactions are still missing, leading to temporarily
* incorrect/bogus balances and unspent outputs until rescan completes.
* Note: Use "getwalletinfo" to query the scanning progress.
*
* @param {string} privkey The private key (see dumpprivkey)
* @param {string} label An optional label
* @param {boolean} rescan Rescan the wallet for transactions
*/
export const Importprivkey = (
privkey: string,
label?: string,
rescan?: boolean
): Promise<void> => Do("Importprivkey", privkey, label, rescan);
/////////////////////////////////////////
// RPC: importprunedfunds
//
/**
* Imports funds without rescan
*
* Corresponding address or script must previously be included in wallet. Aimed towards pruned wallets.
* The end-user is responsible to import additional transactions that subsequently spend the imported
* outputs or rescan after the point in the blockchain the transaction is included.
*
* @param {string} rawtransaction A raw transaction in hex funding an already-existing address in wallet
* @param {string} txoutproof The hex output from gettxoutproof that contains the transaction
*/
export const Importprunedfunds = (
rawtransaction: string,
txoutproof: string
): Promise<void> => Do("Importprunedfunds", rawtransaction, txoutproof);
/////////////////////////////////////////
// RPC: importpubkey
//
/**
* Adds a public key (in hex) that can be watched as if it were in your wallet but cannot be used to
*
* spend. Requires a new wallet backup.
* Hint: use importmulti to import more than one public key.
*
* Note: This call can take over an hour to complete if rescan is true, during that time, other rpc calls
* may report that the imported pubkey exists but related transactions are still missing, leading to
* temporarily incorrect/bogus balances and unspent outputs until rescan completes.
* Note: Use "getwalletinfo" to query the scanning progress.
*
* @param {string} pubkey The hex-encoded public key
* @param {string} label An optional label
* @param {boolean} rescan Rescan the wallet for transactions
*/
export const Importpubkey = (
pubkey: string,
label?: string,
rescan?: boolean
): Promise<void> => Do("Importpubkey", pubkey, label, rescan);
/////////////////////////////////////////
// RPC: importwallet
//
/**
* Imports keys from a wallet dump file (see dumpwallet)
*
* Requires a new wallet backup to include imported keys.
* Note: Use "getwalletinfo" to query the scanning progress.
*
* @param {string} filename The wallet file
*/
export const Importwallet = (
filename: string
): Promise<void> => Do("Importwallet", filename);
/////////////////////////////////////////
// RPC: invalidateblock
//
/**
* Permanently marks a block as invalid, as if it violated a consensus rule
*
*
* @param {string} blockhash the hash of the block to mark as invalid
*/
export const Invalidateblock = (
blockhash: string
): Promise<void> => Do("Invalidateblock", blockhash);
/////////////////////////////////////////
// RPC: joinpsbts
//
/**
* Joins multiple distinct PSBTs with different inputs and outputs into one PSBT with inputs and outputs
*
* from all of the PSBTs
* No input in any of the PSBTs can be in more than one of the PSBTs.
*
* @param {string[]} txs The base64 strings of partially signed transactions
*/
export const Joinpsbts = (
txs: string[]
): Promise<string> => Do("Joinpsbts", txs);
/////////////////////////////////////////
// RPC: keypoolrefill
//
/**
* Fills the keypool
*
* Requires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.
*
* @param {number} newsize The new keypool size
*/
export const Keypoolrefill = (
newsize?: number
): Promise<void> => Do("Keypoolrefill", newsize);
/////////////////////////////////////////
// RPC: listaddressgroupings
//
export type ListaddressgroupingsResult = [string, string, string?];
/**
* Lists groups of addresses which have had their common ownership
*
* made public by common use as inputs or as the resulting change
* in past transactions
*/
export const Listaddressgroupings = (): Promise<(
ListaddressgroupingsResult[]
)[]> => Do("Listaddressgroupings");
/////////////////////////////////////////
// RPC: listbanned
//
export interface ListbannedResult {
/** The IP/Subnet of the banned node */
address: string;
/** The UNIX epoch time the ban was created */
ban_created: number;
/** The UNIX epoch time the ban expires */
banned_until: number;
/** The ban duration, in seconds */
ban_duration: number;
/** The time remaining until the ban expires, in seconds */
time_remaining: number;
}
/**
* List all manually banned IPs/Subnets
*
*/
export const Listbanned = (): Promise<ListbannedResult[]> => Do("Listbanned");
/////////////////////////////////////////
// RPC: listdescriptors
//
/**
* Defined only for ranged descriptors
*/
export type ListdescriptorsDescriptorRange = [number, number];
export interface ListdescriptorsDescriptor {
/** Descriptor string representation */
desc: string;
/** The creation time of the descriptor */
timestamp: number;
/** Activeness flag */
active: boolean;
/** Whether this is an internal or external descriptor; defined only for active descriptors */
internal?: boolean;
/** Defined only for ranged descriptors */
range: ListdescriptorsDescriptorRange;
/** The next index to generate addresses from; defined only for ranged descriptors */
next?: number;
}
export interface ListdescriptorsResult {
/** Name of wallet this operation was performed on */
wallet_name: string;
/** Array of descriptor objects */
descriptors: ListdescriptorsDescriptor[];
}
/**
* List descriptors imported into a descriptor-enabled wallet
*/
export const Listdescriptors = (): Promise<ListdescriptorsResult> => Do("Listdescriptors");
/////////////////////////////////////////
// RPC: listlabels
//
/**
* Returns the list of all labels, or labels that are assigned to addresses with a specific purpose
*
*
* @param {string} purpose Address purpose to list labels for ('send','receive'). An empty string is
* the
* same as not providing this argument.
*/
export const Listlabels = (
purpose?: string
): Promise<string[]> => Do("Listlabels", purpose);
/////////////////////////////////////////
// RPC: listlockunspent
//
export interface ListlockunspentResult {
/** The transaction id locked */
txid: string;
/** The vout value */
vout: number;
}
/**
* Returns list of temporarily unspendable outputs
*
* See the lockunspent call to lock and unlock transactions for spending.
*/
export const Listlockunspent = (): Promise<ListlockunspentResult[]> => Do("Listlockunspent");
/////////////////////////////////////////
// RPC: listreceivedbyaddress
//
export interface ListreceivedbyaddressResult {
/** Only returns true if imported addresses were involved in transaction */
involvesWatchonly: boolean;
/** The receiving address */
address: string;
/** The total amount in BTC received by the address */
amount: string;
/** The number of confirmations of the most recent transaction included */
confirmations: number;
/** The label of the receiving address. The default label is "" */
label: string;
txids: string[];
}
/**
* List balances by receiving address
*
*
* @param {number} minconf The minimum number of confirmations before payments are included.
* @param {boolean} includeEmpty Whether to include addresses that haven't received any payments.
* @param {boolean} includeWatchonly Whether to include watch-only addresses (see 'importaddress')
* @param {string} addressFilter If present, only return information on this address.
*/
export const Listreceivedbyaddress = (
minconf?: number,
includeEmpty?: boolean,
includeWatchonly?: boolean,
addressFilter?: string
): Promise<ListreceivedbyaddressResult[]> => Do("Listreceivedbyaddress", minconf, includeEmpty, includeWatchonly,
addressFilter);
/////////////////////////////////////////
// RPC: listreceivedbylabel
//
export interface ListreceivedbylabelResult {
/** Only returns true if imported addresses were involved in transaction */
involvesWatchonly: boolean;
/** The total amount received by addresses with this label */
amount: string;
/** The number of confirmations of the most recent transaction included */
confirmations: number;
/** The label of the receiving address. The default label is "" */
label: string;
}
/**
* List received transactions by label
*
*
* @param {number} minconf The minimum number of confirmations before payments are included.
* @param {boolean} includeEmpty Whether to include labels that haven't received any payments.
* @param {boolean} includeWatchonly Whether to include watch-only addresses (see 'importaddress')
*/
export const Listreceivedbylabel = (
minconf?: number,
includeEmpty?: boolean,
includeWatchonly?: boolean
): Promise<ListreceivedbylabelResult[]> => Do("Listreceivedbylabel", minconf, includeEmpty, includeWatchonly);
/////////////////////////////////////////
// RPC: listsinceblock
//
export interface ListsinceblockTransaction {
/** Only returns true if imported addresses were involved in transaction. */
involvesWatchonly: boolean;
/** The bitcoin address of the transaction. */
address: string;
/**
* The transaction category.
* "send" Transactions sent.
* "receive" Non-coinbase transactions received.
* "generate" Coinbase transactions received with more than 100 confirmations.
* "immature" Coinbase transactions received with 100 or fewer confirmations.
* "orphan" Orphaned coinbase transactions received.
*/
category: string;
/**
* The amount in BTC. This is negative for the 'send' category, and is positive
* for all other categories
*/
amount: string;
/** the vout value */
vout: number;
/**
* The amount of the fee in BTC. This is negative and only available for the
* 'send' category of transactions.
*/
fee: string;
/**
* The number of confirmations for the transaction. Negative confirmations means the
* transaction conflicted that many blocks ago.
*/
confirmations: number;
/** Only present if transaction only input is a coinbase one. */
generated: boolean;
/** Only present if we consider transaction to be trusted and so safe to spend from. */
trusted: boolean;
/** The block hash containing the transaction. */
blockhash: string;
/** The block height containing the transaction. */
blockheight: number;
/** The index of the transaction in the block that includes it. */
blockindex: number;
/** The block time expressed in UNIX epoch time. */
blocktime: number;
/** The transaction id. */
txid: string;
/** Conflicting transaction ids. */
walletconflicts: string[];
/** The transaction time expressed in UNIX epoch time. */
time: number;
/** The time received expressed in UNIX epoch time. */
timereceived: number;
/** If a comment is associated with the transaction, only present if not empty. */
comment: string;
/**
* ("yes|no|unknown") Whether this transaction could be replaced due to BIP125 (replace-by-fee);
* may be unknown for unconfirmed transactions not in the mempool
*/
"bip125-replaceable": string;
/**
* 'true' if the transaction has been abandoned (inputs are respendable). Only available for the
* 'send' category of transactions.
*/
abandoned: boolean;
/** A comment for the address/transaction, if any */
label: string;
/** If a comment to is associated with the transaction. */
to: string;
}
export interface ListsinceblockResult {
transactions: ListsinceblockTransaction[];
/**
* <structure is the same as "transactions" above, only present if include_removed=true>
* Note: transactions that were re-added in the active chain will appear as-is in this array, and
* may thus have a positive confirmation count.
*/
removed: (Dict<string | boolean | number | object>)[];
/**
* The hash of the block (target_confirmations-1) from the best block on the main chain, or the genesis
* hash if the referenced block does not exist yet. This is typically used to feed back into listsinceblock
* the next time you call it. So you would generally use a target_confirmations of say 6, so you
* will be continually re-notified of transactions until they've reached 6 confirmations plus any
* new ones
*/
lastblock: string;
}
/**
* Get all transactions in blocks since block [blockhash], or all transactions if omitted
*
* If "blockhash" is no longer a part of the main chain, transactions from the fork point onward are
* included.
* Additionally, if include_removed is set, transactions affecting the wallet which were removed are
* returned in the "removed" array.
*
* @param {string} blockhash If set, the block hash to list transactions since, otherwise list all transactions.
* @param {number} targetConfirmations Return the nth block hash from the main chain. e.g. 1 would mean
* the best block hash. Note: this is not used as a filter, but only affects [lastblock] in the return
* value
* @param {boolean} includeWatchonly Include transactions to watch-only addresses (see 'importaddress')
* @param {boolean} includeRemoved Show transactions that were removed due to a reorg in the "removed"
* array
* (not guaranteed to work on pruned nodes)
*/
export const Listsinceblock = (
blockhash?: string,
targetConfirmations?: number,
includeWatchonly?: boolean,
includeRemoved?: boolean
): Promise<ListsinceblockResult> => Do("Listsinceblock", blockhash, targetConfirmations, includeWatchonly,
includeRemoved);
/////////////////////////////////////////
// RPC: listtransactions
//
export interface ListtransactionsResult {
/** Only returns true if imported addresses were involved in transaction. */
involvesWatchonly: boolean;
/** The bitcoin address of the transaction. */
address: string;
/**
* The transaction category.
* "send" Transactions sent.
* "receive" Non-coinbase transactions received.
* "generate" Coinbase transactions received with more than 100 confirmations.
* "immature" Coinbase transactions received with 100 or fewer confirmations.
* "orphan" Orphaned coinbase transactions received.
*/
category: string;
/**
* The amount in BTC. This is negative for the 'send' category, and is positive
* for all other categories
*/
amount: string;
/** A comment for the address/transaction, if any */
label: string;
/** the vout value */
vout: number;
/**
* The amount of the fee in BTC. This is negative and only available for the
* 'send' category of transactions.
*/
fee: string;
/**
* The number of confirmations for the transaction. Negative confirmations means the
* transaction conflicted that many blocks ago.
*/
confirmations: number;
/** Only present if transaction only input is a coinbase one. */
generated: boolean;
/** Only present if we consider transaction to be trusted and so safe to spend from. */
trusted: boolean;
/** The block hash containing the transaction. */
blockhash: string;
/** The block height containing the transaction. */
blockheight: number;
/** The index of the transaction in the block that includes it. */
blockindex: number;
/** The block time expressed in UNIX epoch time. */
blocktime: number;
/** The transaction id. */
txid: string;
/** Conflicting transaction ids. */
walletconflicts: string[];
/** The transaction time expressed in UNIX epoch time. */
time: number;
/** The time received expressed in UNIX epoch time. */
timereceived: number;
/** If a comment is associated with the transaction, only present if not empty. */
comment: string;
/**
* ("yes|no|unknown") Whether this transaction could be replaced due to BIP125 (replace-by-fee);
* may be unknown for unconfirmed transactions not in the mempool
*/
"bip125-replaceable": string;
/**
* 'true' if the transaction has been abandoned (inputs are respendable). Only available for the
* 'send' category of transactions.
*/
abandoned: boolean;
}
/**
* If a label name is provided, this will return only incoming transactions paying to addresses with
*
* the specified label.
*
* Returns up to 'count' most recent transactions skipping the first 'from' transactions.
*
* @param {string} label If set, should be a valid label name to return only incoming transactions
* with the specified label, or "*" to disable filtering and return all transactions.
* @param {number} count The number of transactions to return
* @param {number} skip The number of transactions to skip
* @param {boolean} includeWatchonly Include transactions to watch-only addresses (see 'importaddress')
*/
export const Listtransactions = (
label?: string,
count?: number,
skip?: number,
includeWatchonly?: boolean
): Promise<ListtransactionsResult[]> => Do("Listtransactions", label, count, skip, includeWatchonly);
/////////////////////////////////////////
// RPC: listunspent
//
export interface ListunspentResult {
/** the transaction id */
txid: string;
/** the vout value */
vout: number;
/** the bitcoin address */
address: string;
/** The associated label, or "" for the default label */
label: string;
/** the script key */
scriptPubKey: string;
/** the transaction output amount in BTC */
amount: string;
/** The number of confirmations */
confirmations: number;
/** The redeemScript if scriptPubKey is P2SH */
redeemScript: string;
/** witnessScript if the scriptPubKey is P2WSH or P2SH-P2WSH */
witnessScript: string;
/** Whether we have the private keys to spend this output */
spendable: boolean;
/** Whether we know how to spend this output, ignoring the lack of keys */
solvable: boolean;
/**
* (only present if avoid_reuse is set) Whether this output is reused/dirty (sent to an address that
* was previously spent from)
*/
reused: boolean;
/** (only when solvable) A descriptor for spending this output */
desc: string;
/**
* Whether this output is considered safe to spend. Unconfirmed transactions
* from outside keys and unconfirmed replacement transactions are considered unsafe
* and are not eligible for spending by fundrawtransaction and sendtoaddress.
*/
safe: boolean;
}
/**
* JSON with query options
*/
export interface ListunspentQueryOptions {
/** Minimum value of each UTXO in BTC */
minimumAmount?: number | string;
/** Maximum value of each UTXO in BTC */
maximumAmount?: number | string;
/** Maximum number of UTXOs */
maximumCount?: number;
/** Minimum sum value of all UTXOs in BTC */
minimumSumAmount?: number | string;
}
/**
* Returns array of unspent transaction outputs
*
* with between minconf and maxconf (inclusive) confirmations.
* Optionally filter to only include txouts paid to specified addresses.
*
* @param {number} minconf The minimum confirmations to filter
* @param {number} maxconf The maximum confirmations to filter
* @param {string[]} addresses The bitcoin addresses to filter
* @param {boolean} includeUnsafe Include outputs that are not safe to spend
* See description of "safe" attribute below.
* @param {ListunspentQueryOptions} queryOptions JSON with query options
*/
export const Listunspent = (
minconf?: number,
maxconf?: number,
addresses?: string[],
includeUnsafe?: boolean,
queryOptions?: ListunspentQueryOptions
): Promise<ListunspentResult[]> => Do("Listunspent", minconf, maxconf, addresses, includeUnsafe, queryOptions);
/////////////////////////////////////////
// RPC: listwalletdir
//
export interface ListwalletdirWallet {
/** The wallet name */
name: string;
}
export interface ListwalletdirResult {
wallets: ListwalletdirWallet[];
}
/**
* Returns a list of wallets in the wallet directory
*
*/
export const Listwalletdir = (): Promise<ListwalletdirResult> => Do("Listwalletdir");
/////////////////////////////////////////
// RPC: listwallets
//
/**
* Returns a list of currently loaded wallets
*
* For full information on the wallet, use "getwalletinfo"
*/
export const Listwallets = (): Promise<string[]> => Do("Listwallets");
/////////////////////////////////////////
// RPC: loadwallet
//
export interface LoadwalletResult {
/** The wallet name if loaded successfully. */
name: string;
/** Warning message if wallet was not loaded cleanly. */
warning: string;
}
/**
* Loads a wallet from a wallet file or directory
*
* Note that all wallet command-line options used when starting bitcoind will be
* applied to the new wallet (eg -rescan, etc).
*
* @param {string} filename The wallet directory or .dat file.
* @param {boolean} loadOnStartup Save wallet name to persistent settings and load on startup. True to
* add
* wallet to startup list, false to remove, null to leave unchanged.
*/
export const Loadwallet = (
filename: string,
loadOnStartup?: boolean
): Promise<LoadwalletResult> => Do("Loadwallet", filename, loadOnStartup);
/////////////////////////////////////////
// RPC: lockunspent
//
export interface LockunspentTransaction {
/** The transaction id */
txid: string;
/** The output number */
vout: number;
}
/**
* Updates list of temporarily unspendable outputs
*
* Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.
* If no transaction outputs are specified when unlocking then all current locked transaction outputs
* are unlocked.
* A locked transaction output will not be chosen by automatic coin selection, when spending bitcoins.
* Manually selected coins are automatically unlocked.
* Locks are stored in memory only. Nodes start with zero locked outputs, and the locked output list
* is always cleared (by virtue of process exit) when a node stops or fails.
* Also see the listunspent call
*
* @param {boolean} unlock Whether to unlock (true) or lock (false) the specified transactions
* @param {LockunspentTransaction[]} transactions The transaction outputs and within each, the txid (string)
* vout (numeric).
*/
export const Lockunspent = (
unlock: boolean,
transactions?: LockunspentTransaction[]
): Promise<boolean> => Do("Lockunspent", unlock, transactions);
/////////////////////////////////////////
// RPC: logging
//
/**
* Gets and sets the logging configuration
*
* When called without an argument, returns the list of categories with status that are currently being
* debug logged or not.
* When called with arguments, adds or removes categories from debug logging and return the lists above.
* The arguments are evaluated in order "include", "exclude".
* If an item is both included and excluded, it will thus end up being excluded.
* The valid logging categories are: net, tor, mempool, http, bench, zmq, walletdb, rpc, estimatefee,
* addrman, selectcoins, reindex, cmpctblock, rand, prune, proxy, mempoolrej, libevent, coindb, qt, leveldb,
* validation, i2p, ipc
* In addition, the following are available as category names with special meanings:
* - "all", "1" : represent all logging categories.
* - "none", "0" : even if other logging categories are specified, ignore all of them.
*
* @param {string[]} include The categories to add to debug logging
* @param {string[]} exclude The categories to remove from debug logging
*/
export const Logging = (
include?: string[],
exclude?: string[]
): Promise<Dict<boolean>> => Do("Logging", include, exclude);
/////////////////////////////////////////
// RPC: mockscheduler
//
/**
* Bump the scheduler into the future (-regtest only)
*
* @param {number} deltaTime Number of seconds to forward the scheduler into the future.
*/
export const Mockscheduler = (
deltaTime: number
): Promise<void> => Do("Mockscheduler", deltaTime);
/////////////////////////////////////////
// RPC: ping
//
/**
* Requests that a ping be sent to all other nodes, to measure ping time
*
* Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.
* Ping command is handled in queue with all other commands, so it measures processing backlog, not just
* network ping.
*/
export const Ping = (): Promise<void> => Do("Ping");
/////////////////////////////////////////
// RPC: preciousblock
//
/**
* Treats a block as if it were received before others with the same work
*
*
* A later preciousblock call can override the effect of an earlier one.
*
* The effects of preciousblock are not retained across restarts.
*
* @param {string} blockhash the hash of the block to mark as precious
*/
export const Preciousblock = (
blockhash: string
): Promise<void> => Do("Preciousblock", blockhash);
/////////////////////////////////////////
// RPC: prioritisetransaction
//
/**
* Accepts the transaction into mined blocks at a higher (or lower) priority
*
* @param {string} txid The transaction id.
* @param {number} dummy API-Compatibility for previous API. Must be zero or null.
* DEPRECATED. For forward compatibility use named arguments and omit this parameter.
* @param {number} feeDelta The fee value (in satoshis) to add (or subtract, if negative).
* Note, that this value is not a fee rate. It is a value to modify absolute fee
* of
* the TX.
* The fee is not actually paid, only the algorithm for selecting transactions
* into
* a block
* considers the transaction as it would have paid a higher (or lower) fee.
*/
export const Prioritisetransaction = (
txid: string,
dummy: number,
feeDelta: number
): Promise<boolean> => Do("Prioritisetransaction", txid, dummy, feeDelta);
/////////////////////////////////////////
// RPC: pruneblockchain
//
/**
* @param {number} height The block height to prune up to
*
* May be set to a discrete height, or to a UNIX
* epoch time
* to prune blocks whose block time is at least 2 hours older than the provided
* timestamp.
*/
export const Pruneblockchain = (
height: number
): Promise<number> => Do("Pruneblockchain", height);
/////////////////////////////////////////
// RPC: psbtbumpfee
//
export interface PsbtbumpfeeResult {
/** The base64-encoded unsigned PSBT of the new transaction. */
psbt: string;
/** The fee of the replaced transaction. */
origfee: string;
/** The fee of the new transaction. */
fee: string;
/** Errors encountered during processing (may be empty). */
errors: string[];
}
export interface PsbtbumpfeeOptions {
/**
* Confirmation target in blocks
*/
conf_target?: number;
/**
* Specify a fee rate in sat/vB instead of relying on the built-in fee estimator.
* Must be at least 1.000 sat/vB higher than the current transaction fee rate.
* WARNING: before version 0.21, fee_rate was in BTC/kvB. As of 0.21, fee_rate is in sat/vB.
*/
fee_rate?: number | string;
/**
* Whether the new transaction should still be
* marked bip-125 replaceable. If true, the sequence numbers in the transaction will
* be left unchanged from the original. If false, any input sequence numbers in the
* original transaction that were less than 0xfffffffe will be increased to 0xfffffffe
* so the new transaction will not be explicitly bip-125 replaceable (though it may
* still be replaceable in practice, for example if it has unconfirmed ancestors which
* are replaceable).
*/
replaceable?: boolean;
/**
* The fee estimate mode, must be one of (case insensitive):
* "unset"
* "economical"
* "conservative"
*/
estimate_mode?: string;
}
/**
* Bumps the fee of an opt-in-RBF transaction T, replacing it with a new transaction B
*
* Returns a PSBT instead of creating and signing a new transaction.
* An opt-in RBF transaction with the given txid must be in the wallet.
* The command will pay the additional fee by reducing change outputs or adding inputs when necessary.
* It may add a new change output if one does not already exist.
* All inputs in the original transaction will be included in the replacement transaction.
* The command will fail if the wallet or mempool contains a transaction that spends one of T's outputs.
* By default, the new fee will be calculated automatically using the estimatesmartfee RPC.
* The user can specify a confirmation target for estimatesmartfee.
* Alternatively, the user can specify a fee rate in sat/vB for the new transaction.
* At a minimum, the new fee rate must be high enough to pay an additional new relay fee (incrementalfee
* returned by getnetworkinfo) to enter the node's mempool.
* * WARNING: before version 0.21, fee_rate was in BTC/kvB. As of 0.21, fee_rate is in sat/vB. *
*
* @param {string} txid The txid to be bumped
* @param {PsbtbumpfeeOptions} options
*/
export const Psbtbumpfee = (
txid: string,
options?: PsbtbumpfeeOptions
): Promise<PsbtbumpfeeResult> => Do("Psbtbumpfee", txid, options);
/////////////////////////////////////////
// RPC: reconsiderblock
//
/**
* Removes invalidity status of a block, its ancestors and its descendants, reconsider them for activation
*
* This can be used to undo the effects of invalidateblock.
*
* @param {string} blockhash the hash of the block to reconsider
*/
export const Reconsiderblock = (
blockhash: string
): Promise<void> => Do("Reconsiderblock", blockhash);
/////////////////////////////////////////
// RPC: removeprunedfunds
//
/**
* Deletes the specified transaction from the wallet
*
* Meant for use with pruned wallets and as a companion to importprunedfunds. This will affect wallet
* balances.
*
* @param {string} txid The hex-encoded id of the transaction you are deleting
*/
export const Removeprunedfunds = (
txid: string
): Promise<void> => Do("Removeprunedfunds", txid);
/////////////////////////////////////////
// RPC: rescanblockchain
//
export interface RescanblockchainResult {
/** The block height where the rescan started (the requested height or 0) */
start_height: number;
/**
* The height of the last rescanned block. May be null in rare cases if there was a reorg and the
* call didn't scan any blocks because they were already scanned in the background.
*/
stop_height: number;
}
/**
* Rescan the local blockchain for wallet related transactions
*
* Note: Use "getwalletinfo" to query the scanning progress.
*
* @param {number} startHeight block height where the rescan should start
* @param {number} stopHeight the last block height that should be scanned. If none is provided it will
* rescan up to the tip at return time of this call.
*/
export const Rescanblockchain = (
startHeight?: number,
stopHeight?: number
): Promise<RescanblockchainResult> => Do("Rescanblockchain", startHeight, stopHeight);
/////////////////////////////////////////
// RPC: savemempool
//
/**
* Dumps the mempool to disk
*
* It will fail until the previous dump is fully loaded.
*/
export const Savemempool = (): Promise<void> => Do("Savemempool");
/////////////////////////////////////////
// RPC: scantxoutset
//
export interface ScantxoutsetAlt {
/** The scan progress */
progress: number;
}
export interface ScantxoutsetUnspent {
/** The transaction id */
txid: string;
/** The vout value */
vout: number;
/** The script key */
scriptPubKey: string;
/** A specialized descriptor for the matched scriptPubKey */
desc: string;
/** The total amount in BTC of the unspent output */
amount: string;
/** Height of the unspent transaction output */
height: number;
}
export interface ScantxoutsetAlt2 {
/** Whether the scan was completed */
success: boolean;
/** The number of unspent transaction outputs scanned */
txouts: number;
/** The current block height (index) */
height: number;
/** The hash of the block at the tip of the chain */
bestblock: string;
unspents: ScantxoutsetUnspent[];
/** The total amount of all found unspent outputs in BTC */
total_amount: string;
}
/**
* An object with output descriptor and metadata
*/
export interface ScantxoutsetScanobjectAlt {
/** An output descriptor */
desc: string;
/** The range of HD chain indexes to explore (either end or [begin,end]) */
range?: number | [number, number];
}
/**
* Array of scan objects
*
* Required for "start" action
* Every scan object is either a string descriptor or an object:
*/
export type ScantxoutsetScanobject = string | ScantxoutsetScanobjectAlt;
/**
* Scans the unspent transaction output set for entries that match certain output descriptors
*
* Examples of output descriptors are:
* addr(<address>) Outputs whose scriptPubKey corresponds to the specified address
* (does not include P2PK)
* raw(<hex script>) Outputs whose scriptPubKey equals the specified hex scripts
* combo(<pubkey>) P2PK, P2PKH, P2WPKH, and P2SH-P2WPKH outputs for the given
* pubkey
* pkh(<pubkey>) P2PKH outputs for the given pubkey
* sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys
*
* In the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv
* optionally followed by one
* or more path elements separated by "/", and optionally ending in "/*" (unhardened), or "/*'" or "/*h"
* (hardened) to specify all
* unhardened or hardened child keys.
* In the latter case, a range needs to be specified by below if different from 1000.
* For more information on output descriptors, see the documentation in the doc/descriptors.md file.
*
* @param {string} action The action to execute
* "start" for starting a scan
* "abort" for aborting the current scan (returns true when abort was successful)
* "status" for progress report (in %) of the current scan
* @param {ScantxoutsetScanobject} scanobjects Array of scan objects. Required for "start" action
* Every scan object is either a string descriptor or an object:
*/
export const Scantxoutset = (
action: string,
scanobjects: ScantxoutsetScanobject
): Promise<boolean | void | ScantxoutsetAlt | ScantxoutsetAlt2> => Do("Scantxoutset", action, scanobjects);
/////////////////////////////////////////
// RPC: send
//
export interface SendResult {
/** If the transaction has a complete set of signatures */
complete: boolean;
/**
* The transaction id for the send. Only 1 transaction is created regardless of the number of addresses.
*/
txid: string;
/** If add_to_wallet is false, the hex-encoded raw transaction with signature(s) */
hex: string;
/**
* If more signatures are needed, or if add_to_wallet is false, the base64-encoded (partially) signed
* transaction
*/
psbt: string;
}
export interface SendOutputAlt {
/** A key-value pair. The key must be "data", the value is hex-encoded data */
data: string;
}
/**
* The outputs (key-value pairs), where none of the keys are duplicated
*
* That is, each address can only appear once and there can only be one 'data' object.
* For convenience, a dictionary, which holds the key-value pairs directly, is also accepted.
*/
export type SendOutput = Dict<number | string> | SendOutputAlt;
/**
* Specify inputs instead of adding them automatically
*
* A JSON array of JSON objects
*/
export type SendOptionsInput = string | number | number;
export interface SendOptions {
/** If inputs are specified, automatically include more if they are not enough. */
add_inputs?: boolean;
/**
* When false, returns a serialized transaction which will not be added to the wallet or broadcast
*/
add_to_wallet?: boolean;
/** The bitcoin address to receive the change */
change_address?: string;
/** The index of the change output */
change_position?: number;
/**
* The output type to use. Only valid if change_address is not specified. Options are "legacy", "p2sh-segwit",
* and "bech32".
*/
change_type?: string;
/** Confirmation target in blocks */
conf_target?: number;
/**
* The fee estimate mode, must be one of (case insensitive):
* "unset"
* "economical"
* "conservative"
*/
estimate_mode?: string;
/** Specify a fee rate in sat/vB. */
fee_rate?: number | string;
/**
* Also select inputs which are watch only.
* Only solvable inputs can be used. Watch-only destinations are solvable if the public key and/or
* output script was imported,
* e.g. with 'importpubkey' or 'importmulti' with the 'pubkeys' or 'desc' field.
*/
include_watching?: boolean;
/** Specify inputs instead of adding them automatically. A JSON array of JSON objects */
inputs?: SendOptionsInput;
/** Raw locktime. Non-0 value also locktime-activates inputs */
locktime?: number;
/** Lock selected unspent outputs */
lock_unspents?: boolean;
/** Always return a PSBT, implies add_to_wallet=false. */
psbt?: boolean;
/**
* Outputs to subtract the fee from, specified as integer indices.
* The fee will be equally deducted from the amount of each specified output.
* Those recipients will receive less bitcoins than you enter in their corresponding amount field.
* If no outputs are specified here, the sender pays the fee.
*/
subtract_fee_from_outputs?: number[];
/**
* Marks this transaction as BIP125 replaceable.
* Allows this transaction to be replaced by a transaction with higher fees
*/
replaceable?: boolean;
}
/**
* EXPERIMENTAL warning: this call may be changed in future releases
*
*
* Send a transaction.
*
* @param {SendOutput} outputs The outputs (key-value pairs), where none of the keys are duplicated.
* That is, each address can only appear once and there can only be one 'data' object.
* For convenience, a dictionary, which holds the key-value pairs directly, is also accepted.
* @param {number} confTarget Confirmation target in blocks
* @param {string} estimateMode The fee estimate mode, must be one of (case insensitive):
* "unset"
* "economical"
* "conservative"
* @param {number | string} feeRate Specify a fee rate in sat/vB.
* @param {SendOptions} options
*/
export const Send = (
outputs: SendOutput,
confTarget?: number,
estimateMode?: string,
feeRate?: number | string,
options?: SendOptions
): Promise<SendResult> => Do("Send", outputs, confTarget, estimateMode, feeRate, options);
/////////////////////////////////////////
// RPC: sendmany
//
export interface SendmanyAlt {
/**
* The transaction id for the send. Only 1 transaction is created regardless of
* the number of addresses.
*/
txid: string;
/** The transaction fee reason. */
"fee reason": string;
}
/**
* Send multiple times
*
* Amounts are double-precision floating point numbers.
* Requires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.
*
* @param {string} dummy Must be set to "" for backwards compatibility.
* @param {Dict<number | string>} amounts The addresses and amounts
* @param {number} minconf Ignored dummy value
* @param {string} comment A comment
* @param {string[]} subtractfeefrom The addresses.
* The fee will be equally deducted from the amount of each selected address.
* Those recipients will receive less bitcoins than you enter in their corresponding amount field.
* If no addresses are specified here, the sender pays the fee.
* @param {boolean} replaceable Allow this transaction to be replaced by a transaction with higher fees
* via BIP 125
* @param {number} confTarget Confirmation target in blocks
* @param {string} estimateMode The fee estimate mode, must be one of (case insensitive):
* "unset"
* "economical"
* "conservative"
* @param {number | string} feeRate Specify a fee rate in sat/vB.
* @param {boolean} verbose If true, return extra infomration about the transaction.
*/
export const Sendmany = (
dummy: string,
amounts: Dict<number | string>,
minconf?: number,
comment?: string,
subtractfeefrom?: string[],
replaceable?: boolean,
confTarget?: number,
estimateMode?: string,
feeRate?: number | string,
verbose?: boolean
): Promise<string | SendmanyAlt> => Do("Sendmany", dummy, amounts, minconf, comment, subtractfeefrom,
replaceable, confTarget, estimateMode, feeRate, verbose);
/////////////////////////////////////////
// RPC: sendrawtransaction
//
/**
* Submit a raw transaction (serialized, hex-encoded) to local node and network
*
*
* The transaction will be sent unconditionally to all peers, so using sendrawtransaction
* for manual rebroadcast may degrade privacy by leaking the transaction's origin, as
* nodes will normally not rebroadcast non-wallet transactions already in their mempool.
*
* A specific exception, RPC_TRANSACTION_ALREADY_IN_CHAIN, may throw if the transaction cannot be added
* to the mempool.
*
* Related RPCs: createrawtransaction, signrawtransactionwithkey
*
* @param {string} hexstring The hex string of the raw transaction
* @param {number | string} maxfeerate Reject transactions whose fee rate is higher than the specified
* value,
* expressed in BTC/kB.
* Set to 0 to accept any fee rate.
*/
export const Sendrawtransaction = (
hexstring: string,
maxfeerate?: number | string
): Promise<string> => Do("Sendrawtransaction", hexstring, maxfeerate);
/////////////////////////////////////////
// RPC: sendtoaddress
//
export interface SendtoaddressAlt {
/** The transaction id. */
txid: string;
/** The transaction fee reason. */
"fee reason": string;
}
/**
* Send an amount to a given address
*
* Requires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.
*
* @param {string} address The bitcoin address to send to.
* @param {number | string} amount The amount in BTC to send. eg 0.1
* @param {string} comment A comment used to store what the transaction is for.
* This is not part of the transaction, just kept in your wallet.
* @param {string} commentTo A comment to store the name of the person or organization
* to which you're sending the transaction. This is not part of the
* transaction, just kept in your wallet.
* @param {boolean} subtractfeefromamount The fee will be deducted from the amount being sent.
* The recipient will receive less bitcoins than you enter in the amount field.
* @param {boolean} replaceable Allow this transaction to be replaced by a transaction with higher fees
* via BIP 125
* @param {number} confTarget Confirmation target in blocks
* @param {string} estimateMode The fee estimate mode, must be one of (case insensitive):
* "unset"
* "economical"
* "conservative"
* @param {boolean} avoidReuse (only available if avoid_reuse wallet flag is set) Avoid spending from
* dirty
* addresses; addresses are considered
* dirty if they have previously been used in a transaction.
* @param {number | string} feeRate Specify a fee rate in sat/vB.
* @param {boolean} verbose If true, return extra information about the transaction.
*/
export const Sendtoaddress = (
address: string,
amount: number | string,
comment?: string,
commentTo?: string,
subtractfeefromamount?: boolean,
replaceable?: boolean,
confTarget?: number,
estimateMode?: string,
avoidReuse?: boolean,
feeRate?: number | string,
verbose?: boolean
): Promise<string | SendtoaddressAlt> => Do("Sendtoaddress", address, amount, comment, commentTo, subtractfeefromamount,
replaceable, confTarget, estimateMode, avoidReuse, feeRate, verbose);
/////////////////////////////////////////
// RPC: setban
//
/**
* Attempts to add or remove an IP/Subnet from the banned list
*
*
* @param {string} subnet The IP/Subnet (see getpeerinfo for nodes IP) with an optional netmask (default
* is /32 = single IP)
* @param {string} command 'add' to add an IP/Subnet to the list, 'remove' to remove an IP/Subnet from
* the
* list
* @param {number} bantime time in seconds how long (or until when if [absolute] is set) the IP is banned
* (0 or empty means using the default time of 24h which can also be overwritten by the -bantime
* startup
* argument)
* @param {boolean} absolute If set, the bantime must be an absolute timestamp expressed in UNIX epoch
* time
*/
export const Setban = (
subnet: string,
command: string,
bantime?: number,
absolute?: boolean
): Promise<void> => Do("Setban", subnet, command, bantime, absolute);
/////////////////////////////////////////
// RPC: sethdseed
//
/**
* Set or generate a new HD wallet seed
*
* Non-HD wallets will not be upgraded to being a HD wallet. Wallets that are already
* HD will have a new HD seed set so that new keys added to the keypool will be derived from this new
* seed.
*
* Note that you will need to MAKE A NEW BACKUP of your wallet after setting the HD wallet seed.
* Requires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.
*
* @param {boolean} newkeypool Whether to flush old unused addresses, including change addresses, from
* the
* keypool and regenerate it.
* If true, the next address from getnewaddress and change address from getrawchangeaddress will
* be
* from this new seed.
* If false, addresses (including change addresses if the wallet already had HD Chain Split enabled)
* from the existing
* keypool will be used until it has been depleted.
* @param {string} seed The WIF private key to use as the new HD seed.
* The seed value can be retrieved using the dumpwallet command. It is the private key marked hdseed=1
*/
export const Sethdseed = (
newkeypool?: boolean,
seed?: string
): Promise<void> => Do("Sethdseed", newkeypool, seed);
/////////////////////////////////////////
// RPC: setlabel
//
/**
* Sets the label associated with the given address
*
*
* @param {string} address The bitcoin address to be associated with a label.
* @param {string} label The label to assign to the address.
*/
export const Setlabel = (
address: string,
label: string
): Promise<void> => Do("Setlabel", address, label);
/////////////////////////////////////////
// RPC: setmocktime
//
/**
* Set the local time to given timestamp (-regtest only)
*
* @param {number} timestamp UNIX epoch time
* Pass 0 to go back to using the system time.
*/
export const Setmocktime = (
timestamp: number
): Promise<void> => Do("Setmocktime", timestamp);
/////////////////////////////////////////
// RPC: setnetworkactive
//
/**
* Disable/enable all p2p network activity
*
*
* @param {boolean} state true to enable networking, false to disable
*/
export const Setnetworkactive = (
state: boolean
): Promise<boolean> => Do("Setnetworkactive", state);
/////////////////////////////////////////
// RPC: settxfee
//
/**
* Set the transaction fee per kB for this wallet
*
* Overrides the global -paytxfee command line parameter.
* Can be deactivated by passing 0 as the fee. In that case automatic fee selection will be used by default.
*
* @param {number | string} amount The transaction fee in BTC/kvB
*/
export const Settxfee = (
amount: number | string
): Promise<boolean> => Do("Settxfee", amount);
/////////////////////////////////////////
// RPC: setwalletflag
//
export interface SetwalletflagResult {
/** The name of the flag that was modified */
flag_name: string;
/** The new state of the flag */
flag_state: boolean;
/** Any warnings associated with the change */
warnings: string;
}
/**
* Change the state of the given wallet flag for a wallet
*
*
* @param {string} flag The name of the flag to change. Current available flags: avoid_reuse
* @param {boolean} value The new state.
*/
export const Setwalletflag = (
flag: string,
value?: boolean
): Promise<SetwalletflagResult> => Do("Setwalletflag", flag, value);
/////////////////////////////////////////
// RPC: signmessage
//
/**
* Sign a message with the private key of an address
*
* Requires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.
*
* @param {string} address The bitcoin address to use for the private key.
* @param {string} message The message to create a signature of.
*/
export const Signmessage = (
address: string,
message: string
): Promise<string> => Do("Signmessage", address, message);
/////////////////////////////////////////
// RPC: signmessagewithprivkey
//
/**
* Sign a message with the private key of an address
*
* @param {string} privkey The private key to sign the message with.
* @param {string} message The message to create a signature of.
*/
export const Signmessagewithprivkey = (
privkey: string,
message: string
): Promise<string> => Do("Signmessagewithprivkey", privkey, message);
/////////////////////////////////////////
// RPC: signrawtransactionwithkey
//
export interface SignrawtransactionwithkeyError {
/** The hash of the referenced, previous transaction */
txid: string;
/** The index of the output to spent and used as input */
vout: number;
/** The hex-encoded signature script */
scriptSig: string;
/** Script sequence number */
sequence: number;
/** Verification or signing error related to the input */
error: string;
}
export interface SignrawtransactionwithkeyResult {
/** The hex-encoded raw transaction with signature(s) */
hex: string;
/** If the transaction has a complete set of signatures */
complete: boolean;
/** Script verification errors (if there are any) */
errors?: SignrawtransactionwithkeyError[];
}
export interface SignrawtransactionwithkeyPrevtx {
/** The transaction id */
txid: string;
/** The output number */
vout: number;
/** script key */
scriptPubKey: string;
/** (required for P2SH) redeem script */
redeemScript: string;
/** (required for P2WSH or P2SH-P2WSH) witness script */
witnessScript: string;
/** (required for Segwit inputs) the amount spent */
amount: number | string;
}
/**
* Sign inputs for raw transaction (serialized, hex-encoded)
*
* The second argument is an array of base58-encoded private
* keys that will be the only keys used to sign the transaction.
* The third optional argument (may be null) is an array of previous transaction outputs that
* this transaction depends on but may not yet be in the block chain.
*
* @param {string} hexstring The transaction hex string
* @param {string[]} privkeys The base58-encoded private keys for signing
* @param {SignrawtransactionwithkeyPrevtx[]} prevtxs The previous dependent transaction outputs
* @param {string} sighashtype The signature hash type. Must be one of:
* "ALL"
* "NONE"
* "SINGLE"
* "ALL|ANYONECANPAY"
* "NONE|ANYONECANPAY"
* "SINGLE|ANYONECANPAY"
*/
export const Signrawtransactionwithkey = (
hexstring: string,
privkeys: string[],
prevtxs?: SignrawtransactionwithkeyPrevtx[],
sighashtype?: string
): Promise<SignrawtransactionwithkeyResult> => Do("Signrawtransactionwithkey", hexstring, privkeys, prevtxs,
sighashtype);
/////////////////////////////////////////
// RPC: signrawtransactionwithwallet
//
export interface SignrawtransactionwithwalletError {
/** The hash of the referenced, previous transaction */
txid: string;
/** The index of the output to spent and used as input */
vout: number;
/** The hex-encoded signature script */
scriptSig: string;
/** Script sequence number */
sequence: number;
/** Verification or signing error related to the input */
error: string;
}
export interface SignrawtransactionwithwalletResult {
/** The hex-encoded raw transaction with signature(s) */
hex: string;
/** If the transaction has a complete set of signatures */
complete: boolean;
/** Script verification errors (if there are any) */
errors?: SignrawtransactionwithwalletError[];
}
export interface SignrawtransactionwithwalletPrevtx {
/** The transaction id */
txid: string;
/** The output number */
vout: number;
/** script key */
scriptPubKey: string;
/** (required for P2SH) redeem script */
redeemScript: string;
/** (required for P2WSH or P2SH-P2WSH) witness script */
witnessScript: string;
/** (required for Segwit inputs) the amount spent */
amount: number | string;
}
/**
* Sign inputs for raw transaction (serialized, hex-encoded)
*
* The second optional argument (may be null) is an array of previous transaction outputs that
* this transaction depends on but may not yet be in the block chain.
* Requires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.
*
* @param {string} hexstring The transaction hex string
* @param {SignrawtransactionwithwalletPrevtx[]} prevtxs The previous dependent transaction outputs
* @param {string} sighashtype The signature hash type. Must be one of
* "ALL"
* "NONE"
* "SINGLE"
* "ALL|ANYONECANPAY"
* "NONE|ANYONECANPAY"
* "SINGLE|ANYONECANPAY"
*/
export const Signrawtransactionwithwallet = (
hexstring: string,
prevtxs?: SignrawtransactionwithwalletPrevtx[],
sighashtype?: string
): Promise<SignrawtransactionwithwalletResult> => Do("Signrawtransactionwithwallet", hexstring, prevtxs,
sighashtype);
/////////////////////////////////////////
// RPC: stop
//
/**
* Request a graceful shutdown of Bitcoin Core
*
* @param {number} wait how long to wait in ms
*/
export const Stop = (
wait?: number
): Promise<string> => Do("Stop", wait);
/////////////////////////////////////////
// RPC: submitblock
//
/**
* Attempts to submit new block to network
*
* See https://en.bitcoin.it/wiki/BIP_0022 for full specification.
*
* @param {string} hexdata the hex-encoded block data to submit
* @param {string} dummy dummy value, for compatibility with BIP22. This value is ignored.
*/
export const Submitblock = (
hexdata: string,
dummy?: string
): Promise<void | string> => Do("Submitblock", hexdata, dummy);
/////////////////////////////////////////
// RPC: submitheader
//
/**
* Decode the given hexdata as a header and submit it as a candidate chain tip if valid
*
* Throws when the header is invalid.
*
* @param {string} hexdata the hex-encoded block header data
*/
export const Submitheader = (
hexdata: string
): Promise<void> => Do("Submitheader", hexdata);
/////////////////////////////////////////
// RPC: syncwithvalidationinterfacequeue
//
/**
* Waits for the validation interface queue to catch up on everything that was there when we entered
*
* this function.
*/
export const Syncwithvalidationinterfacequeue = (): Promise<void> => Do("Syncwithvalidationinterfacequeue");
/////////////////////////////////////////
// RPC: testmempoolaccept
//
/**
* Transaction fees (only present if 'allowed' is true)
*/
export interface TestmempoolacceptFees {
/** transaction fee in BTC */
base: string;
}
export interface TestmempoolacceptResult {
/** The transaction hash in hex */
txid: string;
/** The transaction witness hash in hex */
wtxid: string;
/** If the mempool allows this tx to be inserted */
allowed: boolean;
/**
* Virtual transaction size as defined in BIP 141. This is different from actual serialized size
* for witness transactions as witness data is discounted (only present when 'allowed' is true)
*/
vsize: number;
/** Transaction fees (only present if 'allowed' is true) */
fees: TestmempoolacceptFees;
/** Rejection string (only present when 'allowed' is false) */
"reject-reason": string;
}
/**
* Returns result of mempool acceptance tests indicating if raw transaction (serialized, hex-encoded)
*
* would be accepted by mempool.
*
* This checks if the transaction violates the consensus or policy rules.
*
* See sendrawtransaction call.
*
* @param {string[]} rawtxs An array of hex strings of raw transactions.
* Length must be one for now.
* @param {number | string} maxfeerate Reject transactions whose fee rate is higher than the specified
* value,
* expressed in BTC/kB
*/
export const Testmempoolaccept = (
rawtxs: string[],
maxfeerate?: number | string
): Promise<TestmempoolacceptResult[]> => Do("Testmempoolaccept", rawtxs, maxfeerate);
/////////////////////////////////////////
// RPC: unloadwallet
//
export interface UnloadwalletResult {
/** Warning message if wallet was not unloaded cleanly. */
warning: string;
}
/**
* Unloads the wallet referenced by the request endpoint otherwise unloads the wallet specified in the
*
* argument.
* Specifying the wallet name on a wallet endpoint is invalid.
* @param {string} walletName The name of the wallet to unload. If provided both here and in the RPC
* endpoint,
* the two must be identical.
* @param {boolean} loadOnStartup Save wallet name to persistent settings and load on startup. True to
* add
* wallet to startup list, false to remove, null to leave unchanged.
*/
export const Unloadwallet = (
walletName?: string,
loadOnStartup?: boolean
): Promise<UnloadwalletResult> => Do("Unloadwallet", walletName, loadOnStartup);
/////////////////////////////////////////
// RPC: upgradewallet
//
export interface UpgradewalletResult {
/** Name of wallet this operation was performed on */
wallet_name: string;
/** Version of wallet before this operation */
previous_version: number;
/** Version of wallet after this operation */
current_version: number;
/** Description of result, if no error */
result?: string;
/** Error message (if there is one) */
error?: string;
}
/**
* Upgrade the wallet
*
* Upgrades to the latest version if no version number is specified.
* New keys may be generated and a new wallet backup will need to be made.
* @param {number} version The version number to upgrade to. Default is the latest wallet version.
*/
export const Upgradewallet = (
version?: number
): Promise<UpgradewalletResult> => Do("Upgradewallet", version);
/////////////////////////////////////////
// RPC: uptime
//
/**
* Returns the total uptime of the server
*
*/
export const Uptime = (): Promise<number> => Do("Uptime");
/////////////////////////////////////////
// RPC: utxoupdatepsbt
//
/**
* An object with an output descriptor and extra information
*/
export interface UtxoupdatepsbtDescriptorAlt {
/** An output descriptor */
desc: string;
/** Up to what index HD chains should be explored (either end or [begin,end]) */
range?: number | [number, number];
}
/**
* An array of either strings or objects
*/
export type UtxoupdatepsbtDescriptor = string | UtxoupdatepsbtDescriptorAlt;
/**
* Updates all segwit inputs and outputs in a PSBT with data from output descriptors, the UTXO set or
*
* the mempool.
*
* @param {string} psbt A base64 string of a PSBT
* @param {UtxoupdatepsbtDescriptor} descriptors An array of either strings or objects
*/
export const Utxoupdatepsbt = (
psbt: string,
descriptors?: UtxoupdatepsbtDescriptor
): Promise<string> => Do("Utxoupdatepsbt", psbt, descriptors);
/////////////////////////////////////////
// RPC: validateaddress
//
export interface ValidateaddressResult {
/** If the address is valid or not */
isvalid: boolean;
/** The bitcoin address validated */
address: string;
/** The hex-encoded scriptPubKey generated by the address */
scriptPubKey: string;
/** If the key is a script */
isscript: boolean;
/** If the address is a witness address */
iswitness: boolean;
/** The version number of the witness program */
witness_version?: number;
/** The hex value of the witness program */
witness_program?: string;
/** Error message, if any */
error?: string;
}
/**
* Return information about the given bitcoin address
*
*
* @param {string} address The bitcoin address to validate
*/
export const Validateaddress = (
address: string
): Promise<ValidateaddressResult> => Do("Validateaddress", address);
/////////////////////////////////////////
// RPC: verifychain
//
/**
* Verifies blockchain database
*
*
* @param {number} checklevel How thorough the block verification is:
* - level 0 reads the blocks from disk
* - level 1 verifies block validity
* - level 2 verifies undo data
* - level 3 checks disconnection of tip blocks
* - level 4 tries to reconnect the blocks
* - each level includes the checks of the previous levels
* @param {number} nblocks The number of blocks to check.
*/
export const Verifychain = (
checklevel?: number,
nblocks?: number
): Promise<boolean> => Do("Verifychain", checklevel, nblocks);
/////////////////////////////////////////
// RPC: verifymessage
//
/**
* Verify a signed message
*
* @param {string} address The bitcoin address to use for the signature.
* @param {string} signature The signature provided by the signer in base 64 encoding (see signmessage).
* @param {string} message The message that was signed.
*/
export const Verifymessage = (
address: string,
signature: string,
message: string
): Promise<boolean> => Do("Verifymessage", address, signature, message);
/////////////////////////////////////////
// RPC: verifytxoutproof
//
/**
* Verifies that a proof points to a transaction in a block, returning the transaction it commits to
*
* and throwing an RPC error if the block is not in our best chain
*
* @param {string} proof The hex-encoded proof generated by gettxoutproof
*/
export const Verifytxoutproof = (
proof: string
): Promise<string[]> => Do("Verifytxoutproof", proof);
/////////////////////////////////////////
// RPC: waitforblock
//
export interface WaitforblockResult {
/** The blockhash */
hash: string;
/** Block height */
height: number;
}
/**
* Waits for a specific new block and returns useful info about it
*
*
* Returns the current block on timeout or exit.
*
* @param {string} blockhash Block hash to wait for.
* @param {number} timeout Time in milliseconds to wait for a response. 0 indicates no timeout.
*/
export const Waitforblock = (
blockhash: string,
timeout?: number
): Promise<WaitforblockResult> => Do("Waitforblock", blockhash, timeout);
/////////////////////////////////////////
// RPC: waitforblockheight
//
export interface WaitforblockheightResult {
/** The blockhash */
hash: string;
/** Block height */
height: number;
}
/**
* Waits for (at least) block height and returns the height and hash
*
* of the current tip.
*
* Returns the current block on timeout or exit.
*
* @param {number} height Block height to wait for.
* @param {number} timeout Time in milliseconds to wait for a response. 0 indicates no timeout.
*/
export const Waitforblockheight = (
height: number,
timeout?: number
): Promise<WaitforblockheightResult> => Do("Waitforblockheight", height, timeout);
/////////////////////////////////////////
// RPC: waitfornewblock
//
export interface WaitfornewblockResult {
/** The blockhash */
hash: string;
/** Block height */
height: number;
}
/**
* Waits for a specific new block and returns useful info about it
*
*
* Returns the current block on timeout or exit.
*
* @param {number} timeout Time in milliseconds to wait for a response. 0 indicates no timeout.
*/
export const Waitfornewblock = (
timeout?: number
): Promise<WaitfornewblockResult> => Do("Waitfornewblock", timeout);
/////////////////////////////////////////
// RPC: walletcreatefundedpsbt
//
export interface WalletcreatefundedpsbtResult {
/** The resulting raw transaction (base64-encoded string) */
psbt: string;
/** Fee in BTC the resulting transaction pays */
fee: string;
/** The position of the added change output, or -1 */
changepos: number;
}
export interface WalletcreatefundedpsbtInput {
/** The transaction id */
txid: string;
/** The output number */
vout: number;
/** The sequence number */
sequence?: number;
}
export interface WalletcreatefundedpsbtOutputAlt {
/** A key-value pair. The key must be "data", the value is hex-encoded data */
data: string;
}
/**
* The outputs (key-value pairs), where none of the keys are duplicated
*
* That is, each address can only appear once and there can only be one 'data' object.
* For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also
* accepted as second parameter.
*/
export type WalletcreatefundedpsbtOutput = Dict<number | string> | WalletcreatefundedpsbtOutputAlt;
export interface WalletcreatefundedpsbtOptions {
/** If inputs are specified, automatically include more if they are not enough. */
add_inputs?: boolean;
/** The bitcoin address to receive the change */
changeAddress?: string;
/** The index of the change output */
changePosition?: number;
/**
* The output type to use. Only valid if changeAddress is not specified. Options are "legacy", "p2sh-segwit",
* and "bech32".
*/
change_type?: string;
/** Also select inputs which are watch only */
includeWatching?: boolean;
/** Lock selected unspent outputs */
lockUnspents?: boolean;
/** Specify a fee rate in sat/vB. */
fee_rate?: number | string;
/** Specify a fee rate in BTC/kvB. */
feeRate?: number | string;
/**
* The outputs to subtract the fee from.
* The fee will be equally deducted from the amount of each specified output.
* Those recipients will receive less bitcoins than you enter in their corresponding amount field.
* If no outputs are specified here, the sender pays the fee.
*/
subtractFeeFromOutputs?: number[];
/**
* Marks this transaction as BIP125 replaceable.
* Allows this transaction to be replaced by a transaction with higher fees
*/
replaceable?: boolean;
/** Confirmation target in blocks */
conf_target?: number;
/**
* The fee estimate mode, must be one of (case insensitive):
* "unset"
* "economical"
* "conservative"
*/
estimate_mode?: string;
}
/**
* Creates and funds a transaction in the Partially Signed Transaction format
*
* Implements the Creator and Updater roles.
*
* @param {WalletcreatefundedpsbtInput[]} inputs Leave empty to add inputs automatically. See add_inputs
* option.
* @param {WalletcreatefundedpsbtOutput} outputs The outputs (key-value pairs), where none of the keys
* are
* duplicated.
* That is, each address can only appear once and there can only be one 'data' object.
* For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also
* accepted as second parameter.
* @param {number} locktime Raw locktime. Non-0 value also locktime-activates inputs
* @param {WalletcreatefundedpsbtOptions} options
* @param {boolean} bip32derivs Include BIP 32 derivation paths for public keys if we know them
*/
export const Walletcreatefundedpsbt = (
inputs: WalletcreatefundedpsbtInput[],
outputs: WalletcreatefundedpsbtOutput,
locktime?: number,
options?: WalletcreatefundedpsbtOptions,
bip32derivs?: boolean
): Promise<WalletcreatefundedpsbtResult> => Do("Walletcreatefundedpsbt", inputs, outputs, locktime, options,
bip32derivs);
/////////////////////////////////////////
// RPC: walletlock
//
/**
* Removes the wallet encryption key from memory, locking the wallet
*
* After calling this method, you will need to call walletpassphrase again
* before being able to call any methods which require the wallet to be unlocked.
*/
export const Walletlock = (): Promise<void> => Do("Walletlock");
/////////////////////////////////////////
// RPC: walletpassphrase
//
/**
* Stores the wallet decryption key in memory for 'timeout' seconds
*
* This is needed prior to performing transactions related to private keys such as sending bitcoins
*
* Note:
* Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock
* time that overrides the old one.
*
* @param {string} passphrase The wallet passphrase
* @param {number} timeout The time to keep the decryption key in seconds; capped at 100000000 (~3 years).
*/
export const Walletpassphrase = (
passphrase: string,
timeout: number
): Promise<void> => Do("Walletpassphrase", passphrase, timeout);
/////////////////////////////////////////
// RPC: walletpassphrasechange
//
/**
* Changes the wallet passphrase from 'oldpassphrase' to 'newpassphrase'
*
*
* @param {string} oldpassphrase The current passphrase
* @param {string} newpassphrase The new passphrase
*/
export const Walletpassphrasechange = (
oldpassphrase: string,
newpassphrase: string
): Promise<void> => Do("Walletpassphrasechange", oldpassphrase, newpassphrase);
/////////////////////////////////////////
// RPC: walletprocesspsbt
//
export interface WalletprocesspsbtResult {
/** The base64-encoded partially signed transaction */
psbt: string;
/** If the transaction has a complete set of signatures */
complete: boolean;
}
/**
* Update a PSBT with input information from our wallet and then sign inputs
*
* that we can sign for.
* Requires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.
*
* @param {string} psbt The transaction base64 string
* @param {boolean} sign Also sign the transaction when updating
* @param {string} sighashtype The signature hash type to sign with if not specified by the PSBT. Must
* be
* one of
* "ALL"
* "NONE"
* "SINGLE"
* "ALL|ANYONECANPAY"
* "NONE|ANYONECANPAY"
* "SINGLE|ANYONECANPAY"
* @param {boolean} bip32derivs Include BIP 32 derivation paths for public keys if we know them
*/
export const Walletprocesspsbt = (
psbt: string,
sign?: boolean,
sighashtype?: string,
bip32derivs?: boolean
): Promise<WalletprocesspsbtResult> => Do("Walletprocesspsbt", psbt, sign, sighashtype, bip32derivs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment