JSON-RPC API
JSON-RPC API
A complete reference for the Scruple node's cookie-authenticated HTTP JSON-RPC API.
Scruple uses a small custom envelope: {"method":"...","params":{...}} in, {"ok":true,"result":...} or {"ok":false,"error":"..."} out. There is no jsonrpc field and no request id. Every method takes a JSON object (or null) as params, never a positional array.
Transport
| Property | Value |
|---|---|
| Protocol | HTTP/1.1, plaintext (no built-in TLS) |
| Method | POST only. Anything else returns 405 Method Not Allowed. |
| Path | Any path; the server does not route on the URL. Use /. |
| Content type | application/json recommended. The server parses the body as JSON regardless of the header. |
| Content length | Send an accurate Content-Length. Transfer-Encoding is rejected. |
| Connection | The server responds with Connection: close; do not reuse the socket. |
| Default bind | 127.0.0.1:18332 mainnet/devnet, 127.0.0.1:28332 testnet. |
| Concurrency | Up to 64 concurrent RPC connections. |
Because the API is plaintext HTTP, keep the listener on localhost or place it behind a TLS-terminating reverse proxy. The node prints a warning if RPC is bound to a non-loopback address.
Authentication
Every request must present the node's current RPC cookie in one of two forms:
X-Scruple-Cookie: <64-hex-token>
Authorization: Basic <base64("__cookie__:<64-hex-token>")>
The token is generated from 32 random bytes on every node startup and written to <data-dir>/.cookie with mode 0600. An optional --rpc-cookie <PATH> mirror is written with the same mode. The node uses constant-time comparison.
Do not cache the token across node restarts. Re-read <data-dir>/.cookie when a request returns 401 Unauthorized. A stale token produces unauthorized: missing or invalid RPC cookie.
COOKIE=$(cat ./data/.cookie)
# Header form
curl -sS http://127.0.0.1:18332 \
-H "X-Scruple-Cookie: $COOKIE" \
-H 'Content-Type: application/json' \
-d '{"method":"info","params":{}}'
# HTTP Basic form
curl -sS http://127.0.0.1:18332 \
-u "__cookie__:$COOKIE" \
-H 'Content-Type: application/json' \
-d '{"method":"info","params":{}}'
Request and response envelope
A request is a JSON object with a method string and an optional params object. Omitting params is equivalent to {}. A non-object, non-null params is rejected with 'params' must be a JSON object.
{
"method": "get_block",
"params": {
"height": 0,
"verbose": true
}
}
A successful response has ok: true and a result field. A method-level failure has ok: false and an error string. Method-level failures still use HTTP 200 OK; only transport and authentication failures use non-200 status codes.
{
"ok": true,
"result": {
"height": 0,
"hash": "BLOCK_HASH",
"tx_count": 1
}
}
{
"ok": false,
"error": "missing required 'addr_hashes' array (pass an explicit list of 64-char hex address hashes)"
}
Examples in this reference use uppercase placeholders such as TIP_HASH, TXID, and ADDR_HASH where a real 64-character hex value would appear.
Method index
| Method | Purpose | Key parameters |
|---|---|---|
info | Chain, mempool, storage, peer, and network status. | none |
seen_addresses | Which address hashes have ever been seen on-chain or in the mempool. | addr_hashes |
utxos | Spendable UTXOs for a set of address hashes. | addr_hashes |
address_history | Paginated transaction history for a set of address hashes. | addr_hashes, limit, offset, include_mempool |
mempool | Current mempool summary and transaction list. | none |
get_tx | Decoded transaction lookup by txid. | txid |
get_headers | Paginated block headers. | from_height, count |
get_block | Block by height or hash, optionally with decoded transactions. | height or hash, verbose |
get_block_template | Build a mining template and RandomX seed. | address |
submit_block | Submit a solved serialized block. | block_hex |
submit_tx | Validate, accept, and relay a serialized transaction. | tx_hex, fast_fluff |
bump_tx | Submit an Ownership-Proven FSS-RBF fee bump. | bump_hex |
dsproofs | List active 0-conf double-spend proofs. | none |
mine | Synchronously mine blocks inside the node. | address, blocks, threads, full_mem |
add_peer | Add an explicit peer. | peer or address |
peers | Detailed connected-peer metadata. | none |
ban_list | Current IP ban list. | none |
Common data types
Amounts and hashes
- All amounts are integer grains.
1 XSL = 100,000,000 grains. txid,wtxid,hash,prev_hash,merkle_root, andaddr_hashare 64-character lowercase hex strings (32 bytes).addr_hashis the 32-byte address commitment, not the Bech32m or legacy address string. A wallet derives it from the address or public key.- Outpoints are compact chain positions:
{"height": u64, "tx_index": u32, "out_index": u32}.
OutPoint, Output, and UTXO
| Object | Fields |
|---|---|
OutPoint | height (u64), tx_index (u32), out_index (u32). |
Output | addr_version (1 or 2), addr_hash (64-hex), amount (grains). |
Utxo | txid (creating transaction), output (Output), is_coinbase (bool). |
SpendableUtxo | outpoint, utxo, mature (bool). mature is evaluated at the next block height. |
Decoded inputs and outputs
get_tx and verbose get_block return decoded inputs and outputs:
| Decoded input field | Meaning |
|---|---|
height, tx_index, out_index | The spent outpoint. |
amount | Previous output amount in grains, or null if the prevout could not be resolved (for example on a pruned node). |
address | Legacy xsl1:/xsl2: address string for the prevout, or null. |
addr_version, addr_hash | Version and 32-byte commitment, or null. |
| Decoded output field | Meaning |
|---|---|
index | Output index within the transaction. |
address | Legacy address string. |
addr_version | 1 single-key or 2 multisig. |
addr_hash | 32-byte address commitment, 64-hex. |
amount | Amount in grains. |
Peer and ban objects
PeerInfo | Meaning |
|---|---|
id | Internal session id. |
addr | Display address of the session. |
advertised_addr | Address the peer advertised, if any. |
direction | "inbound" or "outbound". |
best_height | Peer's best known height. |
misbehavior_score | Accumulated misbehavior score. |
connected_secs, last_seen_secs | Session timing in seconds. |
rtt_ms | Round-trip time estimate in milliseconds, if known. |
BanInfo | Meaning |
|---|---|
ip | Banned IP address. |
score | Misbehavior score at ban time. |
reason | Human-readable ban reason. |
banned_at, expires_at | Unix timestamps. |
remaining_secs | Seconds until the ban expires. |
info
Returns a snapshot of chain, mempool, storage, peer, and network state. It takes no parameters and is the cheapest health check.
| Parameter | Type | Required | Description |
|---|---|---|---|
| — | — | — | No parameters. Send {} or omit params. |
| Result field | Type | Description |
|---|---|---|
height | u64 | Active chain height. |
header_height | u64 | Highest known header height. |
tip_hash | 64-hex | Active tip block hash. |
genesis_hash | 64-hex | Network genesis hash. |
mempool_len | usize | Number of mempool transactions. |
mempool_bytes | usize | Total serialized mempool bytes. |
utxo_count | usize | Active UTXO count. |
pruned_below_height | u64 | Blocks below this height have been pruned; 0 when unpruned. |
next_target_bits | string | Next block's compact target, formatted 0x......... |
peers | array<string> | Known peer addresses. |
connected_peers | usize | Active sessions. |
ban_count | usize | Current bans. |
network | string | mainnet, testnet, or devnet. |
coinbase_maturity | u64 | Coinbase maturity for the active network. |
block_reward | u64 | Fixed block subsidy in grains (100000000). |
dust_floor | u64 | Non-consensus relay/wallet dust floor in grains (5000). |
txindex | bool | Whether the persistent transaction index is enabled. |
clock_skew_warnings | u64 | Headers/blocks rejected as too far in the future. |
dsproof_count | usize | Active 0-conf double-spend proofs. |
curl -sS http://127.0.0.1:18332 \
-H "X-Scruple-Cookie: $(cat ./data/.cookie)" \
-H 'Content-Type: application/json' \
-d '{"method":"info","params":{}}'
{
"ok": true,
"result": {
"height": 12345,
"header_height": 12345,
"tip_hash": "TIP_HASH",
"genesis_hash": "GENESIS_HASH",
"mempool_len": 3,
"mempool_bytes": 1042,
"utxo_count": 20001,
"pruned_below_height": 0,
"next_target_bits": "0x1e0fffff",
"peers": ["203.0.113.10:18333"],
"connected_peers": 1,
"ban_count": 0,
"network": "mainnet",
"coinbase_maturity": 24,
"block_reward": 100000000,
"dust_floor": 5000,
"txindex": true,
"clock_skew_warnings": 0,
"dsproof_count": 0
}
}
seen_addresses
Given a set of 32-byte address hashes, returns the subset that has ever been confirmed on-chain (including spent or pruned outputs) or is currently present in the mempool. This is how HD wallets recover used addresses beyond a gap without relying on UTXO presence alone.
| Parameter | Type | Required | Description |
|---|---|---|---|
addr_hashes | array<64-hex> | required | Address hashes to test. Maximum 1,000 entries. An empty array returns []. |
Result: an array of the 64-hex hashes that were seen. Omitting addr_hashes or passing null is an error; the method never dumps the full seen-address set.
{
"method": "seen_addresses",
"params": {
"addr_hashes": ["ADDR_HASH_A", "ADDR_HASH_B"]
}
}
{
"ok": true,
"result": ["ADDR_HASH_A"]
}
utxos
Returns spendable UTXOs for a set of address hashes. Coinbase outputs include a mature flag evaluated against the next block height. The node never returns the full UTXO set in one call.
| Parameter | Type | Required | Description |
|---|---|---|---|
addr_hashes | array<64-hex> | required | Address hashes to query. Maximum 1,000 entries. An empty array returns []. |
{
"method": "utxos",
"params": {
"addr_hashes": ["ADDR_HASH"]
}
}
{
"ok": true,
"result": [
{
"outpoint": { "height": 12345, "tx_index": 1, "out_index": 0 },
"utxo": {
"txid": "TXID",
"output": {
"addr_version": 1,
"addr_hash": "ADDR_HASH",
"amount": 100000000
},
"is_coinbase": false
},
"mature": true
}
]
}
address_history
Returns paginated wallet-style history for a set of address hashes. Mempool entries are returned first, then confirmed entries scanned newest-to-oldest. Each entry reports the signed net movement for the queried addresses, the fee when every input could be resolved, and decoded wallet/external outputs.
| Parameter | Type | Required | Description |
|---|---|---|---|
addr_hashes | array<64-hex> | optional | Address hashes to match. Maximum 1,000. If omitted or empty, the result is []. |
include_mempool | bool | optional | Include unconfirmed mempool entries. Defaults to true. |
limit | integer | optional | Page size 1–1,000. Defaults to 100. |
offset | integer | optional | Entries to skip. Defaults to 0. |
| Entry field | Type | Description |
|---|---|---|
txid | 64-hex | Transaction id. |
direction | string | mined, received, sent, or self. |
amount | i64 | Signed net movement in grains. Positive for mined/received, negative for sent/self. |
fee | u64 | Full transaction fee in grains, or 0 when inputs are unresolved or the transaction is coinbase. |
block_height | u64|null | Confirmation height, or null for mempool. |
timestamp | u64|null | Block timestamp, or null for mempool. |
confirmations | u64 | Confirmations; 0 for mempool. |
coinbase | bool | Whether the transaction is a coinbase. |
wallet_outputs | array | Outputs paying the queried addresses: out_index, addr_hash, amount. |
wallet_inputs | array | Inputs spending the queried addresses: outpoint, addr_hash, amount. |
external_outputs | array | Outputs paying other addresses. |
raw_hex | string | Serialized transaction hex. |
{
"method": "address_history",
"params": {
"addr_hashes": ["ADDR_HASH"],
"include_mempool": true,
"limit": 50,
"offset": 0
}
}
{
"ok": true,
"result": [
{
"txid": "TXID",
"direction": "received",
"amount": 40000000,
"fee": 312,
"block_height": 12345,
"timestamp": 1796256300,
"confirmations": 7,
"coinbase": false,
"wallet_outputs": [
{ "out_index": 1, "addr_hash": "ADDR_HASH", "amount": 40000000 }
],
"wallet_inputs": [],
"external_outputs": [
{ "out_index": 0, "addr_hash": "OTHER_HASH", "amount": 12345678 }
],
"raw_hex": "0100..."
}
]
}
Confirmed history is scanned from stored block bodies and undo prevouts. A pruned node cannot reconstruct history for blocks older than its prune window. For full historical address history, run an unpruned node.
mempool
Returns a summary of the current mempool and one entry per transaction. It takes no parameters.
| Result field | Type | Description |
|---|---|---|
count | usize | Number of transactions. |
bytes | usize | Total serialized bytes. |
txs | array | Entries with txid, fee, bytes, fee_per_byte, inputs, and outputs counts. |
{
"ok": true,
"result": {
"count": 1,
"bytes": 412,
"txs": [
{
"txid": "TXID",
"fee": 412,
"bytes": 412,
"fee_per_byte": 1.0,
"inputs": 1,
"outputs": 2
}
]
}
}
get_tx
Looks up a transaction by txid. Mempool transactions are always available. Confirmed transactions require the node to be running with --txindex.
| Parameter | Type | Required | Description |
|---|---|---|---|
txid | 64-hex | required | Transaction id. |
| Result field | Type | Description |
|---|---|---|
txid, wtxid | 64-hex | Non-malleable txid and witness txid. |
status | string | mempool or confirmed. |
confirmations | u64 | Confirmations; 0 for mempool. |
block_height, block_hash, tx_index, timestamp | mixed | Confirmation location, or null for mempool. |
is_coinbase | bool | Coinbase transaction flag. |
bytes | usize | Serialized size. |
fee | u64|null | Fee in grains when inputs are resolvable. |
fee_per_byte | f64|null | Fee rate. |
double_spend_detected | bool | True for a mempool transaction with an active double-spend proof. |
inputs, outputs | array | Decoded inputs and outputs (see common data types). |
raw_hex | string | Serialized transaction hex. |
{
"method": "get_tx",
"params": { "txid": "TXID" }
}
{
"ok": true,
"result": {
"txid": "TXID",
"wtxid": "WTXID",
"status": "confirmed",
"confirmations": 12,
"block_height": 12345,
"block_hash": "BLOCK_HASH",
"tx_index": 1,
"timestamp": 1796256300,
"is_coinbase": false,
"bytes": 412,
"fee": 412,
"fee_per_byte": 1.0,
"double_spend_detected": false,
"inputs": [
{
"height": 12300,
"tx_index": 1,
"out_index": 0,
"amount": 100000000,
"address": "xsl1:ADDR_HASH",
"addr_version": 1,
"addr_hash": "ADDR_HASH"
}
],
"outputs": [
{
"index": 0,
"address": "xsl1:OTHER_HASH",
"addr_version": 1,
"addr_hash": "OTHER_HASH",
"amount": 40000000
}
],
"raw_hex": "0100..."
}
}
If the transaction is not in the mempool and --txindex is disabled, the error explains that the node must be started with --txindex to look up confirmed transactions.
get_headers
Returns a page of active-chain headers. Omitting from_height returns the most recent count headers ending at the tip.
| Parameter | Type | Required | Description |
|---|---|---|---|
from_height | u64 | optional | First height to return. Defaults to the last count headers ending at the tip. |
count | u64 | optional | Number of headers, 1–2,000. Defaults to 100. |
Result: { "tip_height": u64, "headers": [...] }. Each header has height, hash, prev_hash, merkle_root, timestamp, target_bits (0x........), nonce, work (32-byte big-endian work as 64-hex), tx_count, and bytes.
{
"method": "get_headers",
"params": { "from_height": 0, "count": 2 }
}
{
"ok": true,
"result": {
"tip_height": 12345,
"headers": [
{
"height": 0,
"hash": "GENESIS_HASH",
"prev_hash": "GENESIS_COMMITMENT",
"merkle_root": "MERKLE_ROOT",
"timestamp": 1796256000,
"target_bits": "0x1e0fffff",
"nonce": 0,
"work": "WORK_HEX",
"tx_count": 1,
"bytes": 145
}
]
}
}
get_block
Returns a block by height or hash. By default the result includes metadata, txids, and raw block hex. Set verbose: true to include decoded transactions with resolved inputs and fees.
| Parameter | Type | Required | Description |
|---|---|---|---|
height | u64 | optional | Block height. Provide this or hash. |
hash | 64-hex | optional | Block hash. Provide this or height. |
verbose | bool | optional | Include decoded txs. Defaults to false. |
Result fields: height, hash, prev_hash, merkle_root, timestamp, target_bits, nonce, tx_count, bytes, txids, and raw_hex. With verbose, txs contains txid, wtxid, tx_index, is_coinbase, bytes, fee, fee_per_byte, inputs, and outputs.
{
"method": "get_block",
"params": { "height": 0, "verbose": true }
}
{
"ok": true,
"result": {
"height": 0,
"hash": "GENESIS_HASH",
"prev_hash": "GENESIS_COMMITMENT",
"merkle_root": "MERKLE_ROOT",
"timestamp": 1796256000,
"target_bits": "0x1e0fffff",
"nonce": 0,
"tx_count": 1,
"bytes": 145,
"txids": ["GENESIS_TXID"],
"raw_hex": "0100...",
"txs": [
{
"txid": "GENESIS_TXID",
"wtxid": "GENESIS_WTXID",
"tx_index": 0,
"is_coinbase": true,
"bytes": 60,
"fee": 0,
"fee_per_byte": 0.0,
"inputs": [],
"outputs": []
}
]
}
}
On a pruned node, requesting a block below pruned_below_height returns an error explaining that the block has been pruned. Verbose decoding may return null input amounts/addresses when prevouts are unavailable.
get_block_template
Builds a candidate block paying the supplied address and returns everything a miner needs: the serialized block, the header, the compact target, and the RandomX seed hash.
| Parameter | Type | Required | Description |
|---|---|---|---|
address | string | required | Reward address. Must match the node's active network. Bech32m or legacy xsl1:/xsl2: forms are accepted. |
| Result field | Type | Description |
|---|---|---|
height | u64 | Candidate block height. |
prev_hash | 64-hex | Parent block hash. |
merkle_root | 64-hex | Dual Merkle root. |
timestamp | u64 | Candidate timestamp. |
target_bits | string | Compact target as 0x......... |
target_bits_u32 | u32 | Compact target as an integer. |
seed_hash | 64-hex | RandomX seed hash for this height. |
tx_count | usize | Transactions in the template. |
header_hex | string | Serialized 85-byte header. |
block_hex | string | Serialized block, ready to solve and submit. |
{
"method": "get_block_template",
"params": { "address": "xsl1:ADDR_HASH" }
}
{
"ok": true,
"result": {
"height": 12346,
"prev_hash": "TIP_HASH",
"merkle_root": "MERKLE_ROOT",
"timestamp": 1796256300,
"target_bits": "0x1e0fffff",
"target_bits_u32": 504627199,
"seed_hash": "SEED_HASH",
"tx_count": 4,
"header_hex": "0100...",
"block_hex": "0100..."
}
}
submit_block
Submits a solved serialized block to the node. The node validates the header, proof-of-work, Merkle root, timestamp, difficulty, coinbase, and all transactions before accepting it.
| Parameter | Type | Required | Description |
|---|---|---|---|
block_hex | string | required | Hex-encoded serialized block. Raw block must be at most 1,000,000 bytes; hex string at most 2,000,000 characters. |
Result: height, hash, and became_tip. A block can be accepted but not become the active tip if it extends a side branch; refresh the template and continue.
{
"method": "submit_block",
"params": { "block_hex": "0100..." }
}
{
"ok": true,
"result": {
"height": 12346,
"hash": "BLOCK_HASH",
"became_tip": true
}
}
submit_tx
Validates a serialized transaction, adds it to the mempool if it passes consensus and policy checks, and relays it. By default the transaction originates in the Dandelion++ stem phase; fast_fluff: true immediately fluff-broadcasts it.
| Parameter | Type | Required | Description |
|---|---|---|---|
tx_hex | string | required | Hex-encoded serialized transaction. Raw transaction must be at most 100,000 bytes. |
fast_fluff | bool | optional | Bypass the stem phase and fluff immediately. Defaults to false. |
Result: txid, fee, bytes, and fast_fluff. Policy failures (dust, fee rate, mempool limits, double spends, invalid signatures) return ok: false with the reason.
{
"method": "submit_tx",
"params": {
"tx_hex": "0100...",
"fast_fluff": true
}
}
{
"ok": true,
"result": {
"txid": "TXID",
"fee": 412,
"bytes": 412,
"fast_fluff": true
}
}
bump_tx
Submits an Ownership-Proven FSS-RBF TxBump to replace one or more conflicting mempool transactions with a higher-fee transaction. The bump must strictly raise the fee rate and total fee, preserve recipient outputs, and attach shrink proofs for any output it reduces or removes.
| Parameter | Type | Required | Description |
|---|---|---|---|
bump_hex | string | required | Hex-encoded serialized TxBump. Maximum 116,384 bytes (100,000-byte transaction plus up to four 4,096-byte shrink proofs). |
Result: txid, fee, bytes, and replaced_txids. Rejections include insufficient fee increase, missing/extra shrink proofs, unauthorized output changes, or a conflicting transaction that is not replaceable.
{
"method": "bump_tx",
"params": { "bump_hex": "0100..." }
}
{
"ok": true,
"result": {
"txid": "NEW_TXID",
"fee": 900,
"bytes": 420,
"replaced_txids": ["OLD_TXID"]
}
}
dsproofs
Lists active 0-conf double-spend proofs. When a node detects a valid conflicting spend that is not an authorized FSS-RBF replacement, it rejects the conflict, records a compact proof, and exposes it here and via get_tx's double_spend_detected flag.
Result: an array of objects with outpoint formatted as "height:tx_index:out_index", original_txid, and conflicting_txid.
{
"ok": true,
"result": [
{
"outpoint": "12345:1:0",
"original_txid": "ORIGINAL_TXID",
"conflicting_txid": "CONFLICTING_TXID"
}
]
}
mine
Synchronously mines one or more blocks inside the node using the RandomX miner. This is convenient for scripts and small batches, but it holds a node-wide mining lock and can run for a long time on high-difficulty networks.
| Parameter | Type | Required | Description |
|---|---|---|---|
address | string | required | Reward address, matching the active network. |
blocks | integer | optional | Number of blocks, 1–100. Defaults to 1. |
threads | integer | optional | Worker threads, 1–64. Defaults to 1. |
full_mem | bool | optional | Use RandomX Full-Memory mode. Defaults to false. |
Result: { "mined": [ { "height", "hash", "txs", "bytes", "hashes", "threads", "full_mem" } ] }. If another RPC mining operation is in progress, the method returns an error instead of queueing.
{
"method": "mine",
"params": {
"address": "xsl1:ADDR_HASH",
"blocks": 1,
"threads": 4,
"full_mem": false
}
}
{
"ok": true,
"result": {
"mined": [
{
"height": 12346,
"hash": "BLOCK_HASH",
"txs": 1,
"bytes": 145,
"hashes": 1048576,
"threads": 4,
"full_mem": false
}
]
}
}
A synchronous mine call can exceed a typical HTTP client timeout. The built-in RPC client defaults to 300 seconds; for mainnet mining, prefer scruple mine --continuous, which manages templates and stale-tip cancellation.
add_peer
Adds an explicit peer to the node. Explicit peers bypass the outbound /16 IPv4 and /32 IPv6 subnet diversity checks, which is useful for LAN clusters. Gossiped and DNS peers remain diversity-enforced.
| Parameter | Type | Required | Description |
|---|---|---|---|
peer | string | required* | Peer address as host:port. Alias: address. |
address | string | required* | Alias for peer. |
* Provide either peer or address.
{
"method": "add_peer",
"params": { "peer": "192.168.1.11:18333" }
}
{
"ok": true,
"result": { "peer": "192.168.1.11:18333", "added": true }
}
peers
Returns detailed metadata for currently connected peers. It takes no parameters. See PeerInfo in common data types for field meanings.
{
"ok": true,
"result": [
{
"id": 1,
"addr": "203.0.113.10:18333",
"advertised_addr": "203.0.113.10:18333",
"direction": "outbound",
"best_height": 12345,
"misbehavior_score": 0,
"connected_secs": 600,
"last_seen_secs": 2,
"rtt_ms": 42
}
]
}
ban_list
Returns the current IP ban list. It takes no parameters. Bans expire automatically; remaining_secs reports the time left.
{
"ok": true,
"result": [
{
"ip": "198.51.100.7",
"score": 120,
"reason": "invalid header",
"banned_at": 1796256000,
"expires_at": 1796259600,
"remaining_secs": 3600
}
]
}
Errors
HTTP status codes
| Status | When | Body |
|---|---|---|
200 OK | Request parsed. Check ok for method success or failure. | RpcResponse envelope. |
400 Bad Request | Malformed request line or headers, duplicate/invalid Content-Length, unsupported Transfer-Encoding, truncated body, or malformed JSON. | {"ok":false,"error":"..."} |
401 Unauthorized | Missing or invalid cookie. Includes WWW-Authenticate: Basic realm="scruple-rpc". | {"ok":false,"error":"unauthorized: missing or invalid RPC cookie"} |
405 Method Not Allowed | Anything other than POST. Includes Allow: POST. | {"ok":false,"error":"only POST is allowed"} |
408 Request Timeout | The request exceeded the 15-second deadline or a socket timeout. | {"ok":false,"error":"request timed out"} |
413 Payload Too Large | Content-Length exceeds 2,065,536 bytes. | {"ok":false,"error":"RPC request body exceeds limit (...)"} |
431 Request Header Fields Too Large | More than 64 header lines or a header line over 8 KB. | {"ok":false,"error":"HTTP headers exceed size limit"} |
Common method errors
| Error text | Cause |
|---|---|
'params' must be a JSON object | params was an array, string, number, or boolean. |
unknown RPC method: ... | Method name typo or unsupported method. |
missing required 'addr_hashes' array ... | seen_addresses or utxos called without the filter. |
'addr_hashes' exceeds maximum length ... | More than 1,000 address hashes in one call. |
'addr_hashes' entries must be 32 bytes ... | An entry is not 64 hex characters. |
missing 'txid' / txid must be 32 bytes ... | Bad or missing transaction id. |
transaction not found ... --txindex | Confirmed lookup on a node without --txindex. |
provide either 'height' or 'hash' | get_block called with neither selector. |
block at height ... has been pruned | Requested block is below the prune window. |
missing address | get_block_template or mine called without a reward address. |
'blocks' must be an integer between 1 and 100 | Invalid mine block count. |
'threads' must be an integer between 1 and 64 | Invalid mine thread count. |
another RPC mine operation is already in progress | A concurrent synchronous mine call holds the node mining lock. |
node is shutting down | The node received a shutdown signal while mining. |
missing 'peer' address | add_peer called without peer or address. |
block_hex exceeds 1 MB hard limit ... | Serialized block exceeds 1,000,000 bytes. |
tx_hex exceeds MAX_TX_SIZE ... | Serialized transaction exceeds 100,000 bytes. |
bump_hex exceeds MAX_TX_BUMP_LEN ... | Serialized bump exceeds 116,384 bytes. |
Limits and timeouts
| Limit | Value |
|---|---|
| Request body | 2,065,536 bytes (2 × 1,000,000 block bytes + 65,536 JSON overhead) |
| Header lines | 64 |
| Header line length | 8,192 bytes |
| Read / write timeout | 10 seconds each |
| Request deadline | 15 seconds |
| Concurrent connections | 64 |
addr_hashes per call | 1,000 |
address_history page size | 1–1,000, default 100 |
get_headers count | 1–2,000, default 100 |
mine blocks / threads | 1–100 blocks / 1–64 threads |
| Block size | 1,000,000 serialized bytes |
| Transaction size | 100,000 serialized bytes |
| TxBump size | 116,384 serialized bytes |
Client examples
curl
COOKIE=$(cat ./data/.cookie)
curl -sS http://127.0.0.1:18332 \
-H "X-Scruple-Cookie: $COOKIE" \
-H 'Content-Type: application/json' \
-d '{
"method": "get_block",
"params": { "height": 0, "verbose": true }
}'
Python (standard library)
import json
import urllib.request
from pathlib import Path
RPC_URL = "http://127.0.0.1:18332"
COOKIE = Path("./data/.cookie").read_text().strip()
def call(method, params=None):
body = json.dumps({"method": method, "params": params or {}}).encode()
req = urllib.request.Request(
RPC_URL,
data=body,
headers={
"Content-Type": "application/json",
"X-Scruple-Cookie": COOKIE,
},
method="POST",
)
with urllib.request.urlopen(req, timeout=30) as resp:
payload = json.load(resp)
if not payload.get("ok"):
raise RuntimeError(payload.get("error", "RPC error"))
return payload["result"]
info = call("info")
print(info["height"], info["network"])
print(call("get_headers", {"count": 3}))
Node.js (fetch)
import fs from "node:fs";
const RPC_URL = "http://127.0.0.1:18332";
const cookie = fs.readFileSync("./data/.cookie", "utf8").trim();
async function call(method, params = {}) {
const res = await fetch(RPC_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Scruple-Cookie": cookie,
},
body: JSON.stringify({ method, params }),
});
const payload = await res.json();
if (!payload.ok) throw new Error(payload.error);
return payload.result;
}
console.log(await call("info"));
Rust (library client)
use scruple::rpc::call_rpc;
fn main() -> Result<(), String> {
let cookie = std::fs::read_to_string("./data/.cookie").map_err(|e| e.to_string())?;
let info = call_rpc(
"127.0.0.1:18332",
"info",
serde_json::json!({}),
Some(cookie.trim()),
)?;
println!("{info:#}");
Ok(())
}
Block explorer recipe
An explorer needs an archive-style node with the transaction index enabled:
./target/release/scruple node \
--network mainnet \
--data-dir ./explorer-data \
--rpc 127.0.0.1:18332 \
--txindex
- Call
infoand confirmtxindex: trueand the currentheight. - Page headers with
get_headers(from_height,countup to 2,000). - Fetch a block with
get_blockandverbose: truefor decoded transactions and fees. - Link transactions to a detail page with
get_tx; confirmed lookups use the tx index. - For wallet history, call
address_historywith the wallet's address hashes, paginating withlimitandoffset. - For HD discovery, batch address hashes through
seen_addressesandutxos(1,000 per call).
The public Scruple block explorer implements this recipe against a testnet node.
The RPC filters use 32-byte addr_hash values. Decode a Bech32m address to its version and hash, or ask a wallet for the hash. Do not pass a full xsl1: string to addr_hashes.
Implementation notes and review findings
The following behaviours are worth knowing when integrating. They reflect the current implementation and are part of the documented contract unless the code changes.
- Not JSON-RPC 2.0. There is no
jsonrpcversion field and no requestid; responses are correlated by connection order. Use one request per connection. - Method errors use HTTP 200. Always check the
okboolean, not just the HTTP status. - Confirmed
get_txrequires--txindex. Mempool lookups work on any node; confirmed lookups need the index.--txindexand--pruneare mutually exclusive. address_historywith no filter returns[]. It does not dump all history. Supplyaddr_hashesexplicitly.utxosandseen_addressesrequire an explicit filter. This prevents accidental full-UTXO-set or full-address-index dumps.mineis synchronous and globally serialized. A second concurrent call fails with a lock error. Long calls need a client timeout above the expected mining time.get_blockby hash derives the height from the coinbase transaction. Valid blocks always have a coinbase first; a malformed block would yield a null height rather than a guessed value.get_block_templatevalidates the address against the active network. A testnet Bech32m address on a mainnet node is rejected before template construction.submit_txdefaults to Dandelion++ stem relay. Usefast_fluff: truefor immediate fluff broadcast in 0-conf point-of-sale flows.add_peerbypasses subnet diversity. This is intentional for LAN clusters; gossiped and DNS peers remain diversity-enforced.- The cookie rotates on every restart. Cache the file path, not the token. Re-read on 401.
- The RPC listener is plaintext HTTP. Bind localhost or terminate TLS in front of it; do not expose it directly to an untrusted network.