THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

Bitcoin Core RPC with curl: JSON Requests, Errors, and Safe Automation

permalink THAMER
#automation#bitcoin-core-curl-rpc#idempotency#json-rpc-errors

curl is a useful tool for testing Bitcoin Core RPC without building a client library. Production integrations need stronger controls than a successful one-line example: authentication, structured error handling, timeouts, secret hygiene, and careful treatment of state-changing calls.

A minimal read-only request

With Bitcoin Core running locally and cookie authentication available, the following example reads the authentication cookie without printing it:

COOKIE="$HOME/.bitcoin/.cookie"
curl --fail-with-body --silent --show-error \
  --max-time 15 \
  --user "$(cat "$COOKIE")" \
  -H 'content-type: text/plain;' \
  --data-binary '{"jsonrpc":"1.0","id":"tip","method":"getblockcount","params":[]}' \
  http://127.0.0.1:8332/

This example is intended for a trusted local shell. Command-line authentication arguments may still be exposed to local process inspection on some systems. A hardened service should use protected credential handling and least-privilege execution. Adjust the cookie path and RPC port for the network and configured data directory.

JSON-RPC success is not only HTTP 200

Inspect both the HTTP outcome and the JSON body. A method can return an RPC error object, and a network timeout can occur after the server performed an operation. JSON parsers should check the error field before consuming result, and preserve the request id to correlate concurrent calls.

Avoid blind retries on sends

A read-only call such as getblockcount can generally be retried after a transient failure. A spending call is different: if the response is lost, repeating the call may create another transaction. Before retrying, reconcile wallet transactions and transaction identifiers. An application-level idempotency mechanism may be required.

Parameter handling

Use a real JSON encoder for variable data rather than concatenating untrusted strings. Validate satoshi/BTC units, addresses, chain/network selection, fee parameters, and wallet context. Do not confuse decimal BTC amounts with integer satoshis; Bitcoin Core RPC methods vary in the units and formats they accept or return.

Protect the interface

Keep RPC on loopback or behind a secured access boundary. Apply timeouts, authentication, least-privilege filesystem access, and log redaction. Do not expose RPC through a public reverse proxy without a separate, carefully designed authorization layer.

Primary references

Bitcoin Core JSON-RPC documentation: https://github.com/bitcoin/bitcoin/blob/master/doc/JSON-RPC-interface.md

Bitcoin Core RPC reference: https://bitcoincore.org/en/doc/

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects