RPC Integration Patterns
Tidecoin exposes the Bitcoin Core JSON-RPC model plus Tidecoin-specific PQHD and AuxPoW RPCs. This page covers integration idioms and workflows. For command schemas and return fields, use RPC Reference. For binding, authentication, and access control, use RPC Security.
Ownership boundary
| Need | Page |
|---|---|
| Exact RPC arguments and result fields | RPC Reference |
| Error codes and retry guidance | RPC Error Codes |
| Secure deployment of RPC | RPC Security |
| Application workflows | This page |
Node health gate
Every long-running integration should gate work on node health:
tidecoin-cli getblockchaininfo
tidecoin-cli getnetworkinfoBefore enabling deposits or withdrawals, check:
| Field or condition | Expected handling |
|---|---|
initialblockdownload | Deposits and withdrawals should wait until false. |
| Current block height | Must be close to your independent monitor or trusted peer set. |
| Best block hash | Store it and compare on the next poll. |
| Peer count | Alert if below your operational threshold. |
| Chain selection | Confirm mainnet/testnet/regtest matches the environment. |
Block tailing
Prefer waitfornewblock for low-latency block tailing, with a polling
fallback for process restarts.
tidecoin-cli waitfornewblock 60Store both height and hash. Heights can be reused during a reorg; hashes identify the actual block.
Recommended loop:
- Read current tip from
getblockchaininfo. - If this is startup, backfill from the last finalized height you have processed.
- Call
waitfornewblock <timeout>. - Fetch the block by hash with
getblock <hash> 2. - Process transactions idempotently.
- Store the processed block hash, height, and previous block hash.
Reorg handling
Never treat height alone as a primary key.
For every processed block, store:
| Field | Why |
|---|---|
height | Ordering and confirmation calculation. |
hash | Canonical identity of the block you processed. |
previousblockhash | Fast continuity check. |
| Processed transaction IDs | Idempotent credit/debit handling. |
On a new tip:
- Compare the new block’s
previousblockhashto your stored tip hash. - If it matches, append normally.
- If it does not match, walk backward with
getblockheaderorgetblockuntil you find a common ancestor. - Mark transactions from disconnected blocks as unconfirmed or reversed.
- Replay blocks from the common ancestor to the new tip.
Wallet deposit monitoring
For wallet-backed deposits, listsinceblock is the simplest cursor API.
Use a confirmation target so transactions are re-reported until they are
deep enough.
tidecoin-cli -rpcwallet="deposits" listsinceblock "<lastblock>" 6 true trueTypical handling:
| Result field | Handling |
|---|---|
transactions[] | Process credits/debits idempotently by txid, vout, address/account metadata, and category. |
removed[] | Reverse or unconfirm records that were in disconnected blocks. |
lastblock | Store as the next cursor after successful processing. |
If you do not use the wallet, scan blocks directly with getblock and
decode outputs with your own address index.
Raw transaction lookup
Use getrawtransaction carefully:
tidecoin-cli getrawtransaction "<txid>" 2 "<blockhash>"Passing a blockhash avoids ambiguity and avoids depending on mempool or
global transaction index availability. For wallet transactions, use
gettransaction on the wallet endpoint.
Mempool observation
Mempool data is policy-local. It is useful for withdrawal monitoring and broadcast feedback, but it is not consensus state.
Useful checks:
tidecoin-cli testmempoolaccept '["<rawtxhex>"]'
tidecoin-cli sendrawtransaction "<rawtxhex>" "<maxfeerate>"Handle RPC_VERIFY_REJECTED (-26) as a rejection and store the message
for operator review. Common rejection reasons include low fee, dust,
non-standardness, pre-activation witness/script use, and invalid
signatures.
Batching and rate limits
JSON-RPC supports batching at the HTTP layer. Use it for independent
lookups such as getblockhash or getrawtransaction, but do not batch
state-changing wallet operations unless your application can tolerate
partial success and retry ambiguity.
Rules:
| Pattern | Guidance |
|---|---|
| Read-only block/tx lookup | Good batch candidate. |
| Wallet sends | Avoid batching; handle one withdrawal at a time or with explicit internal locking. |
| Import/rescan operations | Do not mix with normal hot-path calls. |
| Long waits | Keep waitfornewblock on a separate worker connection. |
Retry policy
| Error | Handling |
|---|---|
RPC_IN_WARMUP (-28) | Retry after startup delay. |
RPC_CLIENT_IN_INITIAL_DOWNLOAD (-10) | Wait for sync before deposit/withdrawal operations. |
RPC_CLIENT_NOT_CONNECTED (-9) | Retry after peer recovery; alert if persistent. |
RPC_INVALID_ADDRESS_OR_KEY (-5) | Treat as input or configuration error. |
RPC_INVALID_PARAMETER (-8) | Treat as caller bug unless input is user-provided. |
RPC_VERIFY_REJECTED (-26) | Do not blindly retry; inspect rejection reason. |
Source of truth
| Topic | Source |
|---|---|
| RPC command registration and named args | ../tidecoin/src/rpc/client.cpp |
| Blockchain RPCs | ../tidecoin/src/rpc/blockchain.cpp |
| Raw transaction and mempool RPCs | ../tidecoin/src/rpc/rawtransaction.cpp, ../tidecoin/src/rpc/mempool.cpp |
| Wallet transaction RPCs | ../tidecoin/src/wallet/rpc/transactions.cpp, ../tidecoin/src/wallet/rpc/spend.cpp |
| Tidecoin-specific PQHD and AuxPoW RPCs | ../tidecoin/doc/pq-rpc.md, RPC Reference |
See also: Reference / RPC Reference, Reference / RPC Error Codes, Exchange Integration.