Framework
Bitcoin
Embed a Bitcoin Core daemon in your Swift application with a type-safe RPC client and fluent configuration builder.
Overview
The Bitcoin module embeds Bitcoin Core in a Swift application and exposes its JSON-RPC interface as typed Swift APIs.
Start and stop an in-process bitcoind with Daemon on a dedicated background thread; start(with:) returns immediately and waitUntilStopped() joins on shutdown
Send typed JSON-RPC commands via RPCClient over an in-process C bridge for non-wallet calls and HTTP for wallet calls or remote nodes
Build Bitcoin Core configurations with the fluent BitcoinConfig builder
Catch network-specific option misuse at compile time via phantom-typed networks
The module pairs with BitcoinKernel in the 21.dev Swift Bitcoin ecosystem. BitcoinKernel wraps libbitcoinkernel for consensus validation without a full node. Use Bitcoin for a full node with mempool, wallet, and P2P. Use BitcoinKernel for validation primitives only.
import Bitcoin
// Configure a regtest node
let auth = RPCAuth(username: "user", salt: "abc", passwordHMAC: "def")
let config = BitcoinConfig.regtest().rpcAuth(auth).server()
// Start the embedded daemon
try Daemon.start(with: config)
// Create an RPC client
let client = RPCClient(
url: URL(string: "http://127.0.0.1:18443")!,
username: "user",
password: "pass"
)
// Query the blockchain
let info = try await client.getBlockchainInfo()
print("Chain: \(info.chain), Height: \(info.blocks)")
Topics
Essentials
Daemon Lifecycle
RPC Client
Transport Layer
JSON-RPC Protocol
Configuration
Configuration Value Types
Configuration Validation
Response Models — Blockchain
Response Models — Transactions
Response Models — PSBT
Response Models — Mempool
Response Models — Network
Response Models — Mining
Response Models — Wallet
Response Models — Utility
Response Models — Shared Types
Response Models — Scanning
Structures
Enumerations