current position:Home>Bitcoin series - BTC synchronous public chain, test chain and private chain

Bitcoin series - BTC synchronous public chain, test chain and private chain

2022-02-03 05:27:49 Brick moving leader

(1) Connect to public chain

The front desk operation

bitcoind
	# If you make a mistake , It should be the relationship between environmental variables 
	bitcoind: error while loading shared libraries: libboost_system.so.1.64.0: cannot open shared object file: No such file or directory

	# Configure environment variables 
	vim ~/.bashrc
	# Add the following :
	LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:/usr/local/lib:/usr/local/lib64
	export LD_LIBRARY_PATH
	export PYTHONPATH=.
	# Save exit after execution 
	source ~/.bashrc

Background operation

Start and synchronize blocks
bitcoind -daemon
start-up Unsynchronized blocks
bitcoind -daemon -maxconnections=0

#####  The public chain runs this sentence  ############
bitcoind -daemon -deprecatedrpc=estimatefee

# Can use mining commands  ( Has been abandoned )
bitcoind -daemon -deprecatedrpc=setgenerate

# Command to enable account 
bitcoind -daemon -deprecatedrpc=accounts
# Unsynchronized blocks 
bitcoind -daemon -maxconnections=0 -deprecatedrpc=accounts

Common command line commands

# Add synchronization nodes 
bitcoin-cli addnode "119.23.63.114:8333" onetry
# View synchronization information 
bitcoin-cli -getinfo
# see account And balance 
bitcoin-cli listaccounts
# Transaction information view 
bitcoin-cli listtransactions
# List all addresses of the whole wallet  
bitcoin-cli getaddressesbyaccount ""
# List all addresses and balances of the whole wallet 
bitcoin-cli listaddressgroupings
# Displays the total balance of all addresses currently managed by the wallet  
bitcoin-cli getbalance
bitcoin-cli getbalance  Address  
# Stop running 
bitcoin-cli stop

(2) Connect to the test network

The front desk operation

bitcoind -testnet
bitcoind -testnet -gen    //-gen The parameter represents the start of mining 

#####  Test chain run  ############
 Began to run  ( Background operation )
bitcoind -testnet -daemon -deprecatedrpc=accounts
 Unsynchronized blocks 
bitcoind -testnet -daemon -maxconnections=0 -deprecatedrpc=accounts
#############################

# Stop running 
bitcoin-cli -testnet stop

# Generate blocks 
bitcoin-cli -regtest generate 101
# Generate wallet address 
bitcoin-cli -regtest getnewaddress
# Generate wallet address   Designated account 
bitcoin-cli -regtest getnewaddress "platform"
# Query the private key of the address 
bitcoin-cli -regtest dumpprivkey 2MvSvdJBGSZVfdMGYXFpnDofv3ADQBeXPq4
# Transfer accounts  ( The unit is btc)
bitcoin-cli -regtest sendtoaddress [ADDRESS] [AMOUNT]
bitcoin-cli -regtest sendtoaddress 2MxNL6tPRKNCEWqrC1z5Sw9WWNVqA39nDc8 2
# Transaction information view ( Transactions at wallet managed addresses )
bitcoin-cli -regtest listtransactions
bitcoin-cli -regtest gettransaction txid
bitcoin-cli decoderawtransaction hex

Common wallet commands

#** Generate wallet address **
bitcoin-cli -testnet getnewaddress
#** Encrypted wallet **
bitcoin-cli -testnet encryptwallet "123456"
#** Unlock wallet **  The last parameter is the unlocking time 
bitcoin-cli -testnet walletpassphrase "123456" 600
#** Query the private key of the address **
bitcoin-cli -testnet dumpprivkey 2MvSvdJBGSZVfdMGYXFpnDofv3ADQBeXPq4
#** Import the corresponding address into the wallet **
bitcoin-cli -testnet importaddress mfcwZvnSE44MuHoNPZcrwvaGSsGnTerKa2
#** Import the private key of the corresponding address into the wallet **
bitcoin-cli -testnet importprivkey cVYGW6TbAVDpP183yPJkGPwAYgoNugnq6ueywcNAY2uRGdyi4X38
# Export wallet 
bitcoin-cli -testnet backupwallet mywallet
# Import wallet 
bitcoin-cli -testnet importwallet  mywallet

(3) Private chain

Background operation

