network-bitcoin-0.1.5: Interface with Bitcoin RPC




Communicate with a Bitcoin daemon over JSON RPC



data Auth Source

Auth describes authentication credentials for making API requests to the Bitcoin daemon




rpcUrl :: String

URL, with port, where bitcoind listens

rpcUser :: String

same as bitcoind's rpcuser config

rpcPassword :: String

same as bitcoind's rpcpassword config


data Address Source

Represents a Bitcoin receiving address. Construct one with mkAddress.


Show Address 
ToValue Address 

mkAddress :: String -> Maybe AddressSource

Construct an Address from a String. Returns Nothing if the string is not a valid Bitcoin address.

Only validates approximate address format. Does not validate address checksum. Until full validation is done, use isValidAddress RPC call instead

type Amount = Fixed SatoshiSource

Fixed precision Bitcoin amount (to avoid floating point errors)

type Account = StringSource

Name of a Bitcoin wallet account

type MinConf = IntegerSource

Minimum number of confirmations for a payment

data AddressValidation Source

Encapsulates address validation results from validateAddress

isValid :: AddressValidation -> BoolSource

Is the address valid?

isMine :: AddressValidation -> BoolSource

Does the address belong to my wallet?

account :: AddressValidation -> AccountSource

To which account does this address belong?

data BitcoinException Source

A BitcoinException is thrown when callApi encounters an error. The API error code is represented as an Int, the message as a String.


BitcoinApiError Int String 

Individual API methods

getBalance :: Auth -> Account -> MinConf -> IO AmountSource

Returns the balance of a specific Bitcoin account

getBlockCount :: Auth -> IO IntegerSource

Returns the number of blocks in the longest block chain

getConnectionCount :: Auth -> IO IntegerSource

Returns the number of connections to other nodes

getDifficulty :: Auth -> IO DoubleSource

Returns the proof-of-work difficulty as a multiple of the minimum difficulty

getGenerate :: Auth -> IO BoolSource

Indicates whether the node is generating or not

getHashesPerSec :: Auth -> IO IntegerSource

Returns a recent hashes per second performance measurement while generating

getReceivedByAccount :: Auth -> Account -> MinConf -> IO AmountSource

Returns the total amount received by addresses with account in transactions with at least minconf confirmations

getReceivedByAddress :: Auth -> Address -> MinConf -> IO AmountSource

Returns the total amount received by an address in transactions with at least minconf confirmations.

validateAddress :: Auth -> Address -> IO AddressValidationSource

Return information about an address. If the address is invalid or doesn't belong to us, the account name is the empty string.

isValidAddress :: Auth -> Address -> IO BoolSource

Returns true if the RPC says the address is valid. Use this function until mkAddress verifies address checksums

Low-level API



:: Auth

authentication credentials for bitcoind

-> String

command name

-> [Value]

command arguments

-> IO Value 

callApi is a low-level interface for making authenticated API calls to a Bitcoin daemon. The first argument specifies authentication details (URL, username, password) and is often curried for convenience:

 callBtc = callApi $ Auth "" "user" "password"

The second argument is the command name. The third argument provides parameters for the API call.

 let result = callBtc "getbalance" ["account-name", Number 6]

On error, throws a BitcoinException

class FromNumber a whereSource

Convert JSON numeric values to more specific numeric types


fromNumber :: Number -> aSource