https://github.com/yegor256/sibit
Simplified Command-Line Bitcoin Client and a Ruby library for making Bitcoin payments and checking address balances
https://github.com/yegor256/sibit
bitcoin bitcoin-client blockchain cryptocurrency ruby
Last synced: about 2 months ago
JSON representation
Simplified Command-Line Bitcoin Client and a Ruby library for making Bitcoin payments and checking address balances
- Host: GitHub
- URL: https://github.com/yegor256/sibit
- Owner: yegor256
- License: mit
- Created: 2019-04-08T12:18:44.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-12-28T17:43:06.000Z (about 2 months ago)
- Last Synced: 2025-12-28T21:55:38.670Z (about 2 months ago)
- Topics: bitcoin, bitcoin-client, blockchain, cryptocurrency, ruby
- Language: Ruby
- Homepage: https://www.yegor256.com/2019/05/07/sibit-bitcoin-command-line-client.html
- Size: 788 KB
- Stars: 27
- Watchers: 2
- Forks: 5
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Send Bitcoin via Command Line, in Ruby
[](https://www.elegantobjects.org)
[](https://www.rultor.com/p/yegor256/sibit)
[](https://www.jetbrains.com/ruby/)
[](https://github.com/yegor256/sibit/actions/workflows/rake.yml)
[](https://www.0pdd.com/p?name=yegor256/sibit)
[](https://badge.fury.io/rb/sibit)
[](https://github.com/yegor256/takes/sibit/master/LICENSE.txt)
[](https://codecov.io/github/yegor256/sibit?branch=master)
[](https://hitsofcode.com/view/github/yegor256/sibit)
To understand how the Bitcoin protocol works, I recommend you watching
this [short video] and then reading this blog post of mine:
[_Sibit Demonstrates How Bitcoin Works_][blog].
This is a simple Bitcoin client for use from the command line
or from your Ruby app.
You don't need to run any Bitcoin software or install anything.
All you need is just a command line and [Ruby] 2.3+.
The purpose of this client is to simplify most typical operations with Bitcoin.
If you need something more complex, I would recommend using
[bitcoin-ruby] for Ruby and [Electrum] as a GUI client.
You may want to discuss this tool at [Bitcointalk]
and give the thread a few merits.
This is a Ruby gem, install it first (if it doesn't work, there are
some hints at the bottom of this page):
```bash
gem install sibit
```
Then, you generate a [private key]:
```bash
$ sibit generate
1461cc61c3b09d01d5c02b901577c9d052264e77043bddd3d222ab8a6f7e0db0
```
Next, you create a new [address],
using your private key:
```bash
$ sibit create 1461cc61c3b09d01d5c02b901577c9d052264e77043bddd3d222ab8a6f7e0db0
1PfsYNygsuVL8fvBarJNQnHytkg4rGih1U
```
To check the balance at the address (the result is in
[satoshi]):
```bash
$ sibit balance 1PfsYNygsuVL8fvBarJNQnHytkg4rGih1U
80988977
```
To send a payment from a few addresses to a new address:
```bash
$ sibit pay AMOUNT FEE P1,P2,... TARGET CHANGE
e87f138c9ebf5986151667719825c28458a28cc66f69fed4f1032a93b399fdf8
```
Here:
* `AMOUNT` is the amount of [satoshi] you are sending (integer),
or `0.42BTC` if in bitcoins (with a suffix),
* `FEE` is the [miner fee] you are ready to spend to get
this transaction delivered (you can say `S`, `M`, `L`, or `XL` if you want it
to be calculated automatically),
* `P1,P2,...` is a comma-separated list
of private keys `P` you are sending your coins from,
* `TARGET` is the address you are sending to,
* `CHANGE` is the address where the change goes.
The transaction hash is returned.
Not all [UTXOs] may be used, but only the necessary amount of them.
By default, the fee is paid on top of the payment amount you are sending.
Say, you are sending 0.5 BTC and the fee is 0.0001 BTC.
Totally, you spend 0.5001.
However, you can make Sibit deduct the fee from the payment amount.
In this case you should provide a negative amount
of the fee or one of `S-`, `M-`, `L-`, `XL-`.
You can also say `S+`, if you want the opposite, which is the default.
It is recommended to run it with `--dry --verbose` options first,
to see what's going to be sent to the network.
If everything looks correct, remove the `--dry` and run again,
the transaction is pushed to the network.
To use an HTTPS proxy for all requests:
```bash
sibit --proxy=host:port balance 1PfsYNygsuVL8fvBarJNQnHytkg4rGih1U
```
The proxy address may include authentication credentials:
```bash
sibit --proxy=user:password@host:port balance 1PfsYNygsuVL8fvBarJNQnHytkg4rGih1U
```
All operations are performed through the [Blockchain API].
Transactions are pushed to the Bitcoin network via [this relay].
## Ruby SDK
You can do the same from your Ruby app:
```ruby
require 'sibit'
sibit = Sibit.new
pkey = sibit.generate
address = sibit.create(pkey)
balance = sibit.balance(address)
target = sibit.create(pkey) # where to send coins to
change = sibit.create(pkey) # where the change goes
tx = sibit.pay(10_000_000, 'XL', { address => pkey }, target, change)
```
It should work.
## APIs
The library works through one (or a few) public APIs for fetching
Bitcoin data and pushing transactions to the network.
At the moment we work with the following APIs:
* [Blockchain.com] - `Sibit::Blockchain`
* [BTC.com] - `Sibit::Btc`
* [Cryptoapis.io] - `Sibit::Cryptoapis`
* [Bitcoinchain.com] - `Sibit::Bitcoinchain`
* [Blockchair.com] - `Sibit::Blockchair`
* [Cex.io] - `Sibit::Cex`
The first one in this list is used by default.
If you want to use a different one,
you just specify it in the constructor of `Sibit` object:
```ruby
require 'sibit'
require 'sibit/btc'
sibit = Sibit.new(api: Sibit::Btc.new)
```
You may also use a combination of APIs.
This may be very useful since some APIs are not reliable
and others don't have all the features required.
You can provide an array of objects and they are used one by one,
until a successful response is obtained:
```ruby
require 'sibit'
require 'sibit/btc'
require 'sibit/cryptoapis'
sibit = Sibit.new(
api: Sibit::FirstOf.new(
[
Sibit::Btc.new,
Sibit::Cryptoapis.new('key')
]
)
)
```
If you think we may need to use some other API, you can submit a ticket,
or implement it yourself and submit a pull request.
## How to install
To install on a fresh Ubuntu 18:
```bash
sudo apt-get update
sudo apt-get install -y ruby ruby-dev autoconf automake build-essential
sudo gem update --system
gem install rake --no-document
gem install sibit
```
It should work.
If it doesn't, submit an issue and I can try to help.
## How to contribute
Read [these guidelines].
Make sure your build is green before you contribute your pull request.
You need to have [Ruby] 2.3+ and [Bundler] installed.
Then:
```bash
bundle update
bundle exec rake
```
If it's clean and you don't see any error messages, submit your pull request.
[address]: https://en.bitcoin.it/wiki/Address
[bitcoin-ruby]: https://github.com/lian/bitcoin-ruby
[Bitcoinchain.com]: https://bitcoinchain.com/api
[Bitcointalk]: https://bitcointalk.org/index.php?topic=5130324
[Blockchain API]: https://www.blockchain.com/api/blockchain_api
[Blockchain.com]: https://www.blockchain.com/explorer
[Blockchair.com]: https://blockchair.com/api/docs
[blog]: https://www.yegor256.com/2019/05/07/sibit-bitcoin-command-line-client.html
[BTC.com]: https://btc.com/api-doc
[Bundler]: https://bundler.io/
[Cex.io]: https://cex.io/rest-api
[Cryptoapis.io]: https://docs.cryptoapis.io/rest-apis/blockchain-as-a-service-apis/btc/index
[Electrum]: https://electrum.org/
[miner fee]: https://en.bitcoin.it/wiki/Miner_fees
[private key]: https://en.bitcoin.it/wiki/Private_key
[Ruby]: https://www.ruby-lang.org/en/
[satoshi]: https://en.bitcoin.it/wiki/Satoshi_%28unit%29
[short video]: https://www.youtube.com/watch?v=IV9pRBq5A4g
[these guidelines]: https://www.yegor256.com/2014/04/15/github-guidelines.html
[this relay]: https://www.blockchain.com/btc/pushtx
[UTXOs]: https://en.wikipedia.org/wiki/Unspent_transaction_output