api.md raw

RPC API Specification

Version: 2.0.1 =======

Note: This document assumes the reader is familiar with gRPC concepts. Refer to the gRPC Concepts documentation for any unfamiliar terms.

Note: The naming style used for autogenerated identifiers may differ depending on the language being used. This document follows the naming style used by Google in their Protocol Buffers and gRPC documentation as well as this project's .proto files. That is, CamelCase is used for services, methods, and messages, lowersnakecase for message fields, and SCREAMINGSNAKECASE for enums.

Note: The entierty of the RPC API is currently considered unstable and may change anytime. Stability will be gradually added based on correctness, perceived usefulness and ease-of-use over alternatives, and user feedback.

This document is the authoritative source on the RPC API's definitions and semantics. Any divergence from this document is an implementation error. API fixes and additions require a version increase according to the rules of Semantic Versioning 2.0.0.

Only optional proto3 message fields are used (the required keyword is never used in the .proto file). If a message field must be set to something other than the default value, or any other values are invalid, the error must occur in the application's message handling. This prevents accidentally introducing parsing errors if a previously optional field is missing or a new required field is added.

Functionality is grouped into gRPC services. Depending on what functions are currently callable, different services will be running. As an example, the server may be running without a loaded wallet, in which case the Wallet service is not running and the Loader service must be used to create a new or load an existing wallet.

VersionService

The VersionService service provides the caller with versioning information regarding the RPC server. It has no dependencies and is always running.

Methods:

Methods

Version

The Version method returns the RPC server version. Versioning follows the rules of Semantic Versioning (SemVer) 2.0.0.

Request: VersionRequest

Response: VersionResponse

Expected errors: None

Stability: Stable

LoaderService

The LoaderService service provides the caller with functions related to the management of the wallet and its connection to the Bitcoin network. It has no dependencies and is always running.

Methods:

Shared messages:

Methods

WalletExists

The WalletExists method returns whether a file at the wallet database's file path exists. Clients that must load wallets with this service are expected to call this RPC to query whether OpenWallet should be used to open an existing wallet, or CreateWallet to create a new wallet.

Request: WalletExistsRequest

Response: WalletExistsResponse

Expected errors: None

Stability: Unstable

CreateWallet

The CreateWallet method is used to create a wallet that is protected by two levels of encryption: the public passphrase (for data that is made public on the blockchain) and the private passphrase (for private keys). Since the seed is not saved in the wallet database and clients should make their users backup the seed, it needs to be passed as part of the request.

After creating a wallet, the WalletService service begins running.

Request: CreateWalletRequest

encryption. This passphrase protects data that is made public on the blockchain. If this passphrase has zero length, an insecure default is used instead.

encryption. This is the passphrase used for data that must always remain private, such as private keys. The length of this field must not be zero.

this field must be between 16 and 64 bytes, inclusive.

Response: CreateWalletReponse

Expected errors:

the seed is of incorrect length.

Stability: Unstable: There needs to be a way to recover all keys and transactions of a wallet being recovered by its seed. It is unclear whether it should be part of this method or a WalletService method.

OpenWallet

The OpenWallet method is used to open an existing wallet database. If the wallet is protected by a public passphrase, it can not be successfully opened if the public passphrase parameter is missing or incorrect.

After opening a wallet, the WalletService service begins running.

Request: OpenWalletRequest

encryption. This passphrase protects data that is made public on the blockchain. If this passphrase has zero length, an insecure default is used instead.

Response: OpenWalletResponse

Expected errors:

Stability: Unstable

CloseWallet

The CloseWallet method is used to cleanly stop all wallet operations on a loaded wallet and close the database. After closing, the WalletService service will remain running but any operations that require the database will be unusable.

Request: CloseWalletRequest

Response: CloseWalletResponse

Expected errors:

