首页 技术 正文
技术 2022年11月21日
0 收藏 367 点赞 2,719 浏览 2571 个字

BTC本地测试节点

环境 ubuntu 16.4

#客户端安装

 #下载页面
#https://bitcoin.org/zh_CN/downloadcd /opt/
wget https://bitcoin.org/bin/bitcoin-core-0.17.0.1/bitcoin-0.17.0.1-x86_64-linux-gnu.tar.gz #解压,软连接
tar zxf bitcoin-0.17.0.1-x86_64-linux-gnu.tar.gz
ln -fs /opt/bitcoin-0.17.0 /opt/bitcoin
ln -fs /opt/bitcoin-0.17.0/bin/bitcoind /usr/local/bin/bitcoind
ln -fs /opt/bitcoin-0.17.0/bin/bitcoin-cli /usr/local/bin/bitcoin-cli

#创建配置

mkdir ~/.bitcoin
vim ~/.bitcoin/bitcoin.conf
# ~/.bitcoin/bitcoin.conf
dbcache=10240
txindex=1
rpcuser=btc
rpcpassword=btc2018
daemon=1
server=1
rest=1
rpcallowip=0.0.0.0/0
deprecatedrpc=accounts
#local testnet
regtest=1

#后台启动

bitcoind -daemon

#关闭

bitcoin-cli stop

#命令练习

#查看钱包信息
bitcoin-cli -regtest getwalletinfo#挖101个block,挖矿奖励在100个block后才能使用
bitcoin-cli -regtest generate 101#查看挖矿奖励
bitcoin-cli -regtest getbalance
#查看默认hash地址
bitcoin-cli -regtest getaccountaddress ""
# 2MueCwwme7SZzuXpe2NYvHGUxx7KaaoCbpj#生成新的地址
bitcoin-cli -regtest getnewaddress "test"
2Myr43NbpxMM3W2iTq5ifec66wFwNVWyMeM
#查看私钥
bitcoin-cli dumpprivkey 2Myr43NbpxMM3W2iTq5ifec66wFwNVWyMeM#账户列表
bitcoin-cli listaccounts#在test账户新建地址
bitcoin-cli -regtest getnewaddress "test"
# 2NAq5QXCPCQcosCxdYMrPxZoXAjU9h2misi
#查看账户test下的地址
bitcoin-cli getaddressesbyaccount "test"
#查地址所属账户
bitcoin-cli getaccount 2NAq5QXCPCQcosCxdYMrPxZoXAjU9h2misi
#查看账户余额
bitcoin-cli getbalance "test"
#查看地址收到币的数量
bitcoin-cli getreceivedbyaddress 2NAq5QXCPCQcosCxdYMrPxZoXAjU9h2misi#从默认账户给目标地址转账
bitcoin-cli sendtoaddress "2NAq5QXCPCQcosCxdYMrPxZoXAjU9h2misi" 0.1
#从指定账户转账
bitcoin-cli sendfrom "test" "n3BMgZMA26TcHnVa5iNJeB3PMqkF3cEWBE" 0.01#生成一个区块,使得交易得到确认(测试网络使用)
bitcoin-cli -regtest generate 1
#再次查看账户余额
bitcoin-cli getbalance "test"#查看收到的比特币
bitcoin-cli -regtest listreceivedbyaddress#查看交易详情
bitcoin-cli gettransaction 550d0bab60193a5edfd2636b6187bbdd557eb167a800b8f8d88edb1a037f19bd
#查看raw交易
bitcoin-cli getrawtransaction d0bab60193a5edfd2636b6187bbdd557eb167a800b8f8d88edb1a037f19bd# rpc api访问测试,查询getwalletinfo
curl -s -X POST --user btc:btc2018 \
-H 'content-type: text/plain;' http://127.0.0.1:18443/ \
--data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getwalletinfo", "params": [] }'#命令列表
bitcoin-cli help
#某个命令的详细帮助信息
bitcoin-cli help sendtoaddress

regtest 启动regtest网络,适合自己测试玩

参考

https://www.felix021.com/blog/read.php?2183

https://www.jianshu.com/p/1891a083e4fe

#钱包操作

#加密钱包:bitcoin-cli encryptwallet 密码
#解密钱包:bitcoin-cli walletpassphrase 密码 360(指多少秒后加密)
#改变解锁钱包的密码短语(test 改 test1)
bitcoin-cli -testnet walletpassphrasechange test test1
#删除内存中的加密密匙
bitcoin-cli -testnet walletlock#备份钱包:
bitcoin-cli importwallet wallet.backup
#导入备份的钱包
bitcoin-cli importwallet wallet.backup
#导出明文私钥
bitcoin-cli dumpwallet wallet.txt
#bitcoin-cli importwallet 导入钱包的文件名 #参考
# http://8btc.com/thread-84788-1-3.html
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,020
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,772
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,850