℈Scruple Docs v0.1.0-alpha.1

JSON-RPC API

JSON-RPC API

A complete reference for the Scruple node's cookie-authenticated HTTP JSON-RPC API.

Custom JSON-RPC, not JSON-RPC 2.0

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

PropertyValue
ProtocolHTTP/1.1, plaintext (no built-in TLS)
MethodPOST only. Anything else returns 405 Method Not Allowed.
PathAny path; the server does not route on the URL. Use /.
Content typeapplication/json recommended. The server parses the body as JSON regardless of the header.
Content lengthSend an accurate Content-Length. Transfer-Encoding is rejected.
ConnectionThe server responds with Connection: close; do not reuse the socket.
Default bind127.0.0.1:18332 mainnet/devnet, 127.0.0.1:28332 testnet.
ConcurrencyUp 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.

The cookie rotates on every restart

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

MethodPurposeKey parameters
infoChain, mempool, storage, peer, and network status.none
seen_addressesWhich address hashes have ever been seen on-chain or in the mempool.addr_hashes
utxosSpendable UTXOs for a set of address hashes.addr_hashes
address_historyPaginated transaction history for a set of address hashes.addr_hashes, limit, offset, include_mempool
mempoolCurrent mempool summary and transaction list.none
get_txDecoded transaction lookup by txid.txid
get_headersPaginated block headers.from_height, count
get_blockBlock by height or hash, optionally with decoded transactions.height or hash, verbose
get_block_templateBuild a mining template and RandomX seed.address
submit_blockSubmit a solved serialized block.block_hex
submit_txValidate, accept, and relay a serialized transaction.tx_hex, fast_fluff
bump_txSubmit an Ownership-Proven FSS-RBF fee bump.bump_hex
dsproofsList active 0-conf double-spend proofs.none
mineSynchronously mine blocks inside the node.address, blocks, threads, full_mem
add_peerAdd an explicit peer.peer or address
peersDetailed connected-peer metadata.none
ban_listCurrent 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, and addr_hash are 64-character lowercase hex strings (32 bytes).
  • addr_hash is 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

ObjectFields
OutPointheight (u64), tx_index (u32), out_index (u32).
Outputaddr_version (1 or 2), addr_hash (64-hex), amount (grains).
Utxotxid (creating transaction), output (Output), is_coinbase (bool).
SpendableUtxooutpoint, 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 fieldMeaning
height, tx_index, out_indexThe spent outpoint.
amountPrevious output amount in grains, or null if the prevout could not be resolved (for example on a pruned node).
addressLegacy xsl1:/xsl2: address string for the prevout, or null.
addr_version, addr_hashVersion and 32-byte commitment, or null.
Decoded output fieldMeaning
indexOutput index within the transaction.
addressLegacy address string.
addr_version1 single-key or 2 multisig.
addr_hash32-byte address commitment, 64-hex.
amountAmount in grains.

Peer and ban objects

PeerInfoMeaning
idInternal session id.
addrDisplay address of the session.
advertised_addrAddress the peer advertised, if any.
direction"inbound" or "outbound".
best_heightPeer's best known height.
misbehavior_scoreAccumulated misbehavior score.
connected_secs, last_seen_secsSession timing in seconds.
rtt_msRound-trip time estimate in milliseconds, if known.
BanInfoMeaning
ipBanned IP address.
scoreMisbehavior score at ban time.
reasonHuman-readable ban reason.
banned_at, expires_atUnix timestamps.
remaining_secsSeconds 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.

ParameterTypeRequiredDescription
———No parameters. Send {} or omit params.
Result fieldTypeDescription
heightu64Active chain height.
header_heightu64Highest known header height.
tip_hash64-hexActive tip block hash.
genesis_hash64-hexNetwork genesis hash.
mempool_lenusizeNumber of mempool transactions.
mempool_bytesusizeTotal serialized mempool bytes.
utxo_countusizeActive UTXO count.
pruned_below_heightu64Blocks below this height have been pruned; 0 when unpruned.
next_target_bitsstringNext block's compact target, formatted 0x.........
peersarray<string>Known peer addresses.
connected_peersusizeActive sessions.
ban_countusizeCurrent bans.
networkstringmainnet, testnet, or devnet.
coinbase_maturityu64Coinbase maturity for the active network.
block_rewardu64Fixed block subsidy in grains (100000000).
dust_flooru64Non-consensus relay/wallet dust floor in grains (5000).
txindexboolWhether the persistent transaction index is enabled.
clock_skew_warningsu64Headers/blocks rejected as too far in the future.
dsproof_countusizeActive 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.

