Bitcoin Coreの基本操作

Bitcoin Coreの基本操作

新しくノードを建てる方が増えたりと、LNの盛り上がりを感じる昨今ですが、今回はあえてBitcoin Coreを触ってみます。

というのも、肝心のBitcoin Coreを全く触ったことがなかったので、今回は備忘録としてbitcoin-cliを使った基本操作を記事にしました。

実行環境

  • Ubuntu 20.04
  • Bitcoin Core v23.0
  • Signet

1. Bitcoin Coreのインストール

ソースコードからビルドしてみます。

①. 依存関係のインストール

$ sudo apt-get install build-essential libtool autotools-dev automake pkg-config bsdmainutils python3 libevent-dev libboost-dev libsqlite3-dev libminiupnpc-dev libnatpmp-dev libzmq3-dev systemtap-sdt-dev

②. ソースコードのダウンロード

$ git clone https://github.com/bitcoin/bitcoin.git
$ git checkout v23.0

③. Berkley DB v4.8のインストール(古いwallet.datとの互換性のため)

$ cd bitcoin/contrib/
$ ./install_db4.sh `pwd`

ビルドの際に必要になるので、以下の出力をメモする。

export BDB_PREFIX='/home/<user>/bitcoin/contrib/db4'
./configure BDB_LIBS="-L${BDB_PREFIX}/lib -ldb_cxx-4.8" BDB_CFLAGS="-I${BDB_PREFIX}/include"

④. ビルド

$ cd ..
$ ./autogen.sh
$ export BDB_PREFIX='/home/<user>/bitcoin/contrib/db4'
$ ./configure BDB_LIBS="-L${BDB_PREFIX}/lib -ldb_cxx-4.8" BDB_CFLAGS="-I${BDB_PREFIX}/include"
$ make

⑤. インストール

$ sudo make install


2. ウォレット

①. createwallet
ウォレットを作成

$ bitcoin-cli createwallet "mywallet"
{
  "name": "mywallet",
  "warning": ""
}

作成されたウォレットのデータは~/.bitcoin/<network>/walletsに保存されます。

$ ls ~/.bitcoin/signet/wallets/
mywallet

パスフレーズを使って暗号化する場合はpassphraseオプションを使用

$ bitcoin-cli -named createwallet wallet_name="mywallet" passphrase="passphrase"

②. backupwallet
指定したパスにwallet.datファイルをコピー

$ bitcoin-cli -rpcwallet="mywallet" backupwallet "/path/to/backup.dat"

③. restorewallet
バックアップファイルからウォレットをリストア

$ bitcoin-cli restorewallet "testwallet" "/path/to/backup.dat"
{
  "name": "testwallet",
  "warning": ""
}

3. アドレス

①. getnewaddress
デフォルトではbech32アドレスを作成

$ bitcoin-cli getnewaddress
tb1qddnmwxlmhvks4fqx30xug9lqaq92mcyfvfxu0h

legacyp2sh-segwitbech32bech32mのアドレスが指定可能

$ bitcoin-cli getnewaddress "" "legacy"
muMSDcBWLh25hzBdty27Ky4URhQrJoK9SJ

使用する機会はあまりないと思いますが、あるアドレスが自分の管理下(秘密鍵を持っている)であることを証明したいとき、signmessageでメッセージを秘密鍵で署名し、

$ bitcoin-cli signmessage "mpLcr9m8gkxvEVGpkYUkC5Cvm1rBVnCXgG" "Hello"
H8vjRK89UG9zS3LlbAoEzTQ+LQdPsfVljE4Lqft9D0LbFDVOU6dYwVLdUjfd/tctADa9PYfywLrq2ZjGPHg34xY=

verifymessageで検証できます(legacyアドレスのみ)。

$ bitcoin-cli verifymessage "muMSDcBWLh25hzBdty27Ky4URhQrJoK9SJ" "H8vjRK89UG9zS3LlbAoEzTQ+LQdPsfVljE4Lqft9D0LbFDVOU6dYwVLdUjfd/tctADa9PYfywLrq2ZjGPHg34xY=" "Hello"
true

②. getrawchangeaddress
おつり用のアドレスを作成(主にcreaterawtransactionで使用)

$ bitcoin-cli getrawchangeaddress
tb1qk5tjpkx0fk870q8g0tm4z74srqz7tmj354sp9l

③. getaddressinfo
アドレスの情報を取得する

