當我們安裝好bitcoin客戶端之后灼擂,會自己在家目錄下面生成一個.bitcoin
文件忱辅,然后我們可以在這個目錄下面建議一個配置文件坊谁,形如:
rpcuser=rpc
rpcpassword=xxxxxxx
rpcport=18332
daemon=1
server=1
testnet=1
whitelist=1.1.1.1
rpcallowip=1.1.1.1
使用bitcoin-cli help
可以看到會輸出如下命令:
== Blockchain ==
getbestblockhash
getblock "blockhash" ( verbose )
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
verifychain ( checklevel nblocks )
verifytxoutproof "proof"
== Control ==
getinfo
getmemoryinfo
help ( "command" )
stop
uptime
== Generating ==
generate nblocks ( maxtries )
generatetoaddress nblocks address (maxtries)
== Mining ==
getblocktemplate ( TemplateRequest )
getmininginfo
getnetworkhashps ( nblocks height )
prioritisetransaction <txid> <priority delta> <fee delta>
submitblock "hexdata" ( "jsonparametersobject" )
== Network ==
addnode "node" "add|remove|onetry"
clearbanned
disconnectnode "[address]" [nodeid]
getaddednodeinfo ( "node" )
getconnectioncount
getexcessiveblock
getnettotals
getnetworkinfo
getpeerinfo
listbanned
ping
setban "subnet" "add|remove" (bantime) (absolute)
setexcessiveblock blockSize
setnetworkactive true|false
== Omni layer (configuration) ==
whc_setautocommit flag
== Omni layer (data retrieval) ==
whc_getactivecrowd address
whc_getallbalancesforaddress "address"
whc_getallbalancesforid propertyid
whc_getbalance "address" propertyid
whc_getbalanceshash propertyid
whc_getcrowdsale propertyid ( verbose )
whc_getcurrentconsensushash
whc_getgrants propertyid
whc_getinfo
whc_getpayload "txid"
whc_getproperty propertyid
whc_getseedblocks startblock endblock
whc_getsto "txid" "recipientfilter"
whc_gettransaction "txid"
whc_listblocktransactions index
whc_listpendingtransactions ( "address" )
whc_listproperties
whc_listtransactions ( "address" count skip startblock endblock )
== Omni layer (payload creation) ==
whc_createpayload_burnbch
whc_createpayload_changeissuer propertyid
whc_createpayload_closecrowdsale propertyid
whc_createpayload_grant propertyid "amount" ( "memo" )
whc_createpayload_issuancecrowdsale ecosystem type previousid "category" "subcategory" "name" "url" "data" propertyiddesired tokensperunit deadline earlybonus issuerpercentage amount
whc_createpayload_issuancefixed ecosystem type previousid "category" "subcategory" "name" "url" "data" "amount"
whc_createpayload_issuancemanaged ecosystem type previousid "category" "subcategory" "name" "url" "data"
whc_createpayload_particrowdsale "amount"
whc_createpayload_revoke propertyid "amount" ( "memo" )
whc_createpayload_sendall ecosystem
whc_createpayload_simplesend propertyid "amount"
whc_createpayload_sto propertyid "amount" ( distributionproperty )
== Omni layer (raw transactions) ==
whc_createrawtx_change "rawtx" "prevtxs" "destination" fee ( position )
whc_createrawtx_input "rawtx" "txid" n
whc_createrawtx_opreturn "rawtx" "payload"
whc_createrawtx_reference "rawtx" "destination" ( amount )
whc_decodetransaction "rawtx" ( "prevtxs" height )
== Omni layer (transaction creation) ==
whc_burnbchgetwhc "amount" redeemaddress
whc_particrowsale "fromaddress" "toaddress" "amount" ( "redeemaddress" "referenceamount" )
whc_send "fromaddress" "toaddress" propertyid "amount" ( "redeemaddress" "referenceamount" )
whc_sendall "fromaddress" "toaddress" ecosystem ( "redeemaddress" "referenceamount" )
whc_sendchangeissuer "fromaddress" "toaddress" propertyid
whc_sendclosecrowdsale "fromaddress" propertyid
whc_sendgrant "fromaddress" "toaddress" propertyid "amount" ( "memo" )
whc_sendissuancecrowdsale "fromaddress" ecosystem precision previousid "category" "subcategory" "name" "url" "data" propertyiddesired tokensperunit deadline earlybonus undefine totalNumber
whc_sendissuancefixed "fromaddress" ecosystem precision previousid "category" "subcategory" "name" "url" "data" "totalNumber"
whc_sendissuancemanaged "fromaddress" ecosystem precision previousid "category" "subcategory" "name" "url" "data"
whc_sendrawtx "fromaddress" "rawtransaction" ( "referenceaddress" "redeemaddress" "referenceamount" )
whc_sendrevoke "fromaddress" propertyid "amount" ( "memo" )
whc_sendsto "fromaddress" propertyid "amount" ( "redeemaddress" distributionproperty )
== Rawtransactions ==
createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,"data":"hex",...} ( locktime )
decoderawtransaction "hexstring"
decodescript "hexstring"
fundrawtransaction "hexstring" ( options )
getrawtransaction "txid" ( verbose )
sendrawtransaction "hexstring" ( allowhighfees )
signrawtransaction "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] ["privatekey1",...] sighashtype )
== Util ==
createmultisig nrequired ["key",...]
estimatefee nblocks
signmessagewithprivkey "privkey" "message"
validateaddress "address"
verifymessage "address" "signature" "message"
== Wallet ==
abandontransaction "txid"
addmultisigaddress nrequired ["key",...] ( "account" )
backupwallet "destination"
dumpprivkey "address"
dumpwallet "filename"
encryptwallet "passphrase"
getaccount "address"
getaccountaddress "account"
getaddressesbyaccount "account"
getbalance ( "account" minconf include_watchonly )
getnewaddress ( "account" )
getrawchangeaddress
getreceivedbyaccount "account" ( minconf )
getreceivedbyaddress "address" ( minconf )
gettransaction "txid" ( include_watchonly )
getunconfirmedbalance
getwalletinfo
importaddress "address" ( "label" rescan p2sh )
importmulti "requests" "options"
importprivkey "bitcoinprivkey" ( "label" ) ( rescan )
importprunedfunds
importpubkey "pubkey" ( "label" rescan )
importwallet "filename"
keypoolrefill ( newsize )
listaccounts ( minconf include_watchonly)
listaddressgroupings
listlockunspent
listreceivedbyaccount ( minconf include_empty include_watchonly)
listreceivedbyaddress ( minconf include_empty include_watchonly)
listsinceblock ( "blockhash" target_confirmations include_watchonly)
listtransactions ( "account" count skip include_watchonly)
listunspent ( minconf maxconf ["addresses",...] [include_unsafe] )
listwallets
lockunspent unlock ([{"txid":"txid","vout":n},...])
move "fromaccount" "toaccount" amount ( minconf "comment" )
removeprunedfunds "txid"
sendfrom "fromaccount" "toaddress" amount ( minconf "comment" "comment_to" )
sendmany "fromaccount" {"address":amount,...} ( minconf "comment" ["address",...] )
sendtoaddress "address" amount ( "comment" "comment_to" subtractfeefromamount )
setaccount "address" "account"
settxfee amount
signmessage "address" "message"
一些常用命令的解釋
-
bitcoin-cli getinfo
獲得比特幣核心客戶端狀態(tài)的信息 -
bitcoin-cli getbalance
命令將顯示錢包當前的所有地址的余額總和 -
bitcoin-cli listunspent
查看我們錢包中所有剩余的從之前交易中已確認的支出弃舒; -
bitcoin-cli createrawtransaction '[{"txid":"myid","vout":0}]' '{"address":0.01}'
該命令用來創(chuàng)建交易鸽粉,可以根據(jù) listunspent 獲取它的 txid ,amount 的數(shù)值不能太大触机,否則會提示昂貴的交易費。執(zhí)行完成之后會生成一個 hexString儡首,用來驗證交易時使用。 -
bitcoin-cli signrawtransaction "hexstring" ‘[{"txid":"id","vout":n, "amount":value,"scriptPubKey":"hex","redeemScript":"hex"},...]’ ‘["privatekey1",...]’ sighashtype
該命令用來簽名交易蔬胯,注意:amount 應(yīng)該是 listunspent 反應(yīng)的 amount 的值,scriptPubKey 也是 listunspent 中的 scriptPubKey 笔宿,sighashtype 的默認值是 all犁钟,可以不寫泼橘,redeemScript 是多重簽名驗證,沒有特殊要求可以不寫炬灭。執(zhí)行完成之后會生成一個 signedhex 的簽名驗證碼。 -
bitcoin-cli sendrawtransaction "signedhex"
該命令用來發(fā)送交易重归。 -
bitcoin-cli walletpassphrase 密碼 時間
walletpassphrase命令需要兩個參數(shù)——密碼米愿,和多久錢包會再次被自動鎖定的秒數(shù)數(shù)字(計時器)精居。該命令是用來解鎖錢包的屯耸,執(zhí)行完成什么也不會輸出腥放,代表解鎖完成编兄。 -
bitcoin-cli dumpprivkey "address"
該命令用來獲取 privateKey,在第五步中會需要灭红。
至此脓斩,一個簡單的交易過程結(jié)束证逻。
- 其他命令
- 探索及解碼交易
- gettransaction 命令探索本錢包前面列出的入賬交易;
- bitcoin-cli gettransaction 交易ID
- getrawtransaction命令獲取交易的原始數(shù)據(jù)
- bitcoin-cli getrawtransaction 交易ID
- decoderawtransaction命令解碼交易的原始數(shù)據(jù)香椎,輸出json格式
- bitcoin-cli decoderawtransaction 交易的原始數(shù)據(jù)
- gettransaction 命令探索本錢包前面列出的入賬交易;
- 探索區(qū)塊
- getblock命令漱竖,把區(qū)塊的哈希值作為參數(shù)來查詢對應(yīng)的區(qū)塊。
- bitcoin-cli getblock 區(qū)塊哈希
- getblockhash命令通過區(qū)塊高度來檢索一個區(qū)塊的哈希畜伐;
- bitcoin-cli getblockhash 區(qū)塊高度
- getblock命令漱竖,把區(qū)塊的哈希值作為參數(shù)來查詢對應(yīng)的區(qū)塊。
- 基于UTXO的建立馍惹,簽名與提交
- listunspent命令去查看我們錢包中所有剩余的從之前交易中已確認的支出;
- bitcoin-cli listunspent
- gettxout 命令來得到未花費的輸出的詳細細節(jié)玛界。
- bitcoin-cli gettxout 交易ID 0
- listunspent命令去查看我們錢包中所有剩余的從之前交易中已確認的支出;
- 錢包地址及接收交易
- bitcoin-cli getnewaddress ; 獲取新的地址
- 整個錢包接收到的交易可以通過使用listtransactions命令展示出來:
- bitcoin-cli listtransactions;
- 詢問bitcoind客戶端此地址已經(jīng)接收到的比特幣數(shù)額万矾,以及指定該數(shù)額要被加到余額中所需要的確認數(shù);
- bitcoin-cli getreceivedbyaddress 錢包地址 確認數(shù);
- 使用getaddressesbyaccount命令列出整個錢包的所有地址
- bitcoin-cli getaddressesbyaccount ""
- getbalance命令將顯示錢包當前的所有地址的余額總和
- bitcoin-cli getbalance
RPC命令
命令: getblocktemplate
If the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.
It returns data needed to construct a block to work on.
For full specification, see BIPs 22, 23, 9, and 145:
https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki
https://github.com/bitcoin/bips/blob/master/bip-0023.mediawiki
https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes
https://github.com/bitcoin/bips/blob/master/bip-0145.mediawiki
Arguments:
1. template_request (json object, optional) A json object in the following spec
{
"mode":"template" (string, optional) This must be set to "template", "proposal" (see BIP 23), or omitted
"capabilities":[ (array, optional) A list of strings
"support" (string) client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'
,...
]
}
Result:
{
"version" : n, (numeric) The preferred block version
"previousblockhash" : "xxxx", (string) The hash of current highest block
"transactions" : [ (array) contents of non-coinbase transactions that should be included in the next block
{
"data" : "xxxx", (string) transaction data encoded in hexadecimal (byte-for-byte)
"txid" : "xxxx", (string) transaction id encoded in little-endian hexadecimal
"hash" : "xxxx", (string) hash encoded in little-endian hexadecimal (including witness data)
"depends" : [ (array) array of numbers
n (numeric) transactions before this one (by 1-based index in 'transactions' list) that must be present in the final block if this one is
,...
],
"fee": n, (numeric) difference in value between transaction inputs and outputs (in Satoshis); for coinbase transactions, this is a negative Number of the total collected block fees (ie, not including the block subsidy); if key is not present, fee is unknown and clients MUST NOT assume there isn't one
"sigops" : n, (numeric) total SigOps cost, as counted for purposes of block limits; if key is not present, sigop cost is unknown and clients MUST NOT assume it is zero
"required" : true|false (boolean) if provided and true, this transaction must be in the final block
}
,...
],
"coinbaseaux" : { (json object) data that should be included in the coinbase's scriptSig content
"flags" : "xx" (string) key name is to be ignored, and value included in scriptSig
},
"coinbasevalue" : n, (numeric) maximum allowable input to coinbase transaction, including the generation award and transaction fees (in Satoshis)
"coinbasetxn" : { ... }, (json object) information for coinbase transaction
"target" : "xxxx", (string) The hash target
"mintime" : xxx, (numeric) The minimum timestamp appropriate for next block time in seconds since epoch (Jan 1 1970 GMT)
"mutable" : [ (array of string) list of ways the block template may be changed
"value" (string) A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'
,...
],
"noncerange" : "00000000ffffffff",(string) A range of valid nonces
"sigoplimit" : n, (numeric) limit of sigops in blocks
"sizelimit" : n, (numeric) limit of block size
"curtime" : ttt, (numeric) current timestamp in seconds since epoch (Jan 1 1970 GMT)
"bits" : "xxxxxxxx", (string) compressed target of next block
"height" : n (numeric) The height of the next block
}
命令:getmininginfo
getmininginfo
Returns a json object containing mining-related information.
Result:
{
"blocks": nnn, (numeric) The current block
"currentblocksize": nnn, (numeric) The last block size
"currentblocktx": nnn, (numeric) The last block transaction
"difficulty": xxx.xxxxx (numeric) The current difficulty
"errors": "..." (string) Current errors
"networkhashps": nnn, (numeric) The network hashes per second
"pooledtx": n (numeric) The size of the mempool
"chain": "xxxx", (string) current network name as defined in BIP70 (main, test, regtest)
}
命令:getnetworkhashps
getnetworkhashps ( nblocks height )
Returns the estimated network hashes per second based on the last n blocks.
Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.
Pass in [height] to estimate the network speed at the time when a certain block was found.
Arguments:
1. nblocks (numeric, optional, default=120) The number of blocks, or -1 for blocks since last difficulty change.
2. height (numeric, optional, default=-1) To estimate at the time of the given height.
Result:
x (numeric) Hashes per second estimated
命令: prioritisetransaction
prioritisetransaction <txid> <priority delta> <fee delta>
Accepts the transaction into mined blocks at a higher (or lower) priority
Arguments:
1. "txid" (string, required) The transaction id.
2. priority_delta (numeric, required) The priority to add or subtract.
The transaction selection algorithm considers the tx as it would have a higher priority.
(priority of a transaction is calculated: coinage * value_in_satoshis / txsize)
3. fee_delta (numeric, required) The fee value (in satoshis) to add (or subtract, if negative).
The fee is not actually paid, only the algorithm for selecting transactions into a block
considers the transaction as it would have paid a higher (or lower) fee.
Result:
true (boolean) Returns true
命令:submitblock
"submitblock ""hexdata"" ( ""jsonparametersobject"" )
Attempts to submit new block to network.
The 'jsonparametersobject' parameter is currently ignored.
See https://en.bitcoin.it/wiki/BIP_0022 for full specification.
Arguments
1. ""hexdata"" (string, required) the hex-encoded block data to submit
2. ""parameters"" (string, optional) object of optional parameters
{
""workid"" : ""id"" (string, optional) if the server provided a workid, it MUST be included with submissions
}
Result:"