CentOS stream 9: bitcoin-core の regtestで送金を行う その1

1. aliceとbobのworking ディレクトリを作成
– user02でlogin
– /home/user02
     |- dev
       |- alice
       |- bob

$ pwd
/home/user02
$ cd ~
$ mkdir dev
$ cd dev
$ mkdir alice bob

$ cd alice
$ vim bitcoin.conf

$ cd ../bob
$ vim bitcoin.conf

2. bitcoin.confの内容

bitcoin.conf
regtest=1
txindex=1
server=1
rpcuser=admin
rpcpassword=keyboardcat

3. aliceのノードを起動

$ bitcoin-core.daemon -regtest -conf=/home/user02/dev/alice/bitcoin.conf -datadir=./alice/ -rpcport=10001 -port=10011

4. bobのノードを起動し、aliceのノードに接続

$ bitcoin-core.daemon -regtest -conf=/home/user02/dev/bob/bitcoin.conf -datadir=./bob -rpcport=10002 -listen=0 -connect=127.0.0.1:10011

5. processの状態

$ ps -aux|grep bitcoin
user02      6775  0.2  0.3 1195600 59660 pts/7   SLl+ 10:32   0:04 /snap/bitcoi -core/120/bin/bitcoind -regtest -conf=/home/user02/dev/alice/bitcoin.conf -datadir=./alice/ -rpcport=10001 -port=10011
user02      6819  0.1  0.3 1041788 54340 pts/1   SLl+ 10:36   0:03 /snap/bitcoi -core/120/bin/bitcoind -regtest -conf=/home/user02/dev/bob/bitcoin.conf -datadir=./bob -rpcport=10002 -listen=0 -connect=127.0.0.1:10011
user02      7301  0.0  0.0   6408  2124 pts/0    S+   11:07   0:00 grep --color=auto bitcoin

6. aliceのWalletのadressを取得
– Fail

$ bitcoin-core.cli -regtest -conf=/home/user02/dev/alice/bitcoin.conf -datadir=. -rpcport=10001 getnewaddress
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)

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

$ bitcoin-core.cli -regtest  -datadir=. -rpcport=10001 createwallet "AliceWallet"
{
  "name": "AliceWallet",
  "warning": ""
}
$

8. walletが作成された場所

$ cd /home/user02/dev/alice/regtest/wallets
$ ls
AliceWallet
$ cd AliceWallet/
$ ls -l
total 52
-rw------- 1 user02 user02 24576 Aug 10 10:57 wallet.dat
-rw------- 1 user02 user02 25136 Aug 10 10:57 wallet.dat-journal

9.再度、aliceのWalletのaddressを取得

$ cd /home/user02/dev/alice
$ bitcoin-core.cli -regtest -conf=/home/user02/dev/alice/bitcoin.conf -datadir=. -rpcport=10001 getnewaddress
bcrt1qht58vxn8avnek2ya3wfpyv65qml9q7l5a6lpek
$

10. マイニングの実行