$ bitcoin-cli getaddressinfo "tb1qxm2n55wpmfyapta3pay42t6e2dq9xuwzw3y7ks"
{
  "address": "tb1qxm2n55wpmfyapta3pay42t6e2dq9xuwzw3y7ks",
  "scriptPubKey": "001436d53a51c1da49d0afb10f49552f5953405371c2",
  "ismine": true,
  "solvable": true,
  "desc": "wpkh([5f1c3b57/84'/1'/0'/0/10]029c8876ba84bbfe63ef200d6701bb9b56bfe0d69250a76a02464bec37340fdeb9)#hw6n4vr2",
  "parent_desc": "wpkh([5f1c3b57/84'/1'/0']tpubDDgHZsHyy94PNZqpKeGZpTPdtEEgNzemsGsfa1HxuzniKpze5jciP2dbasG3pwaYTerXRyLQGdndGtqcxhwxfLwVzeq3kmhzTXsEMdsym1e/0/*)#j2vpqxyc",
  "iswatchonly": false,
  "isscript": false,
  "iswitness": true,
  "witness_version": 0,
  "witness_program": "36d53a51c1da49d0afb10f49552f5953405371c2",
  "pubkey": "029c8876ba84bbfe63ef200d6701bb9b56bfe0d69250a76a02464bec37340fdeb9",
  "ischange": false,
  "timestamp": 1658579249,
  "hdkeypath": "m/84'/1'/0'/0/10",
  "hdseedid": "0000000000000000000000000000000000000000",
  "hdmasterfingerprint": "5f1c3b57",
  "labels": [
    ""
  ]
}

④. addmultisigaddress
マルチシグアドレスをウォレットに追加する。
descriptor walletではサポートされていないので、descriptorを無効にしたウォレットを作成

$ bitcoin-cli -named createwallet descriptors=false wallet_name="mywallet2"
{
  "name": "mywallet2",
  "warning": ""
}

自分とアリスとボブの鍵を使用した2-of-3のマルチシグアドレスを作成する。
複数のウォレットがロードされている場合は、-rpcwalletで使用するウォレットを指定する。

me$ bitcoin-cli -rpcwallet="mywallet2" getnewaddress
tb1qxmu72pgdyjgqpwr2gpgsuxw4carg6v900psx36

alice$ bitcoin-cli getnewaddress
tb1qnvkuru5nzlhpjr7xy06784uqyvsfgm65k9tacr

bob$ bitcoin-cli getnewaddress
tb1qpl82vg9pg5lkr2cn0jc3drhkn257jx3n7qqt8n

getaddressinfoでそれぞれのアドレスの公開鍵を確認する

me$ bitcoin-cli -rpcwallet="mywallet2" getaddressinfo "tb1qxmu72pgdyjgqpwr2gpgsuxw4carg6v900psx36"
{
...
  "pubkey": "02e62426c2d36b94fa10fb6b1d05cf06dd6ffcd975857617e7b38070a2069ee51b",
...
}

alice$ bitcoin-cli getaddressinfo "tb1qnvkuru5nzlhpjr7xy06784uqyvsfgm65k9tacr"
{
...
  "pubkey": "026ece8f6129d03e148c6add23d0b7af6f74d6a723b547af30ff070b7b981c07cc",
...
}

bob$ bitcoin-cli getaddressinfo "tb1qpl82vg9pg5lkr2cn0jc3drhkn257jx3n7qqt8n"
{
...
  "pubkey": "039cda88cd0987a320421952761fd49404422c3d0c7e636be34880e9215c54393a",
...
}

マルチシグアドレスを作成

$ bitcoin-cli -named -rpcwallet="mywallet2" addmultisigaddress nrequired=2 keys='["02e62426c2d36b94fa10fb6b1d05cf06dd6ffcd975857617e7b38070a2069ee51b","026ece8f6129d03e148c6add23d0b7af6f74d6a723b547af30ff070b7b981c07cc","039cda88cd0987a320421952761fd49404422c3d0c7e636be34880e9215c54393a"]'
{
  "address": "tb1qfxf0jwxmxeuyznz7ceqeud0dylxm88yphg4h8hw6jrt8u8hu8rks72fx0n",
  "redeemScript": "522102e62426c2d36b94fa10fb6b1d05cf06dd6ffcd975857617e7b38070a2069ee51b21026ece8f6129d03e148c6add23d0b7af6f74d6a723b547af30ff070b7b981c07cc21039cda88cd0987a320421952761fd49404422c3d0c7e636be34880e9215c54393a53ae",
  "descriptor": "wsh(multi(2,[5e52b1f7/0'/0'/0']02e62426c2d36b94fa10fb6b1d05cf06dd6ffcd975857617e7b38070a2069ee51b,[9b2dc1f2]026ece8f6129d03e148c6add23d0b7af6f74d6a723b547af30ff070b7b981c07cc,[0fcea620]039cda88cd0987a320421952761fd49404422c3d0c7e636be34880e9215c54393a))#tz0yng28"
}

