mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-01-19 05:43:51 +01:00
.. | ||
src/main/scala/org/bitcoins/rpc | ||
README.md |
Note:
bitcoin-s-bitcoind-rpc
requires you to havebitcoind
(Bitcoin Core daemon) installed. Grab this at bitcoincore.org
Usage
The Bitcoin Core RPC client in Bitcoin-S currently supports the Bitcoin Core 0.16 and 0.17 version lines. It can be set up to work with both local and remote Bitcoin Core servers.
Basic example
import org.bitcoins.rpc
import rpc.client.common._
import rpc.config.BitcoindInstance
import akka.actor.ActorSystem
// data directory defaults to ~/.bitcoin on Linux and
// ~/Library/Application Support/Bitcoin on macOS
val bitcoindInstance = BitcoindInstance.fromDatadir()
// alternative:
import java.io.File
val dataDir = new File("/my/bitcoin/data/dir")
val otherInstance = BitcoindInstance.fromDatadir(dataDir)
implicit val actorSystem: ActorSystem = ActorSystem.create()
val client = new BitcoindRpcClient(bitcoindInstance)
for {
_ <- client.start()
balance <- client.getBalance
} yield balance
Advanced example
TODO: How to connect to remote bitcoind
Testing
To test the Bitcoin-S RPC project you need both version 0.16 and 0.17 of Bitcoin Core. A list of current and previous releases can be found here.
You then need to set environment variables to indicate where Bitcoin-S can find the different versions:
$ export BITCOIND_V16_PATH=/path/to/v16/bitcoind
$ export BITCOIND_V17_PATH=/path/to/v17/bitcoind
If you just run tests testing common functionality it's enough to have either version 0.16 or 0.17 on your PATH
.
To run all RPC related tests:
$ bash sbt bitcoindRpcTest/test