Bitcoin Toolkit for Elixir.
BTx is a modern Elixir library for Bitcoin development, starting with a
powerful JSON-RPC client for Bitcoin Core. Designed for developers building
Bitcoin applications, BTx provides an idiomatic Elixir interface with
comprehensive Bitcoin tooling.
- Full Bitcoin Core API Coverage: Complete implementation of Bitcoin Core's JSON-RPC API.
- Type-Safe Requests: All methods use Ecto schemas with automatic validation.
- Intelligent Response Parsing: Structured response handling with embedded schemas.
- Idiomatic Elixir Interface: Clean, functional API that feels natural in Elixir applications.
- Context-Organized API: Well-organized modules (
BTx.RPC.Wallets,BTx.RPC.Blockchain, etc.). - Comprehensive Error Handling: Detailed error messages with specific Bitcoin Core error codes.
- Built-in Retries: Configurable retry logic for network resilience.
- Flexible HTTP Client: Built on Tesla for maximum configurability.
- Telemetry Integration: Built-in metrics and observability.
- Connection Pooling: Efficient resource management.
- Wallet Routing: Automatic wallet-specific endpoint routing.
Add btx to your dependencies in mix.exs:
def deps do
[
{:btx, "~> 0.1.0"}
]
endFor more detailed information, see the getting started guide and online documentation.
# Using the included docker-compose
docker-compose up -dclient = BTx.RPC.client(
base_url: "http://127.0.0.1:18443",
username: "my-user",
password: "my-pass"
){:ok, result} = BTx.RPC.Wallets.create_wallet(client,
wallet_name: "my-wallet",
passphrase: "secure-passphrase",
avoid_reuse: true,
descriptors: true
)
# => %BTx.RPC.Wallets.CreateWalletResult{name: "my-wallet", warning: nil}# Generate a new address
{:ok, address} = BTx.RPC.Wallets.get_new_address(client,
wallet_name: "my-wallet",
label: "customer-payment",
address_type: "bech32"
)
# Get wallet balance
{:ok, balance} = BTx.RPC.Wallets.get_balance(client,
wallet_name: "my-wallet"
)
# Send payment
{:ok, txid} = BTx.RPC.Wallets.send_to_address(client,
address: "bc1q...",
amount: 0.001,
wallet_name: "my-wallet"
)# ✅ Type-safe with validation
{:ok, wallet} = BTx.RPC.Wallets.create_wallet(client,
wallet_name: "valid-name",
descriptors: true
)
# ❌ Invalid parameters caught early
{:error, changeset} = BTx.RPC.Wallets.create_wallet(client,
wallet_name: "", # Empty name validation fails
descriptors: "invalid" # Type validation fails
)case BTx.RPC.Wallets.create_wallet(client, wallet_name: "existing") do
{:ok, result} ->
# Success
{:error, %BTx.RPC.MethodError{reason: :misc_error}} ->
# Wallet already exists
{:error, %BTx.RPC.Error{reason: :econnrefused}} ->
# Bitcoin Core not running
end
BTx.RPC.Blockchain- Blockchain info, blocks, miningBTx.RPC.Mining- Mining utilitiesBTx.RPC.RawTransactions- Transaction creation and signingBTx.RPC.Utils- Utility functions, validation, estimatesBTx.RPC.Wallets- Wallet management, addresses, transactions
Ready to dive deeper? Check out our comprehensive guides:
📖 Getting Started Guide - Complete tutorial with real examples
📋 API Documentation - Full API reference
BTx is actively developed with an ambitious roadmap focused on building comprehensive Bitcoin development tools:
| Phase | Description | Status |
|---|---|---|
| 🔌 I | Foundation layer providing complete Bitcoin Core JSON-RPC API coverage with type-safe requests and intelligent response parsing. | |
| 📋 II | High-level transaction builders, multi-signature support, fee optimization algorithms, and advanced signing workflows for complex transaction scenarios. | ❌ Planned |
| 🚧 III | Wallet utilities including backup/restore formats, address generation algorithms, balance calculation helpers, and transaction parsing/validation tools. | ❌ Planned |
| 📊 IV | Blockchain analysis tools including UTXO analysis algorithms, transaction graph building utilities, mempool monitoring helpers, and block parsing/validation tools. | ❌ Planned |
| 🧙 V | Advanced Bitcoin primitives including Lightning Network protocols, privacy features (CoinJoin), smart contract scripting, and custom Bitcoin protocol extensions. | ❌ Planned |
Work in Progress: BTx is currently in active development. While the core
JSON-RPC functionality is stable and well-tested, the API may evolve between
versions. Currently suitable for development and testing environments.
Contributions are very welcome! Here's how you can help:
- Report Issues: Use the issue tracker for bugs or feature requests
- Submit PRs: Open pull requests for improvements
- Run Tests: Ensure
mix test.cipasses before submitting - Documentation: Help improve docs and examples
# Clone and setup
git clone https://github.com/cabol/btx.git
cd btx
mix deps.get
# Start Bitcoin regtest for testing
docker-compose up -d
# Run full test suite
mix test.ciCopyright (c) 2025 Carlos Andres Bolaños R.A.
BTx source code is licensed under the MIT License.