4. 残高

testnetではhttps://bitcoinfaucet.uo1.net/、signetではhttps://signetfaucet.com/等のfausetが利用できます。

①. getunconfirmedbalance
未承認残高の確認

$ bitcoin-cli getunconfirmedbalance 
0.00100000

②. getbalance
承認済残高の確認

$ bitcoin-cli getbalance
0.00100000

③. listunspent
UTXOのリストを取得

$ bitcoin-cli listunspent
[
  {
    "txid": "39ee72ef89519151fb4c55b85718d9599a1e54a0c5af77c96b414d9b8b5d4c5d",
    "vout": 0,
    "address": "tb1qddnmwxlmhvks4fqx30xug9lqaq92mcyfvfxu0h",
    "label": "",
    "scriptPubKey": "00146b67b71bfbbb2d0aa4068bcdc417e0e80aade089",
    "amount": 0.00100000,
    "confirmations": 1,
    "spendable": true,
    "solvable": true,
    "desc": "wpkh([5f1c3b57/84'/1'/0'/0/0]02548877a71ead3dde5d59a5bffd0a449f5a6fd6aa70c4c5c170ce520d0022fe9c)#xcwf8uqj",
    "safe": true
  }
]

5. トランザクション

①. listtransactions
ウォレット内のトランザクション一覧を取得

$ bitcoin-cli listtransactions
[
  {
    "address": "tb1qddnmwxlmhvks4fqx30xug9lqaq92mcyfvfxu0h",
    "category": "receive",
    "amount": 0.00100000,
    "label": "",
    "vout": 0,
    "confirmations": 1,
    "blockhash": "0000016540c3cf1094f826280777c1855fdf145a33d625d017f8e537511cf7ac",
    "blockheight": 100291,
    "blockindex": 11,
    "blocktime": 1658580836,
    "txid": "39ee72ef89519151fb4c55b85718d9599a1e54a0c5af77c96b414d9b8b5d4c5d",
    "walletconflicts": [
    ],
    "time": 1658580172,
    "timereceived": 1658580172,
    "bip125-replaceable": "no"
  }
]

②. gettransaction 
ウォレットの特定のトランザクションの情報を取得する

$ bitcoin-cli gettransaction "39ee72ef89519151fb4c55b85718d9599a1e54a0c5af77c96b414d9b8b5d4c5d"
{
  "amount": 0.00100000,
  "confirmations": 1,
  "blockhash": "0000016540c3cf1094f826280777c1855fdf145a33d625d017f8e537511cf7ac",
  "blockheight": 100291,
  "blockindex": 11,
  "blocktime": 1658580836,
  "txid": "39ee72ef89519151fb4c55b85718d9599a1e54a0c5af77c96b414d9b8b5d4c5d",
  "walletconflicts": [
  ],
  "time": 1658580172,
  "timereceived": 1658580172,
  "bip125-replaceable": "no",
  "details": [
    {
      "address": "tb1qddnmwxlmhvks4fqx30xug9lqaq92mcyfvfxu0h",
      "category": "receive",
      "amount": 0.00100000,
      "label": "",
      "vout": 0
    }
  ],
  "hex": "02000000000101e35b08f0365a964ad286dc8169957d2ef9b53216b49bd97015ed83fad262cb520100000000feffffff02a0860100000000001600146b67b71bfbbb2d0aa4068bcdc417e0e80aade089d79da04653060000160014a0c152a0aa8e9bfa0c723f57a15e703aabf111230247304402206ad3c6ba5c01368fc5ff7a0ca5bab0f21eeacd8d3a753cfb6deeec1927162ac202206a0cca3a051fd43a49f03a6273548ebe1fdb512eff06f1d7dcbb91be4689926e0121024e73aa1c9994904f6057124e1a0488a94ccaaf1411f1cc649c15e64e67a45a4ac2870100"
}

verboseオプションを有効にすることで、より詳細な情報を取得できる

$ bitcoin-cli -named gettransaction verbose="true" txid="39ee72ef89519151fb4c55b85718d9599a1e54a0c5af77c96b414d9b8b5d4c5d"

③. getrawtransaction 
ウォレットには関係ないトランザクションの情報を取得する

$ bitcoin-cli -named getrawtransaction verbose="true" txid="1a38b64a662ff4b75628f3962680909386d7a24525de15d9411914e1bfca701a"

6. 送金

①. sendtoaddress
指定したアドレスに送金する

$ bitcoin-cli sendtoaddress "tb1q5rq49g9236dl5rrj8at6zhns824lzyfrqjpsz7" "0.00001"
b0730152e00815f1427713a86aa2acee731c6507847f0dd17cb3c0596b221a77

