BCH gitlab
BCH github
1、下载BCH二进制文件
root@iZj6c076dm0c5n5b39lzlxZ:/data/docker-compose/bch# wget https://github.com/bitcoin-cash-node/bitcoin-cash-node/releases/download/v26.1.0/bitcoin-cash-node-26.1.0-x86_64-linux-gnu.tar.gz
--2023-07-05 16:30:46-- https://github.com/bitcoin-cash-node/bitcoin-cash-node/releases/download/v26.1.0/bitcoin-cash-node-26.1.0-x86_64-linux-gnu.tar.gz
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.111.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 31056067 (30M) [application/octet-stream]
Saving to: ‘bitcoin-cash-node-26.1.0-x86_64-linux-gnu.tar.gz’
bitcoin-cash-node-26.1.0-x86_64-linux-gnu.tar.gz 100%[=========================================================================================================================================>] 29.62M 20.1MB/s in 1.5s
2023-07-05 16:30:49 (20.1 MB/s) - ‘bitcoin-cash-node-26.1.0-x86_64-linux-gnu.tar.gz’ saved [31056067/31056067]
2、编写Dockerfile
root@iZj6c076dm0c5n5b39lzlxZ:/data/docker-compose/bch# vim Dockerfile
root@iZj6c076dm0c5n5b39lzlxZ:/data/docker-compose/bch# cat Dockerfile
M ubuntu:20.04
# 安装依赖库和工具
RUN apt-get update && apt-get install -y \
curl \
libssl-dev \
libevent-dev \
software-properties-common
ADD bitcoin-cash-node-26.1.0-x86_64-linux-gnu.tar.gz .
# 解压并复制二进制文件到 /usr/local/bin 目录
RUN mv bitcoin-cash-node-26.1.0/bin/bitcoind /usr/local/bin/ && \
mv bitcoin-cash-node-26.1.0/bin/bitcoin-cli /usr/local/bin/ && \
rm -rf bitcoin-cash-node-26.1.0
# 配置 Bitcoin Cash 节点
COPY bitcoin.conf /root/.bitcoin/bitcoin.conf
# 暴露节点端口
EXPOSE 8332 8333
# 启动 Bitcoin Cash 节点
CMD ["/usr/local/bin/bitcoind"]
3、编写bitcoin配置文件
root@iZj6c076dm0c5n5b39lzlxZ:/data/docker-compose/bch# vim bitcoin.conf
server=1
txindex=1
listen=1
rpcbind=0.0.0.0:8332
rpcallowip=0.0.0.0/0
rpcport=8332
rpcuser=bch
rpcpassword=asfefsdfwefdsafedsdfwe
uacomment=bitcore-bch
datadir=/bitcoin/data
#timestampindex=1
4、编写docker-compose.yml文件
root@iZj6c076dm0c5n5b39lzlxZ:/data/docker-compose/bch# vim docker-compose.yml
root@iZj6c076dm0c5n5b39lzlxZ:/data/docker-compose/bch# cat docker-compose.yml
version: '3'
services:
bch-node:
image: bch/bitcoin-cash-node:v26.1.0
volumes:
- ./bitcoin.conf:/root/.bitcoin/bitcoin.conf
- ./data:/bitcoin/data
ports:
- 8332:8332
- 8333:8333
5、打镜像
root@iZj6c076dm0c5n5b39lzlxZ:/data/docker-compose/bch# docker build . -t bch/bitcoin-cash-node:v26.1.0
[+] Building 54.0s (10/10) FINISHED
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 670B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:20.04 2.5s
=> [internal] load build context 0.1s
=> => transferring context: 31.06MB 0.1s
=> [1/5] FROM docker.io/library/ubuntu:20.04@sha256:c9820a44b950956a790c354700c1166a7ec648bc0d215fa438d3a339812f1d01 2.0s
=> => resolve docker.io/library/ubuntu:20.04@sha256:c9820a44b950956a790c354700c1166a7ec648bc0d215fa438d3a339812f1d01 0.0s
=> => sha256:01085d60b3a624c06a7132ff0749efc6e6565d9f2531d7685ff559fb5d0f669f 27.51MB / 27.51MB 1.5s
=> => sha256:c9820a44b950956a790c354700c1166a7ec648bc0d215fa438d3a339812f1d01 1.13kB / 1.13kB 0.0s
=> => sha256:8c38f4ea0b178a98e4f9f831b29b7966d6654414c1dc008591c6ec77de3bf2c9 424B / 424B 0.0s
=> => sha256:14be0685b7682b182af5b862c9638cb1cb4ca1a70bd5aa90deed96e9cca881e7 2.30kB / 2.30kB 0.0s
=> => extracting sha256:01085d60b3a624c06a7132ff0749efc6e6565d9f2531d7685ff559fb5d0f669f 0.4s
=> [2/5] RUN apt-get update && apt-get install -y curl libssl-dev libevent-dev software-properties-common 47.6s
=> [3/5] ADD bitcoin-cash-node-26.1.0-x86_64-linux-gnu.tar.gz . 0.5s
=> [4/5] RUN mv bitcoin-cash-node-26.1.0/bin/bitcoind /usr/local/bin/ && mv bitcoin-cash-node-26.1.0/bin/bitcoin-cli /usr/local/bin/ && rm -rf bitcoin-cash-node-26.1.0 0.3s
=> [5/5] COPY bitcoin.conf /root/.bitcoin/bitcoin.conf 0.0s
=> exporting to image 1.0s
=> => exporting layers 1.0s
=> => writing image sha256:bb00a8466266b6e11326bc5b2241f1b7610f27cbbe0611c22105a966bf8f818f 0.0s
=> => naming to docker.io/bch/bitcoin-cash-node:v26.1.0
6、启动容器
root@iZj6c076dm0c5n5b39lzlxZ:/data/docker-compose/bch# mkdir bitcoin
root@iZj6c076dm0c5n5b39lzlxZ:/data/docker-compose/bch# chmod 777 bitcoin -R
root@iZj6c076dm0c5n5b39lzlxZ:/data/docker-compose/bch# mv bitcoin data
root@iZj6c076dm0c5n5b39lzlxZ:/data/docker-compose/bch# docker-compose up -d
Starting bch_bch-node_1 ... done
7、查看节点同步情况
root@iZj6c076dm0c5n5b39lzlxZ:/data/docker-compose/bch# docker exec -it bch_bch-node_1 /bin/bash
root@496cbc45ff5a:/# bitcoin-cli -conf=/root/.bitcoin/bitcoin.conf getblockchaininfo
{
"chain": "main",
"blocks": 220892,
"headers": 800413,
"bestblockhash": "00000000000001faa5f06c81b98ef9d008b5853243fa8449c1b4b1f2e6c76194",
"difficulty": 3275464.586565617,
"mediantime": 1360719428,
"verificationprogress": 0.03421628954813776,
"initialblockdownload": true,
"chainwork": "00000000000000000000000000000000000000000000002a375ba8ca11508bcd",
"size_on_disk": 6433940923,
"pruned": false,
"warnings": ""
}
区块浏览器上对比
区块浏览器地址
curl测试
获取区块高度
curl --user bch:asfefsdfwefdsafedsdfwe --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "ping", "params": [] }' -H 'content-type: text/plain;' http://localhost:8332
{"result":null,"error":null,"id":"curltest"}
获取最新区块信息
curl --user bch:asfefsdfwefdsafedsdfwe --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblock", "params": [] }' -H 'content-type: text/plain;' http://localhost:8332
{"result":null,"error":{"code":-1,"message":"getblock \"blockhash\" ( verbosity )\n\nIf verbosity is 0 or false, returns a string that is serialized, hex-encoded data for block 'hash'.\nIf verbosity is 1 or true, returns an Object with information about block <hash>.\nIf verbosity is 2, returns an Object with information about block <hash> and information about each transaction, including fee.\nIf verbosity is >=3, returns an Object with information about block <hash> and information about each transaction, including fee, and including prevout information for inputs (only for unpruned blocks in the current best chain).\n\nArguments:\n1. \"blockhash\" (string, required) The block hash\n2. verbosity (numeric, optional, default=1) 0 for hex-encoded data, 1 for a json object, and 2 for json object with transaction data, and 3 for JSON object with transaction data including prevout information for inputs\n\nResult (for verbosity = 0):\n\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n\nResult (for verbosity = 1):\n{\n \"hash\" : \"hash\", (string) The block hash (same as provided)\n \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n \"size\" : n, (numeric) The block size\n \"height\" : n, (numeric) The block height or index\n \"version\" : n, (numeric) The block version\n \"versionHex\" : \"00000000\", (string) The block version formatted in hexadecimal\n \"merkleroot\" : \"xxxx\", (string) The merkle root\n \"tx\" : [ (array of string) The transaction ids\n \"transactionid\" (string) The transaction id\n ,...\n ],\n \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n \"nonce\" : n, (numeric) The nonce\n \"bits\" : \"1d00ffff\", (string) The bits\n \"difficulty\" : x.xxx, (numeric) The difficulty\n \"chainwork\" : \"xxxx\", (string) Expected number of hashes required to produce the chain up to this block (in hex)\n \"nTx\" : n, (numeric) The number of transactions in the block.\n \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n \"nextblockhash\" : \"hash\" (string) The hash of the next block\n}\n\nResult (for verbosity = 2):\n{\n ..., Same output as verbosity = 1\n \"tx\" : [ (json array)\n { (json object)\n ..., The transactions in the format of the getrawtransaction RPC; different from verbosity = 1 \"tx\" result\n \"fee\" : n (numeric) The transaction fee in BCH, omitted if block undo data is not available\n },\n ...\n ],\n ... Same output as verbosity = 1\n}\n\nResult (for verbosity >= 3):\n{\n ..., Same output as verbosity = 2\n \"tx\" : [ (json array)\n { (json object)\n ..., Same output as verbosity = 2\n \"vin\" : [ (json array)\n { (json object)\n ..., Same output as verbosity = 2\n \"prevout\" : { (json object, optional) (Only if undo information is available)\n \"generated\" : true|false, (boolean) Coinbase or not\n \"height\" : n, (numeric) The height of the prevout\n \"value\" : n, (numeric) The value in BCH\n \"scriptPubKey\" : { (json object)\n \"asm\" : \"str\", (string) The asm\n \"hex\" : \"str\", (string) The hex\n \"type\" : \"str\", (string) The type (one of: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata)\n \"address\" : \"str\" (string, optional) The Bitcoin Cash address (only if well-defined address exists)\n },\n \"tokenData\" : { (json object, optional) CashToken data (only if the input contained a token)\n \"category\" : \"hex\", (string) Token id\n \"amount\" : \"xxx\", (string) Fungible amount (is a string to support >53-bit amounts)\n \"nft\" : { (json object, optional) NFT data (only if the token has an NFT)\n \"capability\" : \"xxx\", (string) One of \"none\", \"mutable\", \"minting\"\n \"commitment\" : \"hex\" (string) NFT commitment formatted as hexadecimal\n },\n }\n }\n },\n ...\n ]\n },\n ...\n ],\n ... Same output as verbosity = 2\n}\n\nExamples:\n> bitcoin-cli getblock \"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"\n> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"getblock\", \"params\": [\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n"},"id":"curltest"}