ParameterTypeRequiredDescription
addr_hashesarray<64-hex>requiredAddress 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.

ParameterTypeRequiredDescription
addr_hashesarray<64-hex>requiredAddress 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.

ParameterTypeRequiredDescription
addr_hashesarray<64-hex>optionalAddress hashes to match. Maximum 1,000. If omitted or empty, the result is [].
include_mempoolbooloptionalInclude unconfirmed mempool entries. Defaults to true.
limitintegeroptionalPage size 1–1,000. Defaults to 100.
offsetintegeroptionalEntries to skip. Defaults to 0.
Entry fieldTypeDescription
txid64-hexTransaction id.
directionstringmined, received, sent, or self.
amounti64Signed net movement in grains. Positive for mined/received, negative for sent/self.
feeu64Full transaction fee in grains, or 0 when inputs are unresolved or the transaction is coinbase.
block_heightu64|nullConfirmation height, or null for mempool.
timestampu64|nullBlock timestamp, or null for mempool.
confirmationsu64Confirmations; 0 for mempool.
coinbaseboolWhether the transaction is a coinbase.
wallet_outputsarrayOutputs paying the queried addresses: out_index, addr_hash, amount.
wallet_inputsarrayInputs spending the queried addresses: outpoint, addr_hash, amount.
external_outputsarrayOutputs paying other addresses.
raw_hexstringSerialized 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..."
    }
  ]
}
History on pruned nodes

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 fieldTypeDescription
countusizeNumber of transactions.
bytesusizeTotal serialized bytes.
txsarrayEntries 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.

ParameterTypeRequiredDescription
txid64-hexrequiredTransaction id.
Result fieldTypeDescription
txid, wtxid64-hexNon-malleable txid and witness txid.
statusstringmempool or confirmed.
confirmationsu64Confirmations; 0 for mempool.
block_height, block_hash, tx_index, timestampmixedConfirmation location, or null for mempool.
is_coinbaseboolCoinbase transaction flag.
bytesusizeSerialized size.
feeu64|nullFee in grains when inputs are resolvable.
fee_per_bytef64|nullFee rate.
double_spend_detectedboolTrue for a mempool transaction with an active double-spend proof.
inputs, outputsarrayDecoded inputs and outputs (see common data types).
raw_hexstringSerialized 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..."
  }
}
No txindex, no confirmed lookup

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.

ParameterTypeRequiredDescription
from_heightu64optionalFirst height to return. Defaults to the last count headers ending at the tip.
countu64optionalNumber 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.

ParameterTypeRequiredDescription
heightu64optionalBlock height. Provide this or hash.
hash64-hexoptionalBlock hash. Provide this or height.
verbosebooloptionalInclude 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.

ParameterTypeRequiredDescription
addressstringrequiredReward address. Must match the node's active network. Bech32m or legacy xsl1:/xsl2: forms are accepted.
Result fieldTypeDescription
heightu64Candidate block height.
prev_hash64-hexParent block hash.
merkle_root64-hexDual Merkle root.
timestampu64Candidate timestamp.
target_bitsstringCompact target as 0x.........
target_bits_u32u32Compact target as an integer.
seed_hash64-hexRandomX seed hash for this height.
tx_countusizeTransactions in the template.
header_hexstringSerialized 85-byte header.
block_hexstringSerialized 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.

ParameterTypeRequiredDescription
block_hexstringrequiredHex-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.

ParameterTypeRequiredDescription
tx_hexstringrequiredHex-encoded serialized transaction. Raw transaction must be at most 100,000 bytes.
fast_fluffbooloptionalBypass 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.

ParameterTypeRequiredDescription
bump_hexstringrequiredHex-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.