手動で手数料レート(sat/vB)を設定する場合はfee_rateオプションで指定する

$ bitcoin-cli -named sendtoaddress fee_rate="1" address="tb1q5rq49g9236dl5rrj8at6zhns824lzyfrqjpsz7" amount="0.00001"
e8216fc5f0bc8e8b4b531e5fda8b986e0ef858b3d8613b39e4312183d6ff384a

RBFを許可する場合はreplaceableオプションを有効にする。常に許可したい場合は、bitcoindを-walletrbfで起動する。

$ bitcoin-cli -named sendtoaddress replaceable=true address="tb1qlzaj3pd9r5ge78w4m9ytazvppy9h842r5u27pe" amount="0.0001"
46df2078288888ef0efbce3a85a44fb503559db94130d4b45e46dd058a70adad

②. bumpfee
RBFを使ってトランザクションを再送信する場合はbumpfeeを使用する。新しい手数料は、"fee_rate"で指定するか、指定しない場合はestimatesmartfeeで自動的に計算される。

$ bitcoin-cli bumpfee "46df2078288888ef0efbce3a85a44fb503559db94130d4b45e46dd058a70adad" '{"fee_rate":8}'
{
  "txid": "e9c2c336248b06b58bcfaf5f190e68656e082048b3f713ad2f75f70ae2e0fb5f",
  "origfee": 0.00000208,
  "fee": 0.00002208,
  "errors": [
  ]
}

7. トランザクションの作成

①. createrawtransaction 
トランザクションを作成する
今回は1 input, 2 outputsのトランザクションを作成

$ bitcoin-cli -named createrawtransaction inputs='[{"txid":"f849a0a46466ac323ad382c58b941306aac65b8e407fdcef81cdea97077778a1","vout":1}]' outputs='{"tb1qt3r3n8a2wl2ljc90jf9rjjtf2ptlu044pvqv8u":0.0001,"tb1qk5tjpkx0fk870q8g0tm4z74srqz7tmj354sp9l":0.00089857}'
0200000001a178770797eacd81efdc7f408e5bc6aa0613948bc582d33a32ac6664a4a049f80100000000ffffffff0210270000000000001600145c47199faa77d5f960af924a3949695057fe3eb5015f010000000000160014b51720d8cf4d8fe780e87af7517ab01805e5ee5100000000

②. signrawtransactionwithwallet 
inputsに署名

$ bitcoin-cli signrawtransactionwithwallet 0200000001a178770797eacd81efdc7f408e5bc6aa0613948bc582d33a32ac6664a4a049f80100000000ffffffff0210270000000000001600145c47199faa77d5f960af924a3949695057fe3eb5015f010000000000160014b51720d8cf4d8fe780e87af7517ab01805e5ee5100000000
{
  "hex": "02000000000101a178770797eacd81efdc7f408e5bc6aa0613948bc582d33a32ac6664a4a049f80100000000ffffffff0210270000000000001600145c47199faa77d5f960af924a3949695057fe3eb5015f010000000000160014b51720d8cf4d8fe780e87af7517ab01805e5ee510247304402206a49c9b3ba3d073b244fa6873a49a88f30e60a81b984901187d2dc64ca0a648c022067f2be04a8839c1d9b9153db4f7b1c3d0925b04d2b1b0529b67f227c49a6515d01210214d16e5b7874849030d1458a7f9179a48ef573e32178bbf99844b29f7dccc9fd00000000",
  "complete": true
}

③. sendrawtransaction 
トランザクションを送信

$ bitcoin-cli sendrawtransaction 02000000000101a178770797eacd81efdc7f408e5bc6aa0613948bc582d33a32ac6664a4a049f80100000000ffffffff0210270000000000001600145c47199faa77d5f960af924a3949695057fe3eb5015f010000000000160014b51720d8cf4d8fe780e87af7517ab01805e5ee510247304402206a49c9b3ba3d073b244fa6873a49a88f30e60a81b984901187d2dc64ca0a648c022067f2be04a8839c1d9b9153db4f7b1c3d0925b04d2b1b0529b67f227c49a6515d01210214d16e5b7874849030d1458a7f9179a48ef573e32178bbf99844b29f7dccc9fd00000000
879d55a23c4e0b9f8a2544cdb72443eda4dea6fc607ae49f48a861b489eecd80

8. RBF、CPFPトランザクションの作成

createrawtransactionでRBFを許可するトランザクションを作成する場合は、replaceableオプションを有効にする

$ bitcoin-cli -named createrawtransaction replaceable=true inputs='[{"txid":"28f51b24a351c9d249fe4190a73fbfb3575b5597b25b79908bb773aa65ff4786","vout":0}]' outputs='{"tb1qt3r3n8a2wl2ljc90jf9rjjtf2ptlu044pvqv8u":0.0001,"tb1qmu0ay49ul686eqn5pjzmuj4vlxvw72xjcfwn4m":0.00089859}'

