Class: JsonRpcProtocol ​
Defined in: packages/bitcoin/src/client/rpc/protocol.ts:35
Sans-I/O JSON-RPC protocol for Bitcoin Core.
Builds HttpRequest descriptors for JSON-RPC method calls and provides response parsing — without performing any I/O.
Security note: Built requests include an Authorization header when credentials are configured. Do not log or persist HttpRequest objects without redacting the Authorization header.
Example ​
const protocol = new JsonRpcProtocol({
host: 'http://localhost:18443',
username: 'user',
password: 'pass',
});
// Build a request descriptor (no I/O)
const req = protocol.buildRequest('getblockcount', []);
// Execute with any HTTP client
const res = await fetch(req.url, req);
const json = await res.json();
// Parse the JSON-RPC response (throws on errors)
const blockCount = protocol.parseResponse(json, 'getblockcount', []);Constructors ​
Constructor ​
new JsonRpcProtocol(
cfg):JsonRpcProtocol
Defined in: packages/bitcoin/src/client/rpc/protocol.ts:44
Parameters ​
cfg ​
Returns ​
JsonRpcProtocol
Properties ​
hasAuth ​
readonlyhasAuth:boolean
Defined in: packages/bitcoin/src/client/rpc/protocol.ts:39
Whether this protocol instance has credentials configured.
url ​
readonlyurl:string
Defined in: packages/bitcoin/src/client/rpc/protocol.ts:36
Methods ​
buildBatchRequest() ​
buildBatchRequest(
calls):HttpRequest
Defined in: packages/bitcoin/src/client/rpc/protocol.ts:88
Build an HttpRequest for a JSON-RPC batch call. Sends all calls in a single HTTP request per the JSON-RPC 2.0 spec.
Parameters ​
calls ​
object[]
Returns ​
buildRequest() ​
buildRequest(
method,params):HttpRequest
Defined in: packages/bitcoin/src/client/rpc/protocol.ts:74
Build an HttpRequest for a JSON-RPC method call.
Parameters ​
method ​
string
params ​
unknown[]
Returns ​
parseBatchResponse() ​
parseBatchResponse(
payloads,calls):unknown[]
Defined in: packages/bitcoin/src/client/rpc/protocol.ts:126
Parse a JSON-RPC batch response payload. Returns results in the same order as the original calls.
Parameters ​
payloads ​
object[]
calls ​
object[]
Returns ​
unknown[]
parseResponse() ​
parseResponse(
payload,method):unknown
Defined in: packages/bitcoin/src/client/rpc/protocol.ts:107
Parse a JSON-RPC response payload, throwing BitcoinRpcError if the response contains an error.
Parameters ​
payload ​
error? ​
{ code: number; message: string; }
error.code ​
number
error.message ​
string
result? ​
unknown
method ​
string
Returns ​
unknown
redactedHeaders() ​
redactedHeaders():
Record<string,string>
Defined in: packages/bitcoin/src/client/rpc/protocol.ts:153
Return a copy of the headers with the Authorization value redacted. Use this for logging or debugging.
Returns ​
Record<string, string>