Stability: Unstable: It would be preferable to stop the WalletService after closing, but there does not appear to be any way to do so currently. It may also be a good idea to limit under what conditions a wallet can be closed, such as only closing wallets loaded by LoaderService and/or using a secret to authenticate the operation.

StartConsensusRPC

The StartConsensusRPC method is used to provide clients the ability to dynamically start the pod RPC client. This RPC client is used for wallet syncing and publishing transactions to the Bitcoin network.

Request: StartConsensusRPCRequest

connect to. IP addresses may be IPv4 or IPv6. If the port is missing, a default port is chosen corresponding to the default pod RPC port of the active Bitcoin network.

server.

has zero length and the network address describes a loopback connection (localhost, 127.0.0.1, or ::1) TLS will be disabled.

Response: StartConsensusRPCResponse

Expected errors:

valid IP address.

return Unavailable as that refers to LoaderService itself being unavailable.

condition may not be return Unauthenticated as that refers to the client not having the credentials to call this method.

Stability: Unstable: It is unknown if the consensus RPC client will remain used after the project gains SPV support.

WalletService

The WalletService service provides RPCs for the wallet itself. The service depends on a loaded wallet and does not run when the wallet has not been created or opened yet.

The service provides the following methods:

Ping

The Ping method checks whether the service is active.

Request: PingRequest

Response: PingResponse

Expected errors: None

Stability: Unstable: This may be moved to another service as it does not depend on the wallet.

Network

The Network method returns the network identifier constant describing the server's active network.

Request: NetworkRequest

Response: NetworkResponse

Expected errors: None

Stability: Unstable: This may be moved to another service as it does not depend on the wallet.

AccountNumber

The AccountNumber method looks up a BIP0044 account number by an account's unique name.

Request: AccountNumberRequest

Response: AccountNumberResponse

Expected errors:

Stability: Unstable

Accounts

The Accounts method returns the current properties of all accounts managed in the wallet.

Request: AccountsRequest

Response: AccountsResponse

message types, one per account, ordered by increasing account numbers.

Nested message: Account

- uint32 account_number: The BIP0044 account number.

- string account_name: The name of the account.

- int64 total_balance: The total (zero-conf and immature) balance, counted in Satoshis.

- uint32 external_key_count: The number of derived keys in the external key chain.

- uint32 internal_key_count: The number of derived keys in the internal key chain.

- uint32 imported_key_count: The number of imported keys.

synced with.

be synced with.

Expected errors:

Stability: Unstable

Balance

The Balance method queries the wallet for an account's balance. Balances are returned as combination of total, spendable (by consensus and request policy), and unspendable immature coinbase balances.

Request: BalanceRequest

unspent transaction output's value is included in the spendable balance. This may not be negative.

Response: BalanceResponse

Satoshis.

confirmations, counted in Satoshis. This equals the total balance when the required number of confirmations is zero and there are no immature coinbase outputs.

counted in Satoshis.

Expected errors:

Stability: Unstable: It may prove useful to modify this RPC to query multiple accounts together.

GetTransactions

The GetTransactions method queries the wallet for relevant transactions. The query set may be specified using a block range, inclusive, with the heights or hashes of the minimum and maximum block. Transaction results are grouped grouped by the block they are mined in, or grouped together with other unmined transactions.

Request: GetTransactionsRequest

transactions from. If this field is set to the default, the starting_block_height field is used instead. If changed, the byte array must have length 32 and starting_block_height must be zero.

transactions from. If this field is non-zero, starting_block_hash must be set to its default value to avoid ambiguity. If positive, the field is interpreted as a block height. If negative, the height is subtracted from the block wallet considers itself in sync with.

transactions from. If this default is set to the default, the ending_block_height field is used instead. If changed, the byte array must have length 32 and ending_block_height must be zero.

transactions from. If non-zero, the ending_block_hash field must be set to its default value to avoid ambiguity. If both this field and ending_block_hash are set to their default values, no upper block limit is used and transactions through the best block and all unmined transactions are included.