RBFを使ってトランザクションを再送信する場合は、対象のトランザクションと同じUTXOを使用し、手数料レートを上げたものを送信する

$ bitcoin-cli -named createrawtransaction inputs='[{"txid":"28f51b24a351c9d249fe4190a73fbfb3575b5597b25b79908bb773aa65ff4786","vout":0}]' outputs='{"tb1qt3r3n8a2wl2ljc90jf9rjjtf2ptlu044pvqv8u":0.0001,"tb1qmu0ay49ul686eqn5pjzmuj4vlxvw72xjcfwn4m":0.00089154}'

自分宛の未承認トランザクションがある際に、自分宛のoutputをinputとしたトランザクションを作成し、手数料レートを上げた後に送信することで、承認時間が短縮されることがある(CPFP)。
getrawtransactionで自分宛のoutputのindexを確認し、

$ bitcoin-cli getrawtransaction "2741d32f8c79480363ed326632cbbbf2b9a039565add7cbb8c324640e9f647a8" true
...
  "vout": [
...
    {
      "value": 0.00069718,
      "n": 1,
      "scriptPubKey": {
        "asm": "0 a49f76504b3f8d2c5beca6396a68546081aadaa7",
        "desc": "addr(tb1q5j0hv5zt87xjcklv5cuk56z5vzq64k487xtq0n)#l8me3dk4",
        "hex": "0014a49f76504b3f8d2c5beca6396a68546081aadaa7",
        "address": "tb1q5j0hv5zt87xjcklv5cuk56z5vzq64k487xtq0n",
        "type": "witness_v0_keyhash"
      }
    }
  ],
...

そのoutputをinputとして使用し、手数料レートを上げ、トランザクションを作成し、送信する。

$ bitcoin-cli -named createrawtransaction inputs='[{"txid":"2741d32f8c79480363ed326632cbbbf2b9a039565add7cbb8c324640e9f647a8","vout":1}]' outputs='{"tb1qk7aan6s4c0cwne4324jpamnueuq5ke8f4gpgc6":0.00069058}'

9. マルチシグアドレスからの送金

マルチシグアドレス(3. アドレスで作成したものを使用)のUTXOを使用し、トランザクションを作成

$ bitcoin-cli -named createrawtransaction inputs='[{"txid":"1d2ec624133e84ed188f23202d657c1e47749446e719ddc211e08d5bbaa9718a","vout":0}]' outputs='[{"tb1qyzhu5mpz394xzphrfa69afr5rgmm00lle8mau6":0.00099854}]'
02000000018a71a9ba5b8de011c2dd19e7469474471e7c652d20238f18ed843e1324c62e1d0000000000ffffffff010e860100

inputsに署名

me$ bitcoin-cli -rpcwallet="mywallet2" signrawtransactionwithwallet "02000000018a71a9ba5b8de011c2dd19e7469474471e7c652d20238f18ed843e1324c62e1d0000000000ffffffff010e8601000000000016001420afca6c22896a6106e34f745ea4741a37b7bfff00000000"
{
  "hex": "020000000001018a71a9ba5b8de011c2dd19e7469474471e7c652d20238f18ed843e1324c62e1d0000000000ffffffff010e8601000000000016001420afca6c22896a6106e34f745ea4741a37b7bfff040047304402200e1e1f422b417a1b0cf66dd9e467e018f65c4874b2978b96de3b5759d5fcefcc022026540a7f55ef7ff5de32b3a288224ab3132b0b7c776f8b2f90ad16ff36c6e77c010069522102e62426c2d36b94fa10fb6b1d05cf06dd6ffcd975857617e7b38070a2069ee51b21026ece8f6129d03e148c6add23d0b7af6f74d6a723b547af30ff070b7b981c07cc21039cda88cd0987a320421952761fd49404422c3d0c7e636be34880e9215c54393a53ae00000000",
  "complete": false,
  "errors": [
    {
      "txid": "1d2ec624133e84ed188f23202d657c1e47749446e719ddc211e08d5bbaa9718a",
      "vout": 0,
      "witness": [
        "",
        "304402200e1e1f422b417a1b0cf66dd9e467e018f65c4874b2978b96de3b5759d5fcefcc022026540a7f55ef7ff5de32b3a288224ab3132b0b7c776f8b2f90ad16ff36c6e77c01",
        "",
        "522102e62426c2d36b94fa10fb6b1d05cf06dd6ffcd975857617e7b38070a2069ee51b21026ece8f6129d03e148c6add23d0b7af6f74d6a723b547af30ff070b7b981c07cc21039cda88cd0987a320421952761fd49404422c3d0c7e636be34880e9215c54393a53ae"
      ],
      "scriptSig": "",
      "sequence": 4294967295,
      "error": "CHECK(MULTI)SIG failing with non-zero signature (possibly need more signatures)"
    }
  ]
}

