
A comprehensive Ruby SDK for the BSV Blockchain, based in the BSV reference implementations
Be the first to ask Simon Bettison something.
What do you think? ...
A comprehensive Ruby SDK for the BSV Blockchain, built with faithful adherence to the BRC specifications and cross-SDK compatibility with the official TypeScript, Go, and Pythonimplementations. The Ruby SDK strives to be a complete, correct, and well-tested implementation that serves the Ruby community — one that developers can rely on as a reference-quality foundation for BSV application development.
The project is grounded in the principles that make Ruby and Rails productive: convention over configuration, sensible defaults, and the principle of least surprise. Every component ships with a sane default that works out of the box, while exposing a pluggable composition interface for teams that need more.
Cryptographic Primitives — ECDSA signing with RFC 6979 deterministic nonces, Schnorr signatures, ECIES encryption/decryption, Bitcoin Signed Messages. Elliptic curve operations are provided by the secp256k1-native gem — a pure Ruby secp256k1 implementation with an optional C extension (~22× speedup).
Key Management — BIP-32 HD key derivation, BIP-39 mnemonic generation (12/24-word phrases), WIF import/export, Base58Check encoding/decoding.
Script Layer — Complete opcode set, script parsing and serialisation, type detection and predicates (p2pkh?, p2pk?, p2sh?, multisig?, op_return?), data extraction (pubkey hashes, script hashes, addresses), and a fluent builder API.
Script Templates — Ready-made locking and unlocking script generators for P2PKH, P2PK, P2MS (multisig), and OP_RETURN.
Transaction Construction — Input/output building, BIP-143 sighash computation (all SIGHASH types with FORKID), P2PKH signing, fee estimation.
SPV Structures — Merkle path construction and verification, BEEF (Background Evaluation Extended Format) serialisation and deserialisation.
Network Integration — ARC broadcaster for transaction submission, WhatsOnChain chain provider for UTXO queries and fee rates.
ProtoWallet — Minimal BRC-100 cryptographic wallet for signing, encryption, HMAC, and key derivation. Full wallet functionality is provided by the standalone bsv-wallet gem.

Earn XP for sharing
Sign in to get a personal referral link and earn XP every time someone visits through your link.
No reviews yet — be the first.
gem install bsv-sdkgem install bsv-sdk```ruby
require 'bsv-sdk'
# Generate a new private key (or load from WIF)
priv_key = BSV::Primitives::PrivateKey.generate
# Derive the public key hash for locking scripts
pubkey_hash = priv_key.public_key.hash160
locking_script = BSV::Script::Script.p2pkh_lock(pubkey_hash)
# Create a transaction spending a UTXO
tx = BSV::Transaction::Transaction.new
# Add an input referencing a previous transaction output
input = BSV::Transaction::TransactionInput.new(
prev_tx_id: source_txid_bytes, # 32-byte binary txid of the UTXO
prev_tx_out_index: 0
)
input.source_satoshis = 100_000
input.source_locking_script = locking_script
tx.add_input(input)
# Add an output sending to the same address (for demonstration)
tx.add_output(BSV::Transaction::TransactionOutput.new(
satoshis: 90_000,
locking_script: locking_script
))
# Sign the input using the P2PKH template
template = BSV::Transaction::P2PKH.new(priv_key)
tx.inputs[0].unlocking_script = template.sign(tx, 0)
# The signed transaction is ready to broadcast
puts tx.to_hex
```