bitcoind -regtest -daemon -deprecatedrpc=accounts  -datadir=/root/blockchain/btc
bitcoind -regtest -daemon -deprecatedrpc=accounts  -datadir=/root/blockchain/btc -rpcuser=admin1 -rpcpassword=123 -rpcallowip=0.0.0.0/0

# Set up rpc port   account number   Code words , Use bitcoin-cli You have to set it accordingly  -rpcport=19001
bitcoin-cli -regtest -rpcuser=admin1 -rpcpassword=123 -getinfo
bitcoin-cli -regtest -rpcuser=admin1 -rpcpassword=123 -datadir=/root/blockchain/btc getnewaddress "platform"
bitcoin-cli -regtest -rpcuser=admin1 -rpcpassword=123 stop

# If a path is specified , Use bitcoin-cli You may not specify rcp Password etc. 
bitcoin-cli -datadir=/root/blockchain/btc -getinfo
bitcoin-cli -datadir=/root/blockchain/btc getnewaddress "platform"
bitcoin-cli -datadir=/root/blockchain/btc stop

# Stop running 
bitcoin-cli -regtest stop

(4) adopt curl Direct tune rpc Interface (RESTAPI)

curl --user admin1 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getaddressesbyaccount", "params": ["tabby"] }' -H 'content-type: text/plain;' http://192.168.131.135:18444/

(5) Use make command

cd blockchain/btc/regtest/
# Put a... In the directory Makefile file , It's configured right make Command response ,  Then you can 
make start
make getinfo
make cli command=getbalance			//command= You can enter commands later 
make stop

# Pay attention to the change of account balance , It has nothing to do with the actual coins on the network 
# When you use sendfrom When remitting money , The specified account is deducted . But the actual chain transaction created always uses any coin controlled by the wallet . Explain again : Coins on the chain ( Transaction output ) There is no relationship with the account balance 

State correlation

# Network Overview ( Including network type   Block height )
make cli command=getblockchaininfo
# Wallet status 
make cli command=getwalletinfo
# View the network status of the current node 
make cli command=getnetworkinfo
# essential information 
make getinfo

Block related

# Generate blocks 
make cli command="generate 10"

# Check the... Corresponding to the block number hash
make cli command="getblockhash 0"
# Check block information 
make cli command="getblock [blockhash]"
# Check the block details 
make cli command="getblock [blockhash] 2"

Account address

# Generate wallet address   Default account 
make cli command=getnewaddress
# Generate wallet address   Designated account 
make cli command="getnewaddress platform"

# List all addresses under the default account  
make cli command="getaddressesbyaccount ''"
# List all addresses under the specified account  
make cli command="getaddressesbyaccount platform"
make cli command="getaddressesbyaccount user"

#*** Query information about an address , It can be used to verify whether an address is valid  ***
make cli command="validateaddress 2NAvfLb7p4BmLAUKiVGTyfCFAAFJ2h88CNg"
make cli command="validateaddress 2NEVRE7j9ZzLmFZREnf3d9QvTq9Y8hP9UqM"
# Returns the account associated with the specified address 
make cli command="getaccount 2NAvfLb7p4BmLAUKiVGTyfCFAAFJ2h88CNg"
# Associate the address to the specified account 
make cli command="setaccount 2NAvfLb7p4BmLAUKiVGTyfCFAAFJ2h88CNg user"

# Returns the current currency collection address of the specified account 
make cli command="getaccountaddress 'platform'"
# Returns at least... Received on the specified account [minconf] Total amount of confirmed collection transactions ( Excluding payment )
make cli command="getreceivedbyaccount 'user' 1"
# Returns at least... Received at the specified address [minconf] Total amount of confirmed collection transactions 
make cli command="getreceivedbyaddress '2NAvfLb7p4BmLAUKiVGTyfCFAAFJ2h88CNg' 1"

The account balance

# The total balance of the wallet 
make cli command="getbalance"
# The total balance of the specified account in the wallet 
make cli command="getbalance platform"
make cli command="getbalance user"

# Return all address information on the wallet ( Address , balance , Account to which it belongs )
make cli command=listaddressgroupings
# List the collection information of the account 
make cli command=listreceivedbyaccount
#** List the collection information of the address **
make cli command=listreceivedbyaddress

#** List accounts and balances **
make cli command=listaccounts
# List all transaction outputs not spent 
make cli command=listunspent
# List at least  X  Output of confirmed unspent transactions , And specify the address filter .
make cli command="listunspent 0 9999999 '[\"2NAvfLb7p4BmLAUKiVGTyfCFAAFJ2h88CNg\"]'"