Response: GetTransactionsResponse

by blocks in the order they appear in the blockchain.

The BlockDetails message is used by other methods and is documented here.

The ordering is unspecified.

The TransactionDetails message is used by other methods and is documented here.

Expected errors:

length.

wallet.

Stability: Unstable

block range is specified.

the most recent transaction, but it is unclear if that should be added to this method's request object, or to make a new method.

transactions would be useful.

ChangePassphrase

The ChangePassphrase method requests a change to either the public (outer) or private (inner) encryption passphrases.

Request: ChangePassphraseRequest

Nested enum: Key

- PRIVATE: The request specifies to change the private (inner) encryption passphrase.

- PUBLIC: The request specifies to change the public (outer) encryption passphrase.

the value being modified. If the public passphrase is being modified and this value is the default value, an insecure default is used instead.

zero length if the public passphrase is being changed, in which case an insecure default will be used instead.

Response: ChangePassphraseResponse

Expected errors:

private passphrase, or the old passphrase was incorrect.

Stability: Unstable

RenameAccount

The RenameAccount method requests a change to an account's name property.

Request: RenameAccountRequest

Response: RenameAccountResponse

Expected errors:

Stability: Unstable: There should be a way to specify a starting block or time to begin the rescan at. Additionally, since the client is expected to be able to do asynchronous RPC, it may be useful for the response to block on the rescan finishing before returning.

NextAccount

The NextAccount method generates the next BIP0044 account for the wallet.

Request: NextAccountRequest

account's key.

Response: NextAccountResponse

Expected errors:

Stability: Unstable

NextAddress

The NextAddress method generates the next deterministic address for the wallet.

Request: NextAddressRequest

Nested enum: Kind

- BIP0044_EXTERNAL: The request specifies to generate the next address for the account's BIP0044 external key chain.

- BIP0044_INTERNAL: The request specifies to generate the next address for the account's BIP0044 internal key chain.

Response: NextAddressResponse

Expected errors:

Stability: Unstable

ImportPrivateKey

The ImportPrivateKey method imports a private key in Wallet Import Format (WIF) encoding to a wallet account. A rescan may optionally be started to search for transactions involving the private key's associated payment address.

Request: ImportPrivateKeyRequest

key.

Response: ImportPrivateKeyResponse

Expected errors:

Stability: Unstable

FundTransaction

The FundTransaction method queries the wallet for unspent transaction outputs controlled by some account. Results may be refined by setting a target output amount and limiting the required confirmations. The selection algorithm is unspecified.

Output results are always created even if a minimum target output amount could not be reached. This allows this method to behave similar to the Balance method while also including the outputs that make up that balance.

Change outputs can optionally be returned by this method as well. This can provide the caller with everything necessary to construct an unsigned transaction paying to already known addresses or scripts.

Request: FundTransactionRequest

set to query.

those that sum to at least this amount (counted in Satoshis). If zero, all outputs not excluded by other arguments are returned. This may not be negative.

needed to consider including an output in the return set. This may not be negative.

also be included.

response object.

Response: FundTransactionResponse

of PreviousOutput nested message objects.

Nested message: PreviousOutput

- bytes transaction_hash: The hash of the transaction this output originates from.

- uint32 output_index: The output index of the transaction this output originates from.

- int64 amount: The output value (counted in Satoshis) of the unspent transaction output.

- bytes pk_script: The output script of the unspent transaction output.

- int64 receive_time: The earliest Unix time the wallet became aware of the transaction containing this output.

- bool from_coinbase: Whether the output is a coinbase output.

than a positive target amount if there were not enough eligible outputs available.

remaining amount to a newly-generated change address for the account. This is null if include_change_script was false or the target amount was not exceeded.

Expected errors:

Stability: Unstable

SignTransaction

The SignTransaction method adds transaction input signatures to a serialized transaction using a wallet private keys.