署名したトランザクションにアリスの署名を追加し、

alice$ bitcoin-cli signrawtransactionwithwallet "020000000001018a71a9ba5b8de011c2dd19e7469474471e7c652d20238f18ed843e1324c62e1d0000000000ffffffff010e8601000000000016001420afca6c22896a6106e34f745ea4741a37b7bfff040047304402200e1e1f422b417a1b0cf66dd9e467e018f65c4874b2978b96de3b5759d5fcefcc022026540a7f55ef7ff5de32b3a288224ab3132b0b7c776f8b2f90ad16ff36c6e77c010069522102e62426c2d36b94fa10fb6b1d05cf06dd6ffcd975857617e7b38070a2069ee51b21026ece8f6129d03e148c6add23d0b7af6f74d6a723b547af30ff070b7b981c07cc21039cda88cd0987a320421952761fd49404422c3d0c7e636be34880e9215c54393a53ae00000000"
{
  "hex": "020000000001018a71a9ba5b8de011c2dd19e7469474471e7c652d20238f18ed843e1324c62e1d0000000000ffffffff010e8601000000000016001420afca6c22896a6106e34f745ea4741a37b7bfff040047304402200e1e1f422b417a1b0cf66dd9e467e018f65c4874b2978b96de3b5759d5fcefcc022026540a7f55ef7ff5de32b3a288224ab3132b0b7c776f8b2f90ad16ff36c6e77c01473044022011dc627931a40c7875a6fdc44df10bdf587700ab3cf0b21a483376b6cda120fb02201d4fec687e067b7aab024252a9520fe33dab969eab9a946201ea1f6bbf55f3520169522102e62426c2d36b94fa10fb6b1d05cf06dd6ffcd975857617e7b38070a2069ee51b21026ece8f6129d03e148c6add23d0b7af6f74d6a723b547af30ff070b7b981c07cc21039cda88cd0987a320421952761fd49404422c3d0c7e636be34880e9215c54393a53ae00000000",
  "complete": true
}

トランザクションを送信

$ bitcoin-cli sendrawtransaction "020000000001018a71a9ba5b8de011c2dd19e7469474471e7c652d20238f18ed843e1324c62e1d0000000000ffffffff010e8601000000000016001420afca6c22896a6106e34f745ea4741a37b7bfff040047304402200e1e1f422b417a1b0cf66dd9e467e018f65c4874b2978b96de3b5759d5fcefcc022026540a7f55ef7ff5de32b3a288224ab3132b0b7c776f8b2f90ad16ff36c6e77c01473044022011dc627931a40c7875a6fdc44df10bdf587700ab3cf0b21a483376b6cda120fb02201d4fec687e067b7aab024252a9520fe33dab969eab9a946201ea1f6bbf55f3520169522102e62426c2d36b94fa10fb6b1d05cf06dd6ffcd975857617e7b38070a2069ee51b21026ece8f6129d03e148c6add23d0b7af6f74d6a723b547af30ff070b7b981c07cc21039cda88cd0987a320421952761fd49404422c3d0c7e636be34880e9215c54393a53ae00000000"
ddd847161fde9d0721f46c0953010e4b0f0271c51665fcf63fffc00a25f60bb3

10. PSBTを使ったマルチシグアドレスからの送金

自分とアリスの鍵を使った2-of-2マルチシグアドレスから、各々に均等な額を送金する。

各自受け取り用のアドレスを作成

me$ bitcoin-cli getnewaddress
tb1q4lnyarnk7jpl30fuydc27vm7ggye2jkkgyyt3f

alice$ bitcoin-cli getnewaddress
tb1qxwg7735pkwr5csyppwvm98wu9csu7d86m3aa0v

CreaterはPSBTを作成し、Signerに送信

creater$ bitcoin-cli -named createpsbt inputs='[{"txid":"4a0b49aacdafeb0ac2401875ff4350a36934ffe0895b975d2aad19f8a5b09a1c","vout":0}]' outputs='{"tb1q4lnyarnk7jpl30fuydc27vm7ggye2jkkgyyt3f":0.00049916,"tb1qxwg7735pkwr5csyppwvm98wu9csu7d86m3aa0v":0.00049916}'
cHNidP8BAHECAAAAARyasKX4Ga0qXZdbieD/NGmjUEP/dRhAwgrrr82qSQtKAAAAAAD/////AvzCAAAAAAAAFgAUr+ZOjnb0g/i9PCNwrzN+QgmVStb8wgAAAAAAABYAFDOR70aBs4dMQIELmbKd3C4hzzT6AAAAAAAAAAA=