ParameterTypeRequiredDescription
addressstringrequiredReward address, matching the active network.
blocksintegeroptionalNumber of blocks, 1–100. Defaults to 1.
threadsintegeroptionalWorker threads, 1–64. Defaults to 1.
full_membooloptionalUse 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
      }
    ]
  }
}
Client timeouts

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.

ParameterTypeRequiredDescription
peerstringrequired*Peer address as host:port. Alias: address.
addressstringrequired*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

StatusWhenBody
200 OKRequest parsed. Check ok for method success or failure.RpcResponse envelope.
400 Bad RequestMalformed request line or headers, duplicate/invalid Content-Length, unsupported Transfer-Encoding, truncated body, or malformed JSON.{"ok":false,"error":"..."}
401 UnauthorizedMissing or invalid cookie. Includes WWW-Authenticate: Basic realm="scruple-rpc".{"ok":false,"error":"unauthorized: missing or invalid RPC cookie"}
405 Method Not AllowedAnything other than POST. Includes Allow: POST.{"ok":false,"error":"only POST is allowed"}
408 Request TimeoutThe request exceeded the 15-second deadline or a socket timeout.{"ok":false,"error":"request timed out"}
413 Payload Too LargeContent-Length exceeds 2,065,536 bytes.{"ok":false,"error":"RPC request body exceeds limit (...)"}
431 Request Header Fields Too LargeMore than 64 header lines or a header line over 8 KB.{"ok":false,"error":"HTTP headers exceed size limit"}

Common method errors

Error textCause
'params' must be a JSON objectparams 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 ... --txindexConfirmed lookup on a node without --txindex.
provide either 'height' or 'hash'get_block called with neither selector.
block at height ... has been prunedRequested block is below the prune window.
missing addressget_block_template or mine called without a reward address.
'blocks' must be an integer between 1 and 100Invalid mine block count.
'threads' must be an integer between 1 and 64Invalid mine thread count.
another RPC mine operation is already in progressA concurrent synchronous mine call holds the node mining lock.
node is shutting downThe node received a shutdown signal while mining.
missing 'peer' addressadd_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

LimitValue
Request body2,065,536 bytes (2 × 1,000,000 block bytes + 65,536 JSON overhead)
Header lines64
Header line length8,192 bytes
Read / write timeout10 seconds each
Request deadline15 seconds
Concurrent connections64
addr_hashes per call1,000
address_history page size1–1,000, default 100
get_headers count1–2,000, default 100
mine blocks / threads1–100 blocks / 1–64 threads
Block size1,000,000 serialized bytes
Transaction size100,000 serialized bytes
TxBump size116,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
  1. Call info and confirm txindex: true and the current height.
  2. Page headers with get_headers (from_height, count up to 2,000).
  3. Fetch a block with get_block and verbose: true for decoded transactions and fees.
  4. Link transactions to a detail page with get_tx; confirmed lookups use the tx index.
  5. For wallet history, call address_history with the wallet's address hashes, paginating with limit and offset.
  6. For HD discovery, batch address hashes through seen_addresses and utxos (1,000 per call).

The public Scruple block explorer implements this recipe against a testnet node.

Address hashes, not addresses

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 jsonrpc version field and no request id; responses are correlated by connection order. Use one request per connection.
  • Method errors use HTTP 200. Always check the ok boolean, not just the HTTP status.
  • Confirmed get_tx requires --txindex. Mempool lookups work on any node; confirmed lookups need the index. --txindex and --prune are mutually exclusive.
  • address_history with no filter returns []. It does not dump all history. Supply addr_hashes explicitly.
  • utxos and seen_addresses require an explicit filter. This prevents accidental full-UTXO-set or full-address-index dumps.
  • mine is 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_block by 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_template validates the address against the active network. A testnet Bech32m address on a mainnet node is rejected before template construction.
  • submit_tx defaults to Dandelion++ stem relay. Use fast_fluff: true for immediate fluff broadcast in 0-conf point-of-sale flows.
  • add_peer bypasses 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.

Scruple Docs · v0.1.0-alpha.1 · Mainnet candidate

Scruple is alpha software. Verify commands against --help and the protocol specification before relying on them.