Request: SignTransactionRequest

be created for. If there are no indexes, input scripts are created for every input that is missing an input script.

Response: SignTransactionResponse

input script could not be created for.

Expected errors:

Stability: Unstable: It is unclear if the request should include an account, and only secrets of that account are used when creating input scripts. It's also missing options similar to Core's signrawtransaction, such as the sighash flags and additional keys.

PublishTransaction

The PublishTransaction method publishes a signed, serialized transaction to the Bitcoin network. If the transaction spends any of the wallet's unspent outputs or creates a new output controlled by the wallet, it is saved by the wallet and republished later if it or a double spend are not mined.

Request: PublishTransactionRequest

Response: PublishTransactionResponse

Expected errors:

input scripts.

Stability: Unstable

TransactionNotifications

The TransactionNotifications method returns a stream of notifications regarding changes to the blockchain and transactions relevant to the wallet.

Request: TransactionNotificationsRequest

Response: stream TransactionNotificationsResponse

chain, sorted by increasing height. All newly mined transactions are included in these messages, in the message corresponding to the block that contains them. If this field has zero length, the notification is due to an unmined transaction being added to the wallet.

The BlockDetails message is used by other methods and is documented here.

reorganized out of the main chain. These are sorted by heights in decreasing order (newest blocks first).

transactions. When relevant transactions are reorganized out and not included in (or double-spent by) the new chain, they are included here.

The TransactionDetails message is used by other methods and is documented here.

currently-unmined transaction. This differs from the unmined_transactions field by including every unmined transaction, rather than those newly added to the unmined set.

Expected errors:

Stability: Unstable: This method could use a better name.

SpentnessNotifications

The SpentnessNotifications method returns a stream of notifications regarding the spending of unspent outputs and/or the discovery of new unspent outputs for an account.

Request: SpentnessNotificationsRequest

newly-discovered unspent outputs controlled by the account.

transactions controlled by the account.

Response: stream SpentnessNotificationsResponse

the output being reported.

If not null, the message records the transaction input that spends the previously-unspent output.

Nested message: Spender

- bytes transaction_hash: The hash of the serialized transaction that spends the reported output.

- uint32 input_index: The index of the input that spends the reported output.

Expected errors:

fields are both true.

Stability: Unstable

AccountNotifications

The AccountNotifications method returns a stream of notifications for account property changes, such as name and key counts.

Request: AccountNotificationsRequest

Response: stream AccountNotificationsResponse

derived for the account.

derived for the account.

the account.

Expected errors:

Stability: Unstable: This should probably share a message with the Accounts method.

Shared messages

The following messages are used by multiple methods. To avoid unnecessary duplication, they are documented once here.

BlockDetails

The BlockDetails message is included in responses to report a block and the wallet's relevant transactions contained therein.

wallet that are mined in this block. Transactions are sorted by their block index in increasing order.

The TransactionDetails message is used by other methods and is documented here.

Stability: Unstable: This should probably include the block version.

TransactionDetails

The TransactionDetails message is included in responses to report transactions relevant to the wallet. The message includes details such as which previous wallet inputs are spent by this transaction, whether each output is controlled by the wallet or not, the total fee (if calculable), and the earlist time the transaction was seen.

spent by this transaction.

Nested message: Input

- uint32 index: The transaction input index of the input being reported.

- uint32 previous_account: The account that controlled the now-spent output.

- int64 previous_amount: The previous output value.

wallet.

Nested message: Output

- uint32 index: The transaction output index of the output being reported.

- uint32 account: The account number of the controlled output.

- bool internal: Whether the output pays to an address derived from the account's internal key series. This often means the output is a change output.

when every previous output spent by this transaction is also recorded by wallet. Otherwise, this field is zero.

seen.

Stability: Unstable: Since the caller is expected to decode the serialized transaction, and would have access to every output script, the output properties could be changed to only include outputs controlled by the wallet.