$ bitcoin-core.cli -regtest -conf=/home/user02/dev/alice/bitcoin.conf -datadir=. -rpcport=10001  generatetoaddress 101 bcrt1qht58vxn8avnek2ya3wfpyv65qml9q7l5a6lpek
[
  "03dc5e5356095692bc1d25a9e26d6ad5dbbb801a5b906446ba8951e5c4bd8b89",
  "516fde5437d5d1b01db98fc0362b3d87f8d4cece4f45886aff2301a3ab8df5de",
  "38fd6d05c33282255b887e8773ee9a08462e25c8f7d6a57435795988296dd0ac",
  "226f476028dcd627795416683b3737f5c7c029e85db52ca8996c1a9e24794f32",
  "7b1c89205d94452ba11a9f3854b240c545d19392f03006e1a985ba4b50b41399",
  "7cd10e01e6ef6b55f4359ae8bd558bc1a389db82e02f17e6465b5459d49ea9e7",
  "4e995e4c98b10f53acd1ebe07f9813b816209d460cdf1d61a40ff18767a9c483",
  "24d2ab44078e51069f088538044e12df99b4bbfffee1cdcad59d8e89f2f5c5d9",
  "4812ca9c40d527f7b6aea226ec7e5c1ec00e4aa147955ca0f84dcb7e03b48c57",
  "190526bea0cf77a4e79317ca72bd5891a72115f297d2df3cbecd17b6de622245",
  "2388ba41ae63862dce797458f43a73003c96126387cad65e6f0928d6d9ccc1d8",
  "54cae5f07f5c9ac5fd44f221226e4fac47de75276568add242b19738df19af18",
  "1f458d2d9745ff3dfe8a6ee4d63045f0485074a7c104cf53e284a5eb17e036a4",
  "7e0aabd314bbd8d1337e1f65076901cc13b8358e173578e62cde59b78e47407f",
  "23a33dc23cc893038c095c2263d6f49a3871101a536f97dd53142f8d80ee9bdb",
  "6c5a7679c345fe696947eb245032ecafddb5669f5d6cbd053c8a854d54ebe6e8",
  "740da119480759192851d7410328551db002fd0323073eeb64e026eb697cc190",
  "134e0ff3bc3ce055487fb7043b8f5dd9bc9e275faa786d93700709a62a27c254",
  "7096e77e2979b8e72ae155a4038f750df1d1a3e4e6988a5889da27e64134f87e",
  "5bc03de223ee15d343860fe210d1f9b8c510a5f668426179c7b77d9c59995184",
  "0d1fb82f8bca2a149c3f531da5c9dcfc6d1d9078e4b34037c6c4f705de11e048",
  "452478d42d08423bb499867711d755b48c4e84ffcbba0796ded6d050e5d4f2fb",
  "7e8aa1d5d35ba5e64bb67a6e581c14ae33af8fcc0e6db7d3d19a25b0d2e5bfbc",
  "6e08c7021d5a1da8e6a9db2cc1238ea9b357ba9babdc64c76c6ad94c3b3fb1d7",
  "5ade9f913304a26c52a5dbf4052bf713a20a8738b408d5fad1485753a059f23f",
  "0fa300ee8824757c15c036430e967bab450f979c562751be28bb5f210bf28fb7",
  "5923cb64962a8443c1781a07e9f0f71b3cf3680e8342fbf69db60e7248ae4ade",
  "7cae388f2953180134961ab4e0802c773eec08c8e15caa952a52efeaa9db7465",
  "421db6d0782d5b5eecc0c644182c2e53dc1c5bd557af1ae8189d054f023f9a6e",
  "0ccc8e5801f3b45d4b6182d217873b84ea19189fd700346999257bf34832d81e",
  "0921b917f67661243c3feb75760be0490bfbd6ec595d69245ad521b553a7b34e",
  "49f088d67331aec0b476c78e0cb0c9a10dd37f67a85f8a6989e351e030d23c4b",
  "7c04fa1ea74b7680b0e11ffa10de2ac9b7f6501be86ed22d35b1113b14e8069d",
  "50be8b19b97b1cce3b8b3ea4cef5f58e0f3d81759b7e5131ca2da82130464649",
  "7ae1d63da68c55563088adeb2d7a55a2df6d178c9fcead67f3bfdecec736aff3",
  "3bf08a7598d494667aba6d942d8ab32fe60ad8e5387c6b96a4175db719f42919",
  "461a3c09f1c66ee77979ad8d63336e4a02be7ff84966e5dd2278b2c1246afdc9",
  "151008925e1b6506fe45bfe8525f9876a1a07828f687c201f173abaf7bd030c0",
  "24bea5bda78a199aac2631d07e8f3ee566a7f49cc21659c74dac04c33cb2a9ab",
  "05c5f7318139af477325a1b3c646ee44e778cf855b8dd3aadd326da98e8cfd3e",
  "0757b631d429c403e7492ab00a93de6b4ec39a9f2b39d1a75b4b810210c6bf35",
  "59d278c9788b26636141f7ffd79245d7ab3a9594ffb1174e143305fbc313204f",
  "4dac4084deb9f998193b2b0af98552bb5e5839c3afd5962d1ff29c1e2ee07a61",
  "625166626af8237bf4566b4f0ea7005c221b993fc790cb15b037557f1c3612d7",
  "6f79afbe43d007611c3f872723771726a9b5bdf3019bf5ca38c736966efad753",
  "555cf21ba6235f057dc9a6c6a3c429d60db951062c2907f9d48db2f8de156907",
  "1d9bc08fbd25832f1cd664bfaa16f7e3918fbcea071097cf05630d37ae3b86c1",
  "3577080916290c850b3a6bc8769c537995d718e976a8787e198f535459e7f23f",
  "144b19f1b84caf7aded3a14ef9e534ac8938dd7cfccff50372a7b2cda41335c2",
  "520bdf25f779689cc845e8e59db89a212faf380411440bb2dc08349a6f4792a6",
  "55d90c0972cd9cce1b01a1cecde430a04d9d23cc3309d60edd480b507df536f1",
  "308d48afa87901eaad960e34dc7e2a50edebb4148a1ce3667e5437d241622749",
  "6a0210a89ad29127a65ac700dac9159337cbc0a0ac2f589b47e5e22e8b817384",
  "4e28dd0664ce6b2dd2c68fd62788980dea4e84b555237f833541ea8e2ee4c5a2",
  "3a848aa5de1be8583b3608484e662fdb1f24ac1036da063730b0cc6f83577818",
  "304e344315845e23def6fb50baf5bb07e42df1d47a5c20293297e70448723b9a",
  "39821f29324fc0a03ff4742c5fe9bff2b02ce4cba29c428cdcb988ed4b52d1f9",
  "0a8380185dcadfddb7cb7afad7218d0323c8eb799679b2b5b0a1ac45090e8eda",
  "014ba3dd1a7ce56a02dcf12d78683a562429fa2c96e90d4f195f6834798a9001",
  "6e40e04b445ed28c8b7a807fc325b6b0d82051f076e5e8064a2da1460b35f712",
  "557ee8ae3546095ddc25ab9149394f92ab39e68b8decefb2580fd1df2b60b448",
  "6bed60e3dfc65f5b3ca75e3f29f70db32330c88e0073f99dd5f27f81b5eabd0c",
  "76c344613ace318ff6b3be6d52c5ae8c31cce97b3536b1dc5fc762d2e95b02c2",
  "5acab928e656d0c5ec8f9bd2cc494fdbc7cb974459cb6fc8b6770f41181f02e8",
  "6386c99624a3db4292967721ce31db8b7010eaae4f62ec4bd253130296e4bba6",
  "233d2b3985e67a141eb69609b2bca0e21403fed85e950ac48cc4d3616c102756",
  "7aa63e87e6b9b700c871d4decab1b615f3059a89e76191633e3e5c9e6a029d1a",
  "6810ed535661b90f5f6d4b32a07e0c010560411d9bbafade91ae20e14c46d631",
  "4ef303720f3683bcab84c979c1cf07aafe8651afcc7185332c84da788facdc7f",
  "4a654e69c66e4ddb4dbc17d1b74d5a4d48ecfdb94a0659b301a1a3bddc275c8e",
  "41efefcbeb1f5390a09abdf431b6d09ae1ac18bd2a22f595d7bf0edb193f6857",
  "17464f7f4d580c97e34f27c899db8eeca25055799a2fd2e048db68f61afb18ec",
  "2e2fcf1ff91d5d627a4bfe787b2d2a8486569a6916d2742ac6d61a454f83a3d8",
  "00b1fe9cd1837f6ffbe57808f3f1bacdcb7386dd2179593a9312857d2e90ee10",
  "368a28bf57ffe7b4c01ebd43be277bd815882111466dd76088336cd264493ca2",
  "26ad7ad4b97ea88280209dda56a73831595d4ff75eea70405fbcb14f457fae8d",
  "71af73c082075de471ec6763c3ac73108b0a913284b7cf80942b11b6e2f20e03",
  "7ea143bc777c05b93cd84a4be9035b31032d093a09984dc6bdf0d2ffd22e75de",
  "62cc81dfebd8f42e0ec38b5125461f516d6dd1f3008426b069f2162d4be45846",
  "55b7d2a344d3512764e552f26d124d44523d693d3877048f6d645bd1e51bede0",
  "711599b43349c470b8b44028900dfc959bfdd8635dac354eeb3468befaf7c50b",
  "1affefa97ccac1c66b7836397ea5fffdeccce8cb19a0a47ae668a8398ad6bddb",
  "08d0bd997c3c91535219e9cf855c8f1f9a06c80d0ac8be783c22a15b50458f1e",
  "554fca51ebe40ebe9aa7e8e05694986fcf2ad252c724f1f59905b42b6af04420",
  "27b0ec83d1d42f83d3a4867d70eeff7ab671661ebb98bcb26e365fbd5b34456d",
  "20cd2c13421b4bc9d056aebb513e89e15a0e68057fd77b637b6a12ad6f81a0ac",
  "30bf27c1ec1f28762ae5ad9b730466595c4601994d341f34d2bbdeb9f63ae53c",
  "03ab82f5f0b0d904361eedff4d102589bff15dea6367ca3cbf631ce7da435d9b",
  "70562b5a9d0cb7468ea2b10f599c6df1a08b729236c339e90b4f7e40c9640a88",
  "10c442ade21ebbb3bdf082c5df998118116d62aa3f666cef89439b25080c6490",
  "53499753701b5ca95bfd90ef3eac429760109a0b49e60cf78eca171a59002d7c",
  "4551db0d45786fe77bf85937259148e6257e2c7c078c9f16a4ca45dcb339ab86",
  "19d139aab34d3fa6364a9460422bc4e6efee0ff8bb9d26f3dab87b2f11fe8672",
  "5dbb9139efe56f928553cd491abdf7f98b2bbf14328a110df5fb028acac1a022",
  "699137d945a60e5168786b2fce76ebd71e06c1ae0050b5027f895d24bf9fb010",
  "7515451c6d2ef91969249c52718a27852790249b49cd3ca823e7714964959010",
  "1d6ea119290407e915795918d538ef6c2e694fa8a0167598e1d8becc4b0ff96a",
  "7c248f9f538d561bc7c37d82fbf800463590af7f4d6560a5bd4b121460250809",
  "43a31805788c5c6888b71c4d33c662749c6a956f4eae3a2e35a40f972263c2f1",
  "36bc300d0519d675e36615b1eeb9ed098e1bd554801fae71a8bd3221b23d6df7",
  "18101ee3aecb6165eacb9b53bbd631731b954038fc84b46b70312f263a4bc4fa"
]
$

