Class: BitcoinCoreRpcClient ​
Defined in: packages/bitcoin/src/client/rpc/index.ts:38
Class representing a Bitcoin Core RPC client. BitcoinCoreRpcClient
Implements ​
Implements ​
Constructors ​
Constructor ​
new BitcoinCoreRpcClient(
config):BitcoinCoreRpcClient
Defined in: packages/bitcoin/src/client/rpc/index.ts:51
Constructs a new BitcoinCoreRpcClient instance from a new RpcClient | RpcClient.
Parameters ​
config ​
The bitcoin-core client instance.
Returns ​
BitcoinCoreRpcClient
Example ​
import BitcoinRpcClient from '@did-btcr2/method';
const bob = BitcoinRpcClient.connect(); // To use default polar config, pass no args. Polar must run locally.Accessors ​
client ​
Get Signature ​
get client():
JsonRpcTransport
Defined in: packages/bitcoin/src/client/rpc/index.ts:80
Get the client for the current BitcoinRpcClient object.
Example ​
const alice = BitcoinRpcClient.connect();
const config = alice.client;Returns ​
The encapsulated RpcClient object.
config ​
Get Signature ​
get config():
BitcoinRpcClientConfig
Defined in: packages/bitcoin/src/client/rpc/index.ts:66
Get the config for the current BitcoinRpcClient object.
Example ​
import BitcoinRpcClient from '@did-btcr2/method';
const alice = BitcoinRpcClient.connect();
const config = alice.config;Returns ​
The encapsulated BitcoinRpcClient object.
Methods ​
createRawTransaction() ​
createRawTransaction(
inputs,outputs,locktime?,replacable?):Promise<string>
Defined in: packages/bitcoin/src/client/rpc/index.ts:323
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.
Parameters ​
inputs ​
The inputs to the transaction (required).
outputs ​
The outputs of the transaction (required).
locktime? ​
number
The locktime of the transaction (optional).
replacable? ​
boolean
Whether the transaction is replaceable (optional).
Returns ​
Promise<string>
The hex-encoded raw transaction.
Implementation of ​
BitcoinRpcClient.createRawTransaction
createSignSendRawTransaction() ​
createSignSendRawTransaction(
inputs,outputs):Promise<string>
Defined in: packages/bitcoin/src/client/rpc/index.ts:297
Combines calls to createRawTransaction, signRawTransaction and sendRawTransaction.
Parameters ​
inputs ​
The inputs to the transaction (required).
outputs ​
The outputs of the transaction (required).
Returns ​
Promise<string>
A promise resolving to the transaction hash in hex.
deriveAddresses() ​
deriveAddresses(
descriptor,range?):Promise<DerivedAddresses[]>
Defined in: packages/bitcoin/src/client/rpc/index.ts:350
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 output script equals the specified hex-encoded bytes tr(<pubkey>,multi_a(<n>,<pubkey>,<pubkey>,...)) P2TR-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 "/", where "h" represents a hardened child key.
See github.com/bitcoin/bitcoin/descriptors.md for more information.
Parameters ​
descriptor ​
string
The descriptor.
range? ​
number[]
If descriptor is ranged, must specify end or [begin,end] to derive.
Returns ​
Promise<DerivedAddresses[]>
a list of derived addresses
Example ​
const bitcoind = BitcoinRpcClient.connect()
const addresses = bitcoind.deriveAddresses("wpkh([d34db33f/84h/0h/0h]xpub6DJ2dN.../0/*)#cjjspncu", [0,2])getBalance() ​
getBalance():
Promise<number>
Defined in: packages/bitcoin/src/client/rpc/index.ts:360
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.
Returns ​
Promise<number>
A promise resolving to the total available balance in BTC.
getBlock() ​
getBlock(
params):Promise<BlockResponse|undefined>
Defined in: packages/bitcoin/src/client/rpc/index.ts:199
Returns the block data associated with a blockhash of a valid block.
Parameters ​
params ​
See GetBlockParams for details.
Returns ​
Promise<BlockResponse | undefined>
A promise resolving to a BlockResponse formatted depending on verbosity level.
Throws ​
If neither blockhash nor height is provided.
Implementation of ​
getBlockchainInfo() ​
getBlockchainInfo():
Promise<ChainInfo>
Defined in: packages/bitcoin/src/client/rpc/index.ts:246
Returns an object containing various blockchain state info.
Returns ​
Promise<ChainInfo>
Implementation of ​
BitcoinRpcClient.getBlockchainInfo
getBlockCount() ​
getBlockCount():
Promise<number>
Defined in: packages/bitcoin/src/client/rpc/index.ts:232
Returns the blockheight of the most-work fully-validated chain. The genesis block has height 0.
Returns ​
Promise<number>
The number of the blockheight with the most-work of the fully-validated chain.
Implementation of ​
BitcoinRpcClient.getBlockCount
getBlockHash() ​
getBlockHash(
height):Promise<string>
Defined in: packages/bitcoin/src/client/rpc/index.ts:239
Returns the blockhash of the block at the given height in the active chain.
Parameters ​
height ​
number
Returns ​
Promise<string>
Implementation of ​
getNewAddress() ​
getNewAddress(
addressType,label?):Promise<string>
Defined in: packages/bitcoin/src/client/rpc/index.ts:372
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'. The 'address_type' can be one of "legacy", "p2sh-segwit", "bech32", or "bech32m".
Parameters ​
addressType ​
string
The address type to use (required, options=["legacy", "p2sh-segwit", "bech32", "bech32m"], default="bech32").
label? ​
string
The label to associate with the new address (optional).
Returns ​
Promise<string>
A promise resolving to the new address.
Implementation of ​
BitcoinRpcClient.getNewAddress
getRawTransaction() ​
getRawTransaction(
txid,verbosity?,blockhash?):Promise<RawTransactionResponse>
Defined in: packages/bitcoin/src/client/rpc/index.ts:449
Get detailed information about a transaction. By default, this call only returns a transaction if it is in the mempool. If -txindex is enabled and no blockhash argument is passed, it will return the transaction if it is in the mempool or any block. If a blockhash argument is passed, it will return the transaction if the specified block is available and the transaction is in that block.
Parameters ​
txid ​
string
The transaction id (required).
verbosity? ​
Response format: 0 (hex), 1 (json) or 2 (jsonext).
blockhash? ​
string
The block in which to look for the transaction (optional).
Returns ​
Promise<RawTransactionResponse>
A promise resolving to data about a transaction in the form specified by verbosity.
getRawTransactions() ​
getRawTransactions(
txids,verbosity?):Promise<RawTransactionResponse[]>
Defined in: packages/bitcoin/src/client/rpc/index.ts:471
Get detailed information about multiple transactions. An extension of getRawTransaction.
Parameters ​
txids ​
string[]
An array of transaction ids.
verbosity? ​
Response format: 0 (hex), 1 (json) or 2 (jsonext).
Returns ​
Promise<RawTransactionResponse[]>
getTransaction() ​
getTransaction(
txid,include_watchonly?):Promise<WalletTransaction>
Defined in: packages/bitcoin/src/client/rpc/index.ts:434
Get detailed information about in-wallet transaction <txid>.
Parameters ​
txid ​
string
include_watchonly? ​
boolean
Whether to include watch-only addresses in balance calculation and details.
Returns ​
Promise<WalletTransaction>
A promise resolving to a WalletTransaction object.
isJsonRpcError() ​
isJsonRpcError(
e):e is Error & { code?: number; name: "RpcError" }
Defined in: packages/bitcoin/src/client/rpc/index.ts:128
Check if the given error is a JSON-RPC error.
Parameters ​
e ​
unknown
The error to check.
Returns ​
e is Error & { code?: number; name: "RpcError" }
True if the error is a JSON-RPC error, false otherwise.
listTransactions() ​
listTransactions(
params):Promise<ListTransactionsResult>
Defined in: packages/bitcoin/src/client/rpc/index.ts:307
TODO: Comments
Parameters ​
params ​
Returns ​
Promise<ListTransactionsResult>
listUnspent() ​
listUnspent(
params):Promise<UnspentTxInfo[]>
Defined in: packages/bitcoin/src/client/rpc/index.ts:386
Returns array of unspent transaction outputs with between minconf and maxconf (inclusive) confirmations. Optionally filter to only include txouts paid to specified addresses.
Parameters ​
params ​
The parameters for the listUnspent command.
address? ​
string[]
Only include outputs paid to these addresses.
include_unsafe? ​
boolean
Whether to include outputs that are not safe to spend.
maxconf? ​
number
The maximum number of confirmations an output can have to be included.
minconf? ​
number
The minimum number of confirmations an output must have to be included.
Returns ​
Promise<UnspentTxInfo[]>
A promise resolving to an array of UnspentTxInfo objects.
sendRawTransaction() ​
sendRawTransaction(
hexstring,maxfeerate?,maxBurnAmount?):Promise<string>
Defined in: packages/bitcoin/src/client/rpc/index.ts:272
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.
Parameters ​
hexstring ​
string
The hex-encoded transaction to send.
maxfeerate? ​
If not passed, default is 0.10.
string | number
maxBurnAmount? ​
string | number
Returns ​
Promise<string>
A promise resolving to the transaction hash in hex.
Implementation of ​
BitcoinRpcClient.sendRawTransaction
sendToAddress() ​
sendToAddress(
address,amount):Promise<RawTransactionV2>
Defined in: packages/bitcoin/src/client/rpc/index.ts:402
Send an amount to a given address.
Parameters ​
address ​
string
The address to send to.
amount ​
number
The amount to send in BTC.
Returns ​
Promise<RawTransactionV2>
A promise resolving to the transaction id.
Implementation of ​
BitcoinRpcClient.sendToAddress
signAndSendRawTransaction() ​
signAndSendRawTransaction(
hexstring):Promise<string>
Defined in: packages/bitcoin/src/client/rpc/index.ts:286
Combines calls to signRawTransaction and sendRawTransaction.
Parameters ​
hexstring ​
string
Returns ​
Promise<string>
A promise resolving to the transaction hash in hex.
signMessage() ​
signMessage(
address,message):Promise<string>
Defined in: packages/bitcoin/src/client/rpc/index.ts:413
Sign a message with the private key of an address.
Parameters ​
address ​
string
The address to sign the message with.
message ​
string
The message to sign.
Returns ​
Promise<string>
A promise resolving to the signature in base64.
Implementation of ​
signRawTransaction() ​
signRawTransaction(
hexstring):Promise<SignedRawTx>
Defined in: packages/bitcoin/src/client/rpc/index.ts:257
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.
Parameters ​
hexstring ​
string
The hex-encoded transaction to send.
Returns ​
Promise<SignedRawTx>
verifyMessage() ​
verifyMessage(
address,signature,message):Promise<boolean>
Defined in: packages/bitcoin/src/client/rpc/index.ts:424
Verify a signed message.
Parameters ​
address ​
string
The address to verify the message with.
signature ​
string
The signature to verify in base64.
message ​
string
The message to verify.
Returns ​
Promise<boolean>
A promise resolving to true if the signature is valid, false otherwise.
Implementation of ​
BitcoinRpcClient.verifyMessage
connect() ​
staticconnect(config?):BitcoinCoreRpcClient
Defined in: packages/bitcoin/src/client/rpc/index.ts:119
Static method connects to a bitcoin node running the bitcoin core daemon (bitcoind). To use default polar config, do not pass a config. See DEFAULT_BITCOIN_NETWORK_CONFIG for default config.
Parameters ​
config? ​
The configuration object for the client (optional).
Returns ​
BitcoinCoreRpcClient
A new BitcoinRpcClient instance.
Required ​
A locally running Polar Lightning regtest node.
Example ​
const alice = BitcoinRpcClient.connect();initialize() ​
staticinitialize(config?):BitcoinRpcClientConfig
Defined in: packages/bitcoin/src/client/rpc/index.ts:103
Static method initializes a new BitcoinCoreRpcClient client with the given configuration. The RpcClient returned by this method does not have any named methods. Use this method to create and pass a new RpcClient instance to a BitcoinCoreRpcClient constructor.
Parameters ​
config? ​
The configuration object for the client (optional).
Returns ​
A new RpcClient instance.
Example ​
const options: RpcClientConfig = {
host: 'http://localhost:18443',
username: 'alice',
password: 'alicepass',
version: '28.1.0',
}
const alice = BitcoinCoreRpcClient.initialize(options); // Client config required