Signerは受け取ったPSBTに署名し、Combinerに送信

me$ bitcoin-cli walletprocesspsbt cHNidP8BAHECAAAAARyasKX4Ga0qXZdbieD/NGmjUEP/dRhAwgrrr82qSQtKAAAAAAD/////AvzCAAAAAAAAFgAUr+ZOjnb0g/i9PCNwrzN+QgmVStb8wgAAAAAAABYAFDOR70aBs4dMQIELmbKd3C4hzzT6AAAAAAAAAAA=
{
  "psbt": "cHNidP8BAHECAAAAARyasKX4Ga0qXZdbieD/NGmjUEP/dRhAwgrrr82qSQtKAAAAAAD/////AvzCAAAAAAAAFgAUr+ZOjnb0g/i9PCNwrzN+QgmVStb8wgAAAAAAABYAFDOR70aBs4dMQIELmbKd3C4hzzT6AAAAAAABAH0CAAAAAROACAaWR59J+3uOqSdXfWLBWG6x1cjZb7k+VHWjDgmsAQAAAAD+////AqCGAQAAAAAAIgAgzTf6ieqjvTkhD08Z9qL7tfecd9ZrjRLtpN18/cWs28RBrEgtVwYAABYAFDaCzr4kjLSuYzYPbhEWVd5Drh4MOI0BAAEBK6CGAQAAAAAAIgAgzTf6ieqjvTkhD08Z9qL7tfecd9ZrjRLtpN18/cWs28QiAgPf3Z4FRIVF1FZ4lUi/qLkUZ4YoJCNYNVIFC3JbOrz4XEcwRAIgAtTMThy7co50MkseRA06xqHB58+PIbEUDnQeHOUrzesCIGxeRTynpEKM/tXshlRvGJFMSfKUFfmse93rk4L1OI4RAQEFR1IhA9/dngVEhUXUVniVSL+ouRRnhigkI1g1UgULcls6vPhcIQPCKZ+0mJ9ZDSdhGRE/33lsUPI1YBj5xrQ+vAj3NRru2VKuIgYDwimftJifWQ0nYRkRP995bFDyNWAY+ca0PrwI9zUa7tkElHM/7CIGA9/dngVEhUXUVniVSL+ouRRnhigkI1g1UgULcls6vPhcEC29pIwAAACAAAAAgAIAAIAAIgICgr+sC/EE4dmcZtE39y7AmTO6foO/cw85Q8To+ewtwnsQLb2kjAAAAIAAAACAAwAAgAAA",
  "complete": false
}

alice$ bitcoin-cli walletprocesspsbt cHNidP8BAHECAAAAARyasKX4Ga0qXZdbieD/NGmjUEP/dRhAwgrrr82qSQtKAAAAAAD/////AvzCAAAAAAAAFgAUr+ZOjnb0g/i9PCNwrzN+QgmVStb8wgAAAAAAABYAFDOR70aBs4dMQIELmbKd3C4hzzT6AAAAAAAAAAA=
{
  "psbt": "cHNidP8BAHECAAAAARyasKX4Ga0qXZdbieD/NGmjUEP/dRhAwgrrr82qSQtKAAAAAAD/////AvzCAAAAAAAAFgAUr+ZOjnb0g/i9PCNwrzN+QgmVStb8wgAAAAAAABYAFDOR70aBs4dMQIELmbKd3C4hzzT6AAAAAAABAH0CAAAAAROACAaWR59J+3uOqSdXfWLBWG6x1cjZb7k+VHWjDgmsAQAAAAD+////AqCGAQAAAAAAIgAgzTf6ieqjvTkhD08Z9qL7tfecd9ZrjRLtpN18/cWs28RBrEgtVwYAABYAFDaCzr4kjLSuYzYPbhEWVd5Drh4MOI0BAAEBK6CGAQAAAAAAIgAgzTf6ieqjvTkhD08Z9qL7tfecd9ZrjRLtpN18/cWs28QiAgPCKZ+0mJ9ZDSdhGRE/33lsUPI1YBj5xrQ+vAj3NRru2UcwRAIgCTgn92trgs54XgETel/cD4hjmSu8A1syUYw8TWsGOQECIAKjggpP18MtZ6T/jsTyT4gUuRvWom3quuHiZJm+I8s2AQEFR1IhA9/dngVEhUXUVniVSL+ouRRnhigkI1g1UgULcls6vPhcIQPCKZ+0mJ9ZDSdhGRE/33lsUPI1YBj5xrQ+vAj3NRru2VKuIgYDwimftJifWQ0nYRkRP995bFDyNWAY+ca0PrwI9zUa7tkQ9a4ouQAAAIAAAACAAgAAgCIGA9/dngVEhUXUVniVSL+ouRRnhigkI1g1UgULcls6vPhcBB7zmy8AACICAsIHOIhIOEBuO7Ks2y7Pv4in8h5ciTJJx4unRlD/v09YEPWuKLkAAACAAAAAgAMAAIAA",
  "complete": false
}