11. Aliceのwalletの balance 確認
– Aliceのwalletに 50BTC 入っている

$ bitcoin-core.cli -regtest -conf=/home/user02/dev/alice/bitcoin.conf -datadir=. -rpcport=10001 getbalance
50.00000000
$

12. 新しいterminalでlogin

$ cd dev/bob
$ pwd
/home/user02/dev/bob

13. Bob の Wallet作成
– BobWallet

$ bitcoin-core.cli -regtest  -datadir=. -rpcport=10002 createwallet "BobWallet"
{
  "name": "BobWallet",
  "warning": ""
}
$

14. bobのWalletのadress確認

$ bitcoin-core.cli -regtest -conf=/home/user02/dev/bob/bitcoin.conf -datadir=. -rpcport=10002 getnewaddress
bcrt1qjyzl9tp964jqakvrmgm7n25fmdw4j950mvxr9p
$

14. bobのWalletの balance 確認

$ bitcoin-core.cli -regtest -conf=/home/user02/dev/bob/bitcoin.conf -datadir=. -rpcport=10002 getbalance
0.00000000
$

15. Alice UTXOのリストを取得

$ bitcoin-core.cli -regtest -datadir=. -rpcport=10001 listunspent
[
  {
    "txid": "9923631305a0658df2c886b232fa9f051901c463cab7b5bd9c06ec72c5e2fbff",
    "vout": 0,
    "address": "bcrt1qht58vxn8avnek2ya3wfpyv65qml9q7l5a6lpek",
    "label": "",
    "scriptPubKey": "0014bae8761a67eb279b289d8b9212335406fe507bf4",
    "amount": 12.50000000,
    "confirmations": 1581,
    "spendable": true,
    "solvable": true,
    "desc": "wpkh([3e93b7c0/84'/1'/0'/0/0]02a36ec1e6e326f4040ad5e86a4ba114d7d59b369e9fae5925bfb55bd1f53d7289)#uw8n8sq7",
    "safe": true
  },
]