CentOS stream 9: install bitcoin-core, and operation

1. Enable snapd

# yum install epel-release
# yum install snapd
# systemctl enable --now snapd.socket
# ln -s /var/lib/snapd/snap /snap

2. log out and back in again

3. Install bitcoin-core
– Fail

# snap install bitcoin-core
error: too early for operation, device not yet seeded or device model not acknowledged

4. Wait a minute and try again
– Success

# snap install bitcoin-core
2022-08-10T05:52:26+09:00 INFO Waiting for automatic snapd restart...
Warning: /var/lib/snapd/snap/bin was not found in your $PATH. If you've not
         restarted your session since you installed snapd, try doing that.
         Please see https://forum.snapcraft.io/t/9469 for more details.

bitcoin-core 23.0 from Bitcoin Core installed
#

5. bitcoin-coreを動かすuser作成

# adduser user02
# passwd user02

6. testnetで設定ファイルを作成
– user02にlogin

$ mkdir -p ~/snap/bitcoin-core/common/.bitcoin
$ vi ~/snap/bitcoin-core/common/.bitcoin/bitcoin.conf
testnet=3
server=1
rpcuser=admin
rpcpassword=keyboardcat

[test]
rpcbind=localhost
rpcport=18332

7. start testnet

$ bitcoin-core.daemon -datadir=/home/user02/bitcoin -testnet -daemon
Bitcoin Core starting
$

8. 状態確認

$ ps -aux |grep bitcoin
user02      2730  1.1  0.4 1189460 75788 ?       Ssl  07:35   0:00 /snap/bitcoin-core/120/bin/bitcoind -datadir=/home/user02/bitcoin -testnet -daemon
user02      2753  0.0  0.0   6408  2148 pts/0    S+   07:37   0:00 grep --color=auto bitcoin
$

9.チェーンの同期状況を確認

$ bitcoin-core.cli -datadir=bitcoin -testnet getblockchaininfo
{
  "chain": "test",
  "blocks": 444448,
  "headers": 2315627,
  "bestblockhash": "00000000000010109da5b215920d4dbeb555aefc0c3ff339cd1e951e1538debd",
  "difficulty": 65536,
  "time": 1432620535,
  "mediantime": 1432620008,
  "verificationprogress": 0.05948045755250513,
  "initialblockdownload": true,
  "chainwork": "0000000000000000000000000000000000000000000000041374c7c233fc2834",
  "size_on_disk": 1944705441,
  "pruned": false,
  "warnings": ""
}
$

10. Bitcoin Core v0.21 以降にはデフォルトのWalletが付属していない。このためWalletを作成する必要がある。
– user02Addr
– Fail

$ bitcoin-core.cli -datadir=bitcoin -testnet getnewaddress user02Addr
error code: -18
error message:
No wallet is loaded. Load a wallet using loadwallet or create a new one with createwallet. (Note: A default wallet is no longer automatically created)
$ bitcoin-core.cli -datadir=bitcoin -testnet  createwallet "user02Addr"
{
  "name": "user02Addr",
  "warning": ""
}
$

11. Create wallet
– user02Addr
– Success

$ bitcoin-core.cli -datadir=bitcoin -testnet getnewaddress user02Addr
tb1qs7fzs09d7k0w2ms3mtfwj4x9m0gnmn96qrljgw
$

12. stop testnet

$  bitcoin-core.cli -datadir=/home/user02/bitcoin -testnet stop
Bitcoin Core stopping
$

13. 再度testnet 再起動と、同期の状況を確認

$ bitcoin-core.daemon -datadir=/home/user02/bitcoin -testnet -daemon
Bitcoin Core starting
$  bitcoin-core.cli -datadir=bitcoin -testnet getblockchaininfo
{
  "chain": "test",
  "blocks": 1135549,
  "headers": 2315633,
  "bestblockhash": "00000000004d4a5da7168c1b9769254ddad004ebd38fb43b793358f22f3060ea",
  "difficulty": 76.54421023816042,
  "time": 1497796063,
  "mediantime": 1497796062,
  "verificationprogress": 0.2224437185354564,
  "initialblockdownload": true,
  "chainwork": "000000000000000000000000000000000000000000000025f890fb165efce2a9",
  "size_on_disk": 11347961301,
  "pruned": false,
  "warnings": ""
}
$

14. laodwallet
– testnet 再起動の後は、laodwalletが必要

$ bitcoin-core.cli -datadir=bitcoin -testnet  loadwallet "user02Addr"
{
  "name": "user02Addr",
  "warning": ""
}

15. マイニングされない

$ bitcoin-core.cli -datadir=bitcoin -testnet getnewaddress user02Addr
tb1qp9ca02lgg0rcvdru6kwmyw7vkpad4393kd2dpj
$
$ bitcoin-core.cli -datadir=bitcoin -testnet generatetoaddress 101 tb1qp9ca02lgg0rcvdru6kwmyw7vkpad4393kd2dpj
[
]
$

16.testnetをregtestに替えてやり直し