Try   HackMD

Bitcoin.conf 設定

tags: bitcoin

安裝

sudo add-apt-repository ppa:bitcoin/bitcoin sudo apt update -y sudo apt install bitcoind

設定 config

需要在自行建立 bitcoin.conf檔案

​/home/ubuntu/.bitcoin/bitcoin.conf

啟動:

  • 監聽主鏈
bitcoind
  • 監聽測試鏈
bitcoind -testnet

關閉:

  • 主鏈
bitcoin-cli -rpcuser=user -rpcpassword=password -rpcconnect=192.168.1.2 -rpcport=8333 stop
  • 測試鏈
bitcoin-cli -rpcuser=user -rpcpassword=password -rpcconnect=192.168.1.2 -rpcport=18333 stop

完整設定

# run background mode daemon=1 # open rpc service server=1 # rpc testnet service [test] rpcport=18333 // your host private ip: 192.168.1.2 rpcbind=192.168.1.2 rpcallowip=0.0.0.0/0 rpcuser=user rpcpassword=password # rpc main service [main] rpcport=8333 // your host private ip: 192.168.1.2 rpcbind=192.168.1.2 rpcallowip=0.0.0.0/0 rpcuser=user rpcpassword=password # start bitcoin with main chain command: bitcoind # start bitcoin with test chain command: bitcoind -testnet # stop command: bitcoin-cli -rpcuser=user -rpcpassword=password -rpcconnect=192.168.1.2 stop

測試指令

  • 檢查監聽狀態
netstat -alpn | grep bitcoind
  • curl 測試 rpc 連線
curl -X POST -H "Content-Type: text/plain" <host public ip>:8333 -u user:password --data '{"method": "getblockhash","params": [0],"id": "foo"}'