Btcd交互式工具btcctl的一些常用命令

* 前言 <https://blog.csdn.net/qq_31739317/article/details/88714084#_2>
* 命令概览 <https://blog.csdn.net/qq_31739317/article/details/88714084#_8>
* 常用命令介绍 <https://blog.csdn.net/qq_31739317/article/details/88714084#_119>
* Chain Server Commands
<https://blog.csdn.net/qq_31739317/article/details/88714084#Chain_Server_Commands_120>
* ```decoderawtransaction "hextx" ```
<https://blog.csdn.net/qq_31739317/article/details/88714084#decoderawtransaction_hextx__121>
* ```generate numblocks```
<https://blog.csdn.net/qq_31739317/article/details/88714084#generate_numblocks_125>
* ```getblcokcount```
<https://blog.csdn.net/qq_31739317/article/details/88714084#getblcokcount_129>
* ```getblockhash index```
<https://blog.csdn.net/qq_31739317/article/details/88714084#getblockhash_index_132>
* ```getblock "hash"```
<https://blog.csdn.net/qq_31739317/article/details/88714084#getblock_hash_135>
* ```getrawtransaction "txid"```
<https://blog.csdn.net/qq_31739317/article/details/88714084#getrawtransaction_txid_138>
* ```setgenerate generate```
<https://blog.csdn.net/qq_31739317/article/details/88714084#setgenerate_generate_141>
* Wallet Server Commands
<https://blog.csdn.net/qq_31739317/article/details/88714084#Wallet_Server_Commands_147>
* ```getaddressesbyaccount "account"```
<https://blog.csdn.net/qq_31739317/article/details/88714084#getaddressesbyaccount_account_148>
* ```getnewaddress "account"```
<https://blog.csdn.net/qq_31739317/article/details/88714084#getnewaddress_account_151>
* ```gettransaction "txid"```
<https://blog.csdn.net/qq_31739317/article/details/88714084#gettransaction_txid_154>
* ```listaccounts```
<https://blog.csdn.net/qq_31739317/article/details/88714084#listaccounts_157>
* ```listtransactions "account"```
<https://blog.csdn.net/qq_31739317/article/details/88714084#listtransactions_account_160>
* ```sendfrom "fromaccount" "toaddress" amount```
<https://blog.csdn.net/qq_31739317/article/details/88714084#sendfrom_fromaccount_toaddress_amount_163>
* ```sendmany "fromaccount" {"address":amount,...}```
<https://blog.csdn.net/qq_31739317/article/details/88714084#sendmany_fromaccount_addressamount_167>
* ```sendtoaddress "address" amount```
<https://blog.csdn.net/qq_31739317/article/details/88714084#sendtoaddress_address_amount_170>
* 结尾 <https://blog.csdn.net/qq_31739317/article/details/88714084#_174>


<>前言

上一篇文章介绍了单节点和双节点的btcd使用,也用btcctl命令做了一些交互。
这篇文章介绍一些btcctl我至今经常用的命令。
本文章不定期更新

<>命令概览

通过btcctl -l可以看到所有的btcctl的命令
Chain Server Commands: addnode "addr" "add|remove|onetry" createrawtransaction
[{"txid":"value","vout":n},...] {"address":amount,...} (locktime) debuglevel
"levelspec" decoderawtransaction "hextx" decodescript "hexscript" generate
numblocks getaddednodeinfo dns ("node") getbestblock getbestblockhash getblock
"hash" (verbose=true verbosetx=false) getblockchaininfo getblockcount
getblockhash index getblockheader "hash" (verbose=true) getblocktemplate
({"mode":"value","capabilities":["capability",...],"longpollid":"value","sigoplimit":sigoplimit,"sizelimit":sizelimit,"maxversion":n,"target":"value","data":"value","workid":"value"})
getcfilter "hash" filtertype getcfilterheader "hash" filtertype getchaintips
getconnectioncount getcurrentnet getdifficulty getgenerate gethashespersec
getheaders ["blocklocator",...] "hashstop" getinfo getmempoolentry "txid"
getmempoolinfo getmininginfo getnettotals getnetworkhashps (blocks=120
height=-1) getnetworkinfo getpeerinfo getrawmempool (verbose=false)
getrawtransaction "txid" (verbose=0) gettxout "txid" vout (includemempool=true)
gettxoutproof ["txid",...] ("blockhash") gettxoutsetinfo getwork ("data") help
("command") invalidateblock "blockhash" node "connect|remove|disconnect"
"target" ("perm|temp") ping preciousblock "blockhash" reconsiderblock
"blockhash" searchrawtransactions "address" (verbose=1 skip=0 count=100
vinextra=0 reverse=false ["filteraddr",...]) sendrawtransaction "hextx"
(allowhighfees=false) setgenerate generate (genproclimit=-1) stop submitblock
"hexblock" ({"workid":"value"}) uptime validateaddress "address" verifychain
(checklevel=3 checkdepth=288) verifymessage "address" "signature" "message"
verifytxoutproof "proof" version Wallet Server Commands (--wallet):
addmultisigaddress nrequired ["key",...] ("account") addwitnessaddress
"address" createmultisig nrequired ["key",...] createnewaccount "account"
dumpprivkey "address" dumpwallet "filename" encryptwallet "passphrase"
estimatefee numblocks estimatepriority numblocks getaccount "address"
getaccountaddress "account" getaddressesbyaccount "account" getbalance
("account" minconf=1) getnewaddress ("account") getrawchangeaddress ("account")
getreceivedbyaccount "account" (minconf=1) getreceivedbyaddress "address"
(minconf=1) gettransaction "txid" (includewatchonly=false) getwalletinfo
importaddress "address" "account" (rescan=true) importprivkey "privkey"
("label" rescan=true) importpubkey "pubkey" (rescan=true) importwallet
"filename" keypoolrefill (newsize=100) listaccounts (minconf=1)
listaddressgroupings listlockunspent listreceivedbyaccount (minconf=1
includeempty=false includewatchonly=false) listreceivedbyaddress (minconf=1
includeempty=false includewatchonly=false) listsinceblock ("blockhash"
targetconfirmations=1 includewatchonly=false) listtransactions ("account"
count=10 from=0 includewatchonly=false) listunspent (minconf=1 maxconf=9999999
["address",...]) lockunspent unlock [{"txid":"value","vout":n},...] move
"fromaccount" "toaccount" amount (minconf=1 "comment") renameaccount
"oldaccount" "newaccount" sendfrom "fromaccount" "toaddress" amount (minconf=1
"comment" "commentto") sendmany "fromaccount" {"address":amount,...} (minconf=1
"comment") sendtoaddress "address" amount ("comment" "commentto") setaccount
"address" "account" settxfee amount signmessage "address" "message"
signrawtransaction "rawtx"
([{"txid":"value","vout":n,"scriptpubkey":"value","redeemscript":"value"},...]
["privkey",...] flags="ALL") walletlock walletpassphrase "passphrase" timeout
walletpassphrasechange "oldpassphrase" "newpassphrase"
可以看到命令主要分两大类 Chain Server Commands 和 Wallet Server Commands , Wallet Server
Commands在运行的时候需要加上--wallet参数

