Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1# JSON-RPC Interface3The headless daemon `bitcoind` has the JSON-RPC API enabled by default, the GUI4`bitcoin-qt` has it disabled by default. This can be changed with the `-server`5option. In the GUI it is possible to execute RPC methods in the Debug Console6Dialog.8## Endpoints10There are two JSON-RPC endpoints on the server:121. `/`132. `/wallet/<walletname>/`15### `/` endpoint17This endpoint is always active.18It can always service non-wallet requests and can service wallet requests when19exactly one wallet is loaded.21### `/wallet/<walletname>/` endpoint23This endpoint is only activated when the wallet component has been compiled in.24It can service both wallet and non-wallet requests.25It MUST be used for wallet requests when two or more wallets are loaded.27This is the endpoint used by bitcoin-cli when a `-rpcwallet=` parameter is passed in.29Best practice would dictate using the `/wallet/<walletname>/` endpoint for ALL30requests when multiple wallets are in use.32### Examples34```sh35# Get block count from the / endpoint when rpcuser=alice and rpcport=3833236$ curl --user alice --data-binary '{"jsonrpc": "2.0", "id": "0", "method": "getblockcount", "params": []}' -H 'content-type: application/json' localhost:38332/38# Get balance from the /wallet/walletname endpoint when rpcuser=alice, rpcport=38332 and rpcwallet=desc-wallet39$ curl --user alice --data-binary '{"jsonrpc": "2.0", "id": "0", "method": "getbalance", "params": []}' -H 'content-type: application/json' localhost:38332/wallet/desc-wallet41```43## Parameter passing45The JSON-RPC server supports both _by-position_ and _by-name_ [parameter46structures](https://www.jsonrpc.org/specification#parameter_structures)47described in the JSON-RPC specification. For extra convenience, to avoid the48need to name every parameter value, all RPC methods accept a named parameter49called `args`, which can be set to an array of initial positional values that50are combined with named values.52Examples:54```sh55# "params": ["mywallet", false, false, "", false, false, true]56bitcoin-cli createwallet mywallet false false "" false false true58# "params": {"wallet_name": "mywallet", "load_on_startup": true}59bitcoin-cli -named createwallet wallet_name=mywallet load_on_startup=true61# "params": {"args": ["mywallet"], "load_on_startup": true}62bitcoin-cli -named createwallet mywallet load_on_startup=true63```65`bitcoin rpc` can also be substituted for `bitcoin-cli -named`, and is a newer alternative.67## Versioning69The RPC interface might change from one major version of Bitcoin Core to the70next. This makes the RPC interface implicitly versioned on the major version.71The version tuple can be retrieved by e.g. the `getnetworkinfo` RPC in72`version`.74Usually deprecated features can be re-enabled during the grace-period of one75major version via the `-deprecatedrpc=` command line option. The release notes76of a new major release come with detailed instructions on what RPC features77were deprecated and how to re-enable them temporarily.79## JSON-RPC 1.1 vs 2.081The server recognizes [JSON-RPC v2.0](https://www.jsonrpc.org/specification) requests82and responds accordingly. A 2.0 request is identified by the presence of83`"jsonrpc": "2.0"` in the request body. If that key + value is not present in a request,84the legacy JSON-RPC v1.1 protocol is followed instead, which was the only available85protocol in v27.0 and prior releases.87|| 1.1 | 2.0 |88|-|-|-|89| Request marker | `"version": "1.1"` (or none) | `"jsonrpc": "2.0"` |90| Response marker | (none) | `"jsonrpc": "2.0"` |91| `"error"` and `"result"` fields in response | both present | only one is present |92| HTTP codes in response | `200` unless there is any kind of RPC error (invalid parameters, method not found, etc) | Always `200` unless there is an actual HTTP server error (request parsing error, endpoint not found, etc) |93| Notifications: requests that get no reply | (not supported) | Supported for requests that exclude the "id" field. Returns HTTP status `204` "No Content" |95## Security97The RPC interface allows other programs to control Bitcoin Core,98including the ability to spend funds from your wallets, affect consensus99verification, read private data, and otherwise perform operations that100can cause loss of money, data, or privacy. This section suggests how101you should use and configure Bitcoin Core to reduce the risk that its102RPC interface will be abused.104- **Securing the executable:** Anyone with physical or remote access to105the computer, container, or virtual machine running Bitcoin Core can106compromise either the whole program or just the RPC interface. This107includes being able to record any passphrases you enter for unlocking108your encrypted wallets or changing settings so that your Bitcoin Core109program tells you that certain transactions have multiple110confirmations even when they aren't part of the best block chain. For111this reason, you should not use Bitcoin Core for security sensitive112operations on systems you do not exclusively control, such as shared113computers or virtual private servers.115- **Securing local network access:** By default, the RPC interface can116only be accessed by a client running on the same computer and only117after the client provides a valid authentication credential (username118and passphrase). Any program on your computer with access to the file119system and local network can obtain this level of access.120Additionally, other programs on your computer can attempt to provide121an RPC interface on the same port as used by Bitcoin Core in order to122trick you into revealing your authentication credentials. For this123reason, it is important to only use Bitcoin Core for124security-sensitive operations on a computer whose other programs you125trust.127- **RPC Credentials Security Boundary:** Any client with valid RPC credentials128should be treated as having significant control over both the Bitcoin Core node129and the filesystem resources accessible by the `bitcoind` process. RPC commands130can load wallet files from paths that the `bitcoind` process has permission to131access, specify file paths for operations, and potentially gain broader access132than intended. This means that someone with RPC access can potentially compromise133not only the Bitcoin Core node, but also the machine it is running on. Bitcoin Core134provides the `-rpcwhitelist` option to restrict which RPC commands specific users135can access, and `-rpcwhitelistdefault` to control the default behavior for users136without explicit whitelists. However, when using multiple wallets or sharing access137with different users, these should not be considered robust security boundaries, as138users with access to certain commands may still be able to exploit functionality in139unexpected ways. For security-sensitive operations, implement proper system-level140isolation (containers, virtualization, separate user accounts with restricted141permissions) rather than relying solely on RPC access controls.143- **Securing remote network access:** You may optionally allow other144computers to remotely control Bitcoin Core by setting the `rpcallowip`145and `rpcbind` configuration parameters. These settings are only meant146for enabling connections over secure private networks or connections147that have been otherwise secured (e.g. using a VPN or port forwarding148with SSH or stunnel). **Do not enable RPC connections over the public149Internet.** Although Bitcoin Core's RPC interface does use150authentication, it does not use encryption, so your login credentials151are sent as clear text that can be read by anyone on your network152path. Additionally, the RPC interface has not been hardened to153withstand arbitrary Internet traffic, so changing the above settings154to expose it to the Internet (even using something like a Tor onion155service) could expose you to unconsidered vulnerabilities. See156`bitcoind -help` for more information about these settings and other157settings described in this document.159Related, if you use Bitcoin Core inside a Docker container, you may160need to expose the RPC port to the host system. The default way to161do this in Docker also exposes the port to the public Internet.162Instead, expose it only on the host system's localhost, for example:163`-p 127.0.0.1:8332:8332`165- **Secure authentication:** By default, when no `rpcpassword` is specified, Bitcoin Core generates unique166login credentials each time it restarts and puts them into a file167readable only by the user that started Bitcoin Core, allowing any of168that user's RPC clients with read access to the file to login169automatically. The file is `.cookie` in the Bitcoin Core170configuration directory, and using these credentials is the preferred171RPC authentication method. If you need to generate static login172credentials for your programs, you can use the script in the173`share/rpcauth` directory in the Bitcoin Core source tree. As a final174fallback, you can directly use manually-chosen `rpcuser` and175`rpcpassword` configuration parameters---but you must ensure that you176choose a strong and unique passphrase (and still don't use insecure177networks, as mentioned above).179- **Secure string handling:** The RPC interface does not guarantee any180escaping of data beyond what's necessary to encode it as JSON,181although it does usually provide serialized data using a hex182representation of the bytes. If you use RPC data in your programs or183provide its data to other programs, you must ensure any problem strings184are properly escaped. For example, the `createwallet` RPC accepts185arguments such as `wallet_name` which is a string and could be used186for a path traversal attack without application level checks. Multiple187websites have been manipulated because they displayed decoded hex strings188that included HTML `<script>` tags. For this reason, and others, it is189recommended to display all serialized data in hex form only.191## RPC consistency guarantees193State that can be queried via RPCs is guaranteed to be at least up-to-date with194the chain state immediately prior to the call's execution. However, the state195returned by RPCs that reflect the mempool may not be up-to-date with the196current mempool state.198### Transaction Pool200The mempool state returned via an RPC is consistent with itself and with the201chain state at the time of the call. Thus, the mempool state only encompasses202transactions that are considered mine-able by the node at the time of the RPC.204The mempool state returned via an RPC reflects all effects of mempool and chain205state related RPCs that returned prior to this call.207### Wallet209The wallet state returned via an RPC is consistent with itself and with the210chain state at the time of the call.212Wallet RPCs will return the latest chain state consistent with prior non-wallet213RPCs. The effects of all blocks (and transactions in blocks) at the time of the214call is reflected in the state of all wallet transactions. For example, if a215block contains transactions that conflicted with mempool transactions, the216wallet would reflect the removal of these mempool transactions in the state.218However, the wallet may not be up-to-date with the current state of the mempool219or the state of the mempool by an RPC that returned before this RPC. For220example, a wallet transaction that was BIP-125-replaced in the mempool prior to221this RPC may not yet be reflected as such in this RPC response.223## Limitations225There is a known issue in the JSON-RPC interface that can cause a node to crash if226too many http connections are being opened at the same time because the system runs227out of available file descriptors. To prevent this from happening you might228want to increase the number of maximum allowed file descriptors in your system229and try to prevent opening too many connections to your JSON-RPC interface at the230same time if this is under your control. It is hard to give general advice231since this depends on your system but if you make several hundred requests at232once you are definitely at risk of encountering this issue.
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.