Combinerは各SignerのPSBTを結合

combiner$ bitcoin-cli combinepsb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zesCIGxeRTynpEKM/tXshlRvGJFMSfKUFfmse93rk4L1OI4RASICA8Ipn7SYn1kNJ2EZET/feWxQ8jVgGPnGtD68CPc1Gu7ZRzBEAiAJOCf3a2uCznheARN6X9wPiGOZK7wDWzJRjDxNawY5AQIgAqOCCk/Xwy1npP+OxPJPiBS5G9aibeq64eJkmb4jyzYBAQVHUiED392eBUSFRdRWeJVIv6i5FGeGKCQjWDVSBQtyWzq8+FwhA8Ipn7SYn1kNJ2EZET/feWxQ8jVgGPnGtD68CPc1Gu7ZUq4iBgPCKZ+0mJ9ZDSdhGRE/33lsUPI1YBj5xrQ+vAj3NRru2QSUcz/sIgYD392eBUSFRdRWeJVIv6i5FGeGKCQjWDVSBQtyWzq8+FwQLb2kjAAAAIAAAACAAgAAgAAiAgKCv6wL8QTh2Zxm0Tf3LsCZM7p+g79zDzlDxOj57C3CexAtvaSMAAAAgAAAAIADAACAACICAsIHOIhIOEBuO7Ks2y7Pv4in8h5ciTJJx4unRlD/v09YEPWuKLkAAACAAAAAgAMAAIAA
{
  "hex": "020000000001011c9ab0a5f819ad2a5d975b89e0ff3469a35043ff751840c20aebafcdaa490b4a0000000000ffffffff02fcc2000000000000160014afe64e8e76f483f8bd3c2370af337e4209954ad6fcc20000000000001600143391ef4681b3874c40810b99b29ddc2e21cf34fa0400473044022002d4cc4e1cbb728e74324b1e440d3ac6a1c1e7cf8f21b1140e741e1ce52bcdeb02206c5e453ca7a4428cfed5ec86546f18914c49f29415f9ac7bddeb9382f5388e11014730440220093827f76b6b82ce785e01137a5fdc0f8863992bbc035b32518c3c4d6b063901022002a3820a4fd7c32d67a4ff8ec4f24f8814b91bd6a26deabae1e26499be23cb360147522103dfdd9e05448545d456789548bfa8b9146786282423583552050b725b3abcf85c2103c2299fb4989f590d276119113fdf796c50f2356018f9c6b43ebc08f7351aeed952ae00000000",
  "complete": true
}

トランザクションを送信

$ bitcoin-cli sendrawtransaction 020000000001011c9ab0a5f819ad2a5d975b89e0ff3469a35043ff751840c20aebafcdaa490b4a0000000000ffffffff02fcc2000000000000160014afe64e8e76f483f8bd3c2370af337e4209954ad6fcc20000000000001600143391ef4681b3874c40810b99b29ddc2e21cf34fa0400473044022002d4cc4e1cbb728e74324b1e440d3ac6a1c1e7cf8f21b1140e741e1ce52bcdeb02206c5e453ca7a4428cfed5ec86546f18914c49f29415f9ac7bddeb9382f5388e11014730440220093827f76b6b82ce785e01137a5fdc0f8863992bbc035b32518c3c4d6b063901022002a3820a4fd7c32d67a4ff8ec4f24f8814b91bd6a26deabae1e26499be23cb360147522103dfdd9e05448545d456789548bfa8b9146786282423583552050b725b3abcf85c2103c2299fb4989f590d276119113fdf796c50f2356018f9c6b43ebc08f7351aeed952ae00000000
ea69f0846033168d8928e67db5445b584310d68df8b31149fedcb44217b850ad

参考

有料部分では、Bitcoinのブロックチェーンに任意のデータを保存する方法を紹介しています。

Remaining : 869 characters / 0 images
100

Sign up / Continue after login

Related stories

Writer

Share

Popular stories

自前ノードを使って簡単なライトニングアプリを作ってみる

297

チャネルバックアップファイルを自動でクラウドに保存してみる

135

チャネルバックアップファイルを自動でコピーしてみる

112