<>常用命令介绍

<>Chain Server Commands

*
<>decoderawtransaction "hextx"

将rawtransaction解码成便于观看的交易信息格式。这个命令主要是将getrawtransaction命令返回的字节码解码成交易信息的格式(如
gettransaction命令返回的信息)
后面的参数hextx就是十六进制的字节码

*
<>generate numblocks


手动生成区块的命令。手动生成区块其实和自动挖矿的原理是一样的(将交易打包、完成coinbase交易等等),只不过我们可以指定生成区块的个数。自动挖矿挖的区块个数是不可控的。
我前一篇文章有写,如果要自动挖矿必须更改defaultGenerate参数,从false改为true,并且需要至少有一个节点与本地相连,才可以自动进行挖矿。

*
<>getblcokcount

获取当前区块链一共拥有的区块个数,这个个数是不包括创世区块的,所以链上如果只有一个创世区块,getblockcount返回0。

*
<>getblockhash index

当通过getblockcount看到一共有多少区块之后,可以用getblockhash命令来查看某个区块的唯一hash值。注意创世区块的索引值为0

*
<>getblock "hash"

当通过getblockhash拿到区块的Hash之后,可以通过getblock命令指定区块的hash值,就可以查看到区块的具体信息

*
<>getrawtransaction "txid"


该命令可以通过指定txid查询区块链上的任何一笔交易的内容,txid指的是区块中交易的hash值,返回值是十六进制字节码,通过上述的decoderawtransaction命令可以解码成能看懂的交易信息
值得注意的是,getrawtransaction命令可以查看区块链上任意一笔交易的内容,不限于和本地钱包地址有关的交易。后面钱包命令的
gettransaction也是查询交易内容,但是只能查询和本地钱包地址有关的交易,其他的交易是查询不到的。

*
<>setgenerate generate

这个命令是控制是否要cpu自动进行挖矿,前面说到当更改了defaultGenerate参数为true之后,就开启了CPU自动挖矿。
因为开启了CPU自动挖矿之后是不能再用generate手动生成区块的。
如果这个时候我们想手动挖矿,可以setgenerate 0,置0将自动挖矿关闭,置1是将自动挖矿打开

<>Wallet Server Commands

*
<>getaddressesbyaccount "account"

此命令可以输出account账户下所有的地址

*
<>getnewaddress "account"

给account用户新建一个地址,如果不指定account是默认给default账户生成一个地址

*
<>gettransaction "txid"

查询本地钱包的某个交易,回显信息是可以读懂的交易信息格式,不需要进行解码

*
<>listaccounts

输出所有账户及相关余额

*
<>listtransactions "account"

输出指定账户的前部交易信息,默认显示十条

*
<>sendfrom "fromaccount" "toaddress" amount

这个命令我进行测试的时候
fromaccount账户好像必须是default账户才能成功进行转账,不知道哪里出了问题不过没有深究,"toaddress"是地址。

*
<>sendmany "fromaccount" {"address":amount,...}

同上,做测试的时候 fromaccount账户必须是default账户才能成功进行转账,后面大括号可以同时指定多个地址

*
<>sendtoaddress "address" amount

从default账户给指定地址转钱

<>结尾

我到现在用的多的就是上面这些命令,而且经过我的测试,有一些命令好像还没有支持完全,希望以后能够逐渐完善。

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信