Author: Chen Jinjian
blog address: HTTPS: //jian1098.github.io
CSDN blog: https: //blog.csdn.net/c_jian
Contact: [email protected]
Install bitcoind
https://bitcoincore.org/bin
Find the appropriate version on the official website , it must be a version below 0.18.0, otherwise the node will not be connected, the configuration of the new version needs to be studied
root@ubuntu:~# wget https://bitcoincore.org/bin/bitcoin-core-0.17.1/bitcoin-0.17.1-x86_64-linux-gnu.tar.gz
root@ubuntu:~# tar zxf bitcoin-0.17.1-x86_64-linux-gnu.tar.gz
Create soft connection
root@ubuntu:~# cd bitcoin-0.17.1
root@ubuntu:~# ln -fs /root/bitcoin-0.17.1/bin/bitcoind /usr/local/bin/bitcoind
root@ubuntu:~# ln -fs /root/bitcoin-0.17.1/bin/bitcoin-cli /usr/local/bin/bitcoin-cli
Check the version number
root@ubuntu:~# bitcoind --version
Configure bitcoin parameters
root@ubuntu:~$ mkdir .bitcoin #创建目录
root@ubuntu:~$ cd .bitcoin/
root@ubuntu:~$ vi bitcoin.conf
Copy all the following information, and modify rpcuser (RPC user name), rpcpassword (RPC user password), rpcallowip (ip address allowed to access) and save
# Generated by https://jlopp.github.io/bitcoin-core-config-generator/
# This config should be placed in following path:
# ~/.bitcoin/bitcoin.conf
# [rpc]
# Accept command line and JSON-RPC commands.
server=1
txindex=1
# Username for JSON-RPC connections
rpcuser=bitcoinrpc
# Password for JSON-RPC connections
rpcpassword=bitcoinrpc
# Listen for JSON-RPC connections on this port
rpcport=18332
# Allow JSON-RPC connections from specified source. Valid for <ip> are a single IP (e.g. 1.2.3.4),
# a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option
# can be specified multiple times.
rpcallowip=192.168.1.178
rpcallowip=192.168.1.179
# 设定默认为私有链
regtest=1
Start bitcoin program
root@ubuntu:~/.bitcoin$ bitcoind -daemon
Bitcoin server starting
-deamon
Means running in the background
Stop bitcoin program
root@ubuntu:~/.bitcoin/testnet3$ bitcoin-cli stop
Bitcoin server stopping
Access Json-RPC interface
In the main network ( mainnet
) and test network ( testnet
) modes, the json-rpc
port is used to access .bitcoin/bitcoin.conf
the 18332
port configured in use , but in the private chain ( regtest
) mode, it seems that the configuration does not work. It is still necessary to access the default 18443
port.
We can use postman
or curl
other tools to access: bitcoinrpc: bitcoinrpc is the rpc username and password respectively
curl -s -X POST --user bitcoinrpc:bitcoinrpc -H 'content-type: text/plain;' http://127.0.0.1:18443/ --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getnetworkinfo", "params": [] }'
More RPC
methods can refer to https://www.blockchain.com/es/api/json_rpc_api
andhttps://bitcoin-rpc.github.io/en/doc/0.17.99/rpc/
Bitcoin-cli commonly used commands
View wallet information
This command can get information such as wallet version, balance, number of transactions, etc.
bitcoin-cli getwalletinfo
Get all wallet addresses and their account names
bitcoin-cli listreceivedbyaddress 1 true
Check balances
bitcoin-cli getbalance
Note: The balance obtained by the query is the sum of the available balances of all wallet addresses, and does not include the balance of wallet addresses whose private keys are not in the node.
Generate wallet address
bitcoin-cli getnewaddress "test" #"test"是输入的账号
Query the number of coins received by the address
bitcoin-cli getreceivedbyaddress 2MtmeZ7W17zJzigtRhzKMP6MSc2DSyL5LYU
Command list
bitcoin-cli help