编译安装比特币客户端
Mac OS X 编译安装指南
翻译自https://github.com/bitcoin/bitcoin/blob/master/doc/build-osx.md
Windows系统的安装操作参看:
https://github.com/bitcoin/bitcoin/blob/master/doc/build-windows.md
我还没有翻译,哪天有空了吧 😑
准备
安装 OS X 命令行工具(这一步可省略,如果你之前有安装过,想保证万无一失的话,就重新安装一遍吧,也花不了多长时间,保证版本是一致的):
xcode-select --install
弹出输入框, 点击 安装
.
然后安装 Homebrew.这个也是,安装过就不需要安装了。
点击同意。
安装依赖
brew install automake berkeley-db4 libtool boost miniupnpc openssl pkg-config protobuf python qt libevent qrencode
查看完整依赖https://github.com/bitcoin/bitcoin/blob/master/doc/dependencies.md
如果要使用make deploy
构建磁盘映像 (.dmg / optional), 需要安装 RSVG
brew install librsvg
注意: 用Qt4构建任然是支持的,不过界面可能会出问题,建议使用Qt5来构建
Berkeley DB
如果你要自己构建建议使用DB 4.8
使用安装脚本 ./contrib/install_db4.sh .
./contrib/install_db4.sh .
注意: 只有在钱包被启用的时候你才需要Berkeley DB
构建 Bitcoin Core
-
克隆比特币源码
git clone https://github.com/bitcoin/bitcoin cd bitcoin
-
构建 bitcoin-core:
配置和构建比特币二进制文件,并且包裹GUI,如果不需要GUI的话,可以在 执行 configure的时候加上 --without-gui
参数
```
./autogen.sh
./configure
make
```
-
建议构建并运行单元测试(可选):
make check
-
创建一个包含.app软件包(可选)
make deploy
运行
现在在./src/bitcoind
就可以找到 bitcoind了。
在运行之前呢,先创建一个RPC配置文件
echo -e "rpcuser=bitcoinrpc\nrpcpassword=$(xxd -l 16 -p /dev/urandom)" > "/Users/${USER}/Library/Application Support/Bitcoin/bitcoin.conf"
chmod 600 "/Users/${USER}/Library/Application Support/Bitcoin/bitcoin.conf"
第一次运行bitcoind, 会从网络上下载区块链. 需要几个小时到几天不等。
查看下载进度:
tail -f $HOME/Library/Application\ Support/Bitcoin/debug.log
如何使用:
启动比特币服务
./src/bitcoind -daemon # 开启比特币守护进程.
之后所有操作都要保证 服务开启。
查看命令行选项列表.
./src/bitcoin-cli --help
查看RPC命令
./src/bitcoin-cli help # 当开启守护进程的时候 显示 RPC 命令的列表
关闭服务
./src/bitcoin-cli stop
启动测试网络
./src/bitcoind -daemon -testnet
关闭测试网络
./src/bitcoin-cli -testnet stop
使用RPC 命令
下面我们启动比特币测试网络
./src/bitcoind -testnet -daemon
Bitcoin server starting
注意:以下操作都在测试网络下进行,添加了 -testnet参数,正式网络不需要
查看命令帮助:
./src/bitcoin-cli -testnet help
== Blockchain ==
getbestblockhash
getblock "blockhash" ( verbosity )
getblockchaininfo
getblockcount
getblockhash height
getblockheader "hash" ( verbose )
getchaintips
getchaintxstats ( nblocks blockhash )
getdifficulty
getmempoolancestors txid (verbose)
getmempooldescendants txid (verbose)
getmempoolentry txid
getmempoolinfo
getrawmempool ( verbose )
gettxout "txid" n ( include_mempool )
gettxoutproof ["txid",...] ( blockhash )
gettxoutsetinfo
preciousblock "blockhash"
pruneblockchain
savemempool
verifychain ( checklevel nblocks )
verifytxoutproof "proof"
== Control ==
getmemoryinfo ("mode")
help ( "command" )
logging ( <include> <exclude> )
stop
uptime
== Generating ==
generate nblocks ( maxtries )
generatetoaddress nblocks address (maxtries)
== Mining ==
getblocktemplate ( TemplateRequest )
getmininginfo
getnetworkhashps ( nblocks height )
prioritisetransaction <txid> <dummy value> <fee delta>
submitblock "hexdata" ( "dummy" )
== Network ==
addnode "node" "add|remove|onetry"
clearbanned
disconnectnode "[address]" [nodeid]
getaddednodeinfo ( "node" )
getconnectioncount
getnettotals
getnetworkinfo
getpeerinfo
listbanned
ping
setban "subnet" "add|remove" (bantime) (absolute)
setnetworkactive true|false
== Rawtransactions ==
combinerawtransaction ["hexstring",...]
createrawtransaction [{"txid":"id","vout":n},...] [{"address":amount},{"data":"hex"},...] ( locktime ) ( replaceable )
decoderawtransaction "hexstring" ( iswitness )
decodescript "hexstring"
fundrawtransaction "hexstring" ( options iswitness )
getrawtransaction "txid" ( verbose "blockhash" )
sendrawtransaction "hexstring" ( allowhighfees )
signrawtransaction "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] ["privatekey1",...] sighashtype )
signrawtransactionwithkey "hexstring" ["privatekey1",...] ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] sighashtype )
testmempoolaccept ["rawtxs"] ( allowhighfees )
== Util ==
createmultisig nrequired ["key",...]
estimatesmartfee conf_target ("estimate_mode")
signmessagewithprivkey "privkey" "message"
validateaddress "address"
verifymessage "address" "signature" "message"
== Wallet ==
abandontransaction "txid"
abortrescan
addmultisigaddress nrequired ["key",...] ( "label" "address_type" )
backupwallet "destination"
bumpfee "txid" ( options )
dumpprivkey "address"
dumpwallet "filename"
encryptwallet "passphrase"
getaccount "address"
getlabeladdress "label"
getaddressesbyaccount "account"
getaddressinfo "address"
getbalance ( "account" minconf include_watchonly )
getnewaddress ( "label" "address_type" )
getrawchangeaddress ( "address_type" )
getreceivedbylabel "label" ( minconf )
getreceivedbyaddress "address" ( minconf )
gettransaction "txid" ( include_watchonly )
getunconfirmedbalance
getwalletinfo
importaddress "address" ( "label" rescan p2sh )
importmulti "requests" ( "options" )
importprivkey "privkey" ( "label" ) ( rescan )
importprunedfunds
importpubkey "pubkey" ( "label" rescan )
importwallet "filename"
keypoolrefill ( newsize )
listaccounts ( minconf include_watchonly)
listaddressgroupings
listlockunspent
listreceivedbylabel ( minconf include_empty include_watchonly)
listreceivedbyaddress ( minconf include_empty include_watchonly address_filter )
listsinceblock ( "blockhash" target_confirmations include_watchonly include_removed )
listtransactions ( "account" count skip include_watchonly)
listunspent ( minconf maxconf ["addresses",...] [include_unsafe] [query_options])
listwallets
lockunspent unlock ([{"txid":"txid","vout":n},...])
move "fromaccount" "toaccount" amount ( minconf "comment" )
removeprunedfunds "txid"
rescanblockchain ("start_height") ("stop_height")
sendfrom "fromaccount" "toaddress" amount ( minconf "comment" "comment_to" )
sendmany "fromaccount" {"address":amount,...} ( minconf "comment" ["address",...] replaceable conf_target "estimate_mode")
sendtoaddress "address" amount ( "comment" "comment_to" subtractfeefromamount replaceable conf_target "estimate_mode")
setlabel "address" "label"
settxfee amount
signmessage "address" "message"
signrawtransactionwithwallet "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] sighashtype )
walletlock
walletpassphrase "passphrase" timeout
walletpassphrasechange "oldpassphrase" "newpassphrase"
列出了所有的可用RPC命令。
比如我们要获取区块 hash
区块链常用命令示例:
getbestblockhash
然后查看该区块内容
./src/bitcoin-cli -testnet getblock 000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943
{
"hash": "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943",
"confirmations": 1,
"strippedsize": 285,
"size": 285,
"weight": 1140,
"height": 0,
"version": 1,
"versionHex": "00000001",
"merkleroot": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
"tx": [
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
],
"time": 1296688602,
"mediantime": 1296688602,
"nonce": 414098458,
"bits": "1d00ffff",
"difficulty": 1,
"chainwork": "0000000000000000000000000000000000000000000000000000000100010001"
}
查看区块数量
./src/bitcoin-cli -testnet getblockcount
根据高度查看区块hash
./src/bitcoin-cli -testnet getblockhash 0
查看指定区块头
./src/bitcoin-cli -testnet getblockheader
查看区块难度
./src/bitcoin-cli -testnet getdifficulty
钱包常用命令示例:
忽略某笔交易
abandontransaction "txid"
备份钱包
backupwallet "destination"
打印私钥
dumpprivkey "address"
打印钱包
dumpwallet "filename"
加密钱包
encryptwallet "passphrase"
获得账户
getaccount
查询余额
getbalance ( "account" minconf include_watchonly )
查看钱包信息
getwalletinfo
导入钱包
importwallet
列出所有钱包
listwallets
设置钱包解锁有效时间
walletpassphrase "passphrase" timeout
更改钱包密码
walletpassphrasechange "oldpassphrase" "newpassphrase"
其他常用命令庆查看帮助
bitcoin-cli help