Transaction related

# Transaction information view ( Transactions at wallet managed addresses )
make cli command=listtransactions
# View single transaction information 
make cli command="gettransaction [txid]"
make cli command="gettransaction 8d44aa1523d1b44519fbfff3f4f0b9373877ad4151d4588673b35518e90a0547"
# View single raw data 
make cli command="getrawtransaction [txid]"
# Decode the original data of the transaction 
make cli command="decoderawtransaction [hex]"

# Transfer accounts  ( The unit is btc)
make cli command="sendtoaddress [ADDRESS] [AMOUNT]"
make cli command="sendtoaddress 2NEVRE7j9ZzLmFZREnf3d9QvTq9Y8hP9UqM 1000"
make cli command="sendtoaddress 2N1XpzLA1ZtUpy5WRfiRJRnhgTJXFmejPCs 1000"

# From the designated account <fromaccount> To the specified address <tobitcoinaddress>  Send the specified amount <amount> Of BTC, Make sure the account has access to [minconf] A confirmed effective balance 
make cli command="sendfrom <fromaccount> <tobitcoinaddress> <amount> [minconf=1] [comment] [comment-to] "
make cli command="sendfrom platform 2NAvfLb7p4BmLAUKiVGTyfCFAAFJ2h88CNg 5"

# Estimated transaction fee 
make cli command="estimatesmartfee 6"

# Transfer between accounts in wallet 
make cli command="move <fromaccount> <toaccount> <amount> [minconf=1] [comment]"
make cli command="move user platform 10"
 #move  Transfer accounts  ****  Account  <fromaccount> <toaccount> <amount> [minconf=1] [comment]  Put an account in your wallet <fromaccount> The specified amount on <amount>  Transfer to another account <toaccount> On . Move from one account in your wallet to another N

Wallet related

make cli command="encryptwallet 123456"
#** Unlock wallet **  The last parameter is the unlocking time 
make cli command="walletpassphrase 123456 600000"
#** Lock Wallet **
make cli command="walletlock"
#** Change wallet password   primary   new **
make cli command="walletpassphrasechange 123456 123123"
#** Refill the key pool **
make cli command="keypoolrefill"

#** Query the private key of the address **
make cli command="dumpprivkey 2NEVRE7j9ZzLmFZREnf3d9QvTq9Y8hP9UqM"
#** Import address to wallet default account **
make cli command="importaddress mfcwZvnSE44MuHoNPZcrwvaGSsGnTerKa2"
#** Import the address to the wallet specified account **  Do not rescan blocks   For newly generated addresses 
make cli command="importaddress 2NEVRE7j9ZzLmFZREnf3d9QvTq9Y8hP9UqM platform false"		
#** Import the address to the wallet specified account **  Rescan blocks   For addresses with balances 
make cli command="importaddress 2NEVRE7j9ZzLmFZREnf3d9QvTq9Y8hP9UqM platform true"		
#****** Import the private key without balance into the wallet *******
make cli command="importprivkey cSKLMu6HVX9TyJPgqJSCu4SWe7aLcpdmYgo76cgQgAV4NwfkgFJq '' false"
#****** Import the private key with balance into the wallet *******
make cli command="importprivkey cSKLMu6HVX9TyJPgqJSCu4SWe7aLcpdmYgo76cgQgAV4NwfkgFJq platform true"
# Export wallet 
make cli command="backupwallet mywallet"
# Import wallet 
make cli command="importwallet mywallet"

mining switch (setgenerate The order appears to have been deprecated )

#setgenerate  Set whether to mine  ****  mining  <generate> [genproclimit]  according to <generate> The value of the parameter (true/false) Determines whether the client is running .[genproclimit] Parameter specifies the maximum number of threads ,-1 Represent unlimited . <generate> is true or false to turn generation on or off.Generation is limited to [genproclimit] processors, -1 is unlimited. N

# open 
make cli command="setgenerate true 1"
# Turn off 
make cli command="setgenerate false"

close bitcoin

make -C  /data/blockchain/btc/fast  stop

Past highlights :
Blockchain Knowledge Series
Cryptography series
Zero knowledge proof series
Consensus series
Public chain research series
Bitcoin series
Ethereum series
EOS series
Filecoin series
Alliance chain series
Fabric series
Smart contract series
Token series

copyright notice
author[Brick moving leader],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202030527467347.html

Random recommended