# bitcoind taproot regtest testing ## Setup 1. install local `bitcoind` and `bitcoin-cli` version 23.0. 2. start bitcoind in regtest mode. ```shell bitcoind -regtest -server -fallbackfee=0.0002 -rpcallowip=0.0.0.0/0 -rpcbind=0.0.0.0 -blockfilterindex=1 -peerblockfilters=1 ``` data will be saved in `$HOME/.bitcoin/regtest` ## Create Key Spend tr() PSBT 1. create a new descriptor wallet. ```shell bitcoin-cli -regtest -named createwallet wallet_name=trkeyspend disable_private_keys=true blank=true avoid_reuse=true descriptors=true load_on_startup=true ``` 2. verify blank wallet. ```shell bitcoin-cli -regtest -rpcwallet=trkeyspend listdescriptors ``` 3. get pub descriptor and checksum info. ```shell bitcoin-cli -regtest getdescriptorinfo "tr(tprv8ZgxMBicQKsPdDArR4xSAECuVxeX1jwwSXR4ApKbkYgZiziDc4LdBy2WvJeGDfUSE4UT4hHhbgEwbdq8ajjUHiKDegkwrNU6V55CxcxonVN/*)" ``` ```json { "descriptor": "tr(tpubD6NzVbkrYhZ4WgCeJid2Zds24zATB58r1q1qTLMuApUxZUxzETADNTeP6SvZKSsXs4qhvFAC21GFjXHwgxAcDtZqzzj8JMpsFDgqyjSJHGa/*)#p6qxwm0p", "checksum": "53nr4k3n", "isrange": true, "issolvable": true, "hasprivatekeys": true } ``` 4. add a single signature tr() descriptor to the "trkeyspend" wallet. ```shell bitcoin-cli -regtest -rpcwallet=trkeyspend importdescriptors '[{"desc":"tr(tpubD6NzVbkrYhZ4WgCeJid2Zds24zATB58r1q1qTLMuApUxZUxzETADNTeP6SvZKSsXs4qhvFAC21GFjXHwgxAcDtZqzzj8JMpsFDgqyjSJHGa/*)#p6qxwm0p","active":true,"timestamp":"now","label":"singlesig tr()" }]' ``` ```json [ { "success": true, "warnings": [ "Range not given, using default keypool range" ] } ] ``` 5. verify wallet descriptor. ```shell bitcoin-cli -regtest -rpcwallet=trkeyspend listdescriptors ``` ```json { "wallet_name": "trkeyspend", "descriptors": [ { "desc": "tr(tpubD6NzVbkrYhZ4WgCeJid2Zds24zATB58r1q1qTLMuApUxZUxzETADNTeP6SvZKSsXs4qhvFAC21GFjXHwgxAcDtZqzzj8JMpsFDgqyjSJHGa/*)#p6qxwm0p", "timestamp": 1296688602, "active": true, "internal": false, "range": [ 0, 999 ], "next": 0 } ] } ``` 6. get two new deposit address. ```shell bitcoin-cli -regtest -rpcwallet=trkeyspend getnewaddress "test generate to" "bech32m" bcrt1p3p03j3l949mguknpksdwx82wapgr87qrzx0e5j77qcy3tlyst6ast0v6xz bitcoin-cli -regtest -rpcwallet=trkeyspend getnewaddress "test send to" "bech32m" bcrt1pudwymxwvvv6p04g5uc2fzpeqd3fkntl9c558d0rlrlcnlazeautqm0u49z bitcoin-cli -regtest -rpcwallet=trkeyspend getnewaddress "test change" "bech32m" bcrt1pl0fwd8wseth46ydh28jvd0dhm9rukcvm542w557r8mpva6uz2gksg5q5p0 ``` 7. generate new bitcoin to tr() trkeyspend wallet. ```shell bitcoin-cli -regtest generatetoaddress 200 "bcrt1p3p03j3l949mguknpksdwx82wapgr87qrzx0e5j77qcy3tlyst6ast0v6xz" bitcoin-cli -regtest -rpcwallet=trkeyspend getbalance 5000.00000000 ``` 8. create spending PSBT in core from first to second address, change to third address. ```shell bitcoin-cli -regtest -rpcwallet=trkeyspend send '{"bcrt1pudwymxwvvv6p04g5uc2fzpeqd3fkntl9c558d0rlrlcnlazeautqm0u49z": 0.4321}' null unset null '{"change_address": "bcrt1pl0fwd8wseth46ydh28jvd0dhm9rukcvm542w557r8mpva6uz2gksg5q5p0", "psbt":true}' ``` ```json { "psbt": "cHNidP8BAIkCAAAAAYDkTndbEjC5MKDmvIhTC+9nUMn1oR7szUXeQlk0jOsFAAAAAAD+////AhBVkwIAAAAAIlEg41xNmcxjNBfVFOYUkQcgbFNpr+XFKHa8fx/xP/RZ7xbokHInAQAAACJRIPvS5p3Qyu9dEbdR5Ma9t9lHy2GbpVTqU8M+ws7rglItAAAAAAABAJECAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////wQBKwEB/////wIA8gUqAQAAACJRIIhfGUflqXaOWmG0GuMdTuhQM/gDEZ+aS94GCRX8kF67AAAAAAAAAAAmaiSqIant4vYcP3HR3v0/qZnfo2lTdVxpBol5mWK0i+vYNpdOjPkAAAAAAQErAPIFKgEAAAAiUSCIXxlH5al2jlphtBrjHU7oUDP4AxGfmkveBgkV/JBeuwAAAA==", "complete": false } ``` ## Create Script Spend tr() PSBT 1. create a new descriptor wallet. ```shell bitcoin-cli -regtest -named createwallet wallet_name=trscriptspend disable_private_keys=true blank=true avoid_reuse=true descriptors=true load_on_startup=true ``` 2. verify blank wallet. ```shell bitcoin-cli -regtest -rpcwallet=trscriptspend listdescriptors ``` 3. get pub descriptor and checksum info. ```shell bitcoin-cli -regtest getdescriptorinfo "tr(b511bd5771e47ee27558b1765e87b541668304ec567721c7b880edc0a010da55,{pk(tprv8ZgxMBicQKsPdDArR4xSAECuVxeX1jwwSXR4ApKbkYgZiziDc4LdBy2WvJeGDfUSE4UT4hHhbgEwbdq8ajjUHiKDegkwrNU6V55CxcxonVN/*),pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642)})" ``` ```json { "descriptor": "tr(b511bd5771e47ee27558b1765e87b541668304ec567721c7b880edc0a010da55,{pk(tpubD6NzVbkrYhZ4WgCeJid2Zds24zATB58r1q1qTLMuApUxZUxzETADNTeP6SvZKSsXs4qhvFAC21GFjXHwgxAcDtZqzzj8JMpsFDgqyjSJHGa/*),pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642)})#a3uvnj4v", "checksum": "cnpznagc", "isrange": true, "issolvable": true, "hasprivatekeys": true } ``` 4. add a script spend signature tr() descriptor to the "trkeyspend" wallet. ```shell bitcoin-cli -regtest -rpcwallet=trscriptspend importdescriptors '[{"desc":"tr(b511bd5771e47ee27558b1765e87b541668304ec567721c7b880edc0a010da55,{pk(tpubD6NzVbkrYhZ4WgCeJid2Zds24zATB58r1q1qTLMuApUxZUxzETADNTeP6SvZKSsXs4qhvFAC21GFjXHwgxAcDtZqzzj8JMpsFDgqyjSJHGa/*),pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642)})#a3uvnj4v","active":true,"timestamp":"now","label":"script spend tr()" }]' ``` ```json [ { "success": true, "warnings": [ "Range not given, using default keypool range" ] } ] ``` 5. verify wallet descriptor. ```shell bitcoin-cli -regtest -rpcwallet=trscriptspend listdescriptors ``` ```json { "wallet_name": "trscriptspend", "descriptors": [ { "desc": "tr(b511bd5771e47ee27558b1765e87b541668304ec567721c7b880edc0a010da55,{pk(tpubD6NzVbkrYhZ4WgCeJid2Zds24zATB58r1q1qTLMuApUxZUxzETADNTeP6SvZKSsXs4qhvFAC21GFjXHwgxAcDtZqzzj8JMpsFDgqyjSJHGa/*),pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642)})#a3uvnj4v", "timestamp": 1652824724, "active": true, "internal": false, "range": [ 0, 999 ], "next": 0 } ] } ``` 6. get two new deposit address. ```shell bitcoin-cli -regtest -rpcwallet=trscriptspend getnewaddress "test generate to" "bech32m" bcrt1pw7e7gmqj2085xdtxnp37kgnlgecwph2fguv77m66zw5flmp6zq9sn44c42 bitcoin-cli -regtest -rpcwallet=trscriptspend getnewaddress "test send to" "bech32m" bcrt1p6v74yeekflargt9hd8pck3ram0z3vepmf0ah8s5duvn8emvmvmhq64egkm bitcoin-cli -regtest -rpcwallet=trscriptspend getnewaddress "test change" "bech32m" bcrt1p2ltczq0t6tz2ez2mwu9zwmukdsq4khvlpy9c5kwlwndfxsuklz6qn93hg6 ``` 7. generate new bitcoin to tr() trkeyspend wallet. ```shell bitcoin-cli -regtest generatetoaddress 200 "bcrt1pw7e7gmqj2085xdtxnp37kgnlgecwph2fguv77m66zw5flmp6zq9sn44c42" bitcoin-cli -regtest -rpcwallet=trscriptspend getbalance 5000.00000000 ``` 8. create spending PSBT in core from first to second address, change to third address. ```shell bitcoin-cli -regtest -rpcwallet=trscriptspend send '{"bcrt1p6v74yeekflargt9hd8pck3ram0z3vepmf0ah8s5duvn8emvmvmhq64egkm": 0.54321}' null unset null '{"change_address": "bcrt1p2ltczq0t6tz2ez2mwu9zwmukdsq4khvlpy9c5kwlwndfxsuklz6qn93hg6", "psbt":true}' ``` ```json { "psbt": "cHNidP8BAIkCAAAAARwLJS8W4FXnZNme/7PIZ2bA4AjmtIZRYjuBklAIcmmuAAAAAAD+////ApAGySYBAAAAIlEgV9eBAevSxKyJW3cKJ2+WbAFbXZ8JC4pZ33Tak0OW+LRo3zwDAAAAACJRINM9Umc2T/o0LLdpw4tEfdvFFmQ7S/tzwo3jJnztm2buAAAAAAABAJECAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////wQBRAEB/////wIA8gUqAQAAACJRIHez5GwSU89DNWaYY+sif0Zw4N1JRxnvb1oTqJ/sOhALAAAAAAAAAAAmaiSqIant4vYcP3HR3v0/qZnfo2lTdVxpBol5mWK0i+vYNpdOjPkAAAAAAQErAPIFKgEAAAAiUSB3s+RsElPPQzVmmGPrIn9GcODdSUcZ729aE6if7DoQCwAAAA==", "complete": false } ``` 9. update PSBT segwit inputs and outputs in core. ```shell bitcoin-cli -regtest -rpcwallet=trkeyspend utxoupdatepsbt "cHNidP8BAIkCAAAAAX8Pluh49K9Oe1oEjrtCqhDHk5iLgdN/aUEfE+qEYf4qAAAAAAD+////AhBVkwIAAAAAIlEg41xNmcxjNBfVFOYUkQcgbFNpr+XFKHa8fx/xP/RZ7xbokHInAQAAACJRIPvS5p3Qyu9dEbdR5Ma9t9lHy2GbpVTqU8M+ws7rglItAAAAAAABAJECAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////wQBEgEB/////wIA8gUqAQAAACJRIIhfGUflqXaOWmG0GuMdTuhQM/gDEZ+aS94GCRX8kF67AAAAAAAAAAAmaiSqIant4vYcP3HR3v0/qZnfo2lTdVxpBol5mWK0i+vYNpdOjPkAAAAAAQErAPIFKgEAAAAiUSCIXxlH5al2jlphtBrjHU7oUDP4AxGfmkveBgkV/JBeuwAAAA==" cHNidP8BAIkCAAAAAX8Pluh49K9Oe1oEjrtCqhDHk5iLgdN/aUEfE+qEYf4qAAAAAAD+////AhBVkwIAAAAAIlEg41xNmcxjNBfVFOYUkQcgbFNpr+XFKHa8fx/xP/RZ7xbokHInAQAAACJRIPvS5p3Qyu9dEbdR5Ma9t9lHy2GbpVTqU8M+ws7rglItAAAAAAABAJECAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////wQBEgEB/////wIA8gUqAQAAACJRIIhfGUflqXaOWmG0GuMdTuhQM/gDEZ+aS94GCRX8kF67AAAAAAAAAAAmaiSqIant4vYcP3HR3v0/qZnfo2lTdVxpBol5mWK0i+vYNpdOjPkAAAAAAQErAPIFKgEAAAAiUSCIXxlH5al2jlphtBrjHU7oUDP4AxGfmkveBgkV/JBeuwAAAA== ``` ## bdk-cli help ```shell % bitcoind --version Bitcoin Core version v23.0 % bitcoin-cli --version Bitcoin Core RPC client version v23.0 % bitcoin-cli -regtest help == Blockchain == getbestblockhash getblock "blockhash" ( verbosity ) getblockchaininfo getblockcount getblockfilter "blockhash" ( "filtertype" ) getblockfrompeer "blockhash" peer_id getblockhash height getblockheader "blockhash" ( verbose ) getblockstats hash_or_height ( stats ) getchaintips getchaintxstats ( nblocks "blockhash" ) getdeploymentinfo ( "blockhash" ) getdifficulty getmempoolancestors "txid" ( verbose ) getmempooldescendants "txid" ( verbose ) getmempoolentry "txid" getmempoolinfo getrawmempool ( verbose mempool_sequence ) gettxout "txid" n ( include_mempool ) gettxoutproof ["txid",...] ( "blockhash" ) gettxoutsetinfo ( "hash_type" hash_or_height use_index ) preciousblock "blockhash" pruneblockchain height savemempool scantxoutset "action" ( [scanobjects,...] ) verifychain ( checklevel nblocks ) verifytxoutproof "proof" == Control == getmemoryinfo ( "mode" ) getrpcinfo help ( "command" ) logging ( ["include_category",...] ["exclude_category",...] ) stop uptime == Mining == getblocktemplate ( "template_request" ) getmininginfo getnetworkhashps ( nblocks height ) prioritisetransaction "txid" ( dummy ) fee_delta submitblock "hexdata" ( "dummy" ) submitheader "hexdata" == Network == addnode "node" "command" clearbanned disconnectnode ( "address" nodeid ) getaddednodeinfo ( "node" ) getconnectioncount getnettotals getnetworkinfo getnodeaddresses ( count "network" ) getpeerinfo listbanned ping setban "subnet" "command" ( bantime absolute ) setnetworkactive state == Rawtransactions == analyzepsbt "psbt" combinepsbt ["psbt",...] combinerawtransaction ["hexstring",...] converttopsbt "hexstring" ( permitsigdata iswitness ) createpsbt [{"txid":"hex","vout":n,"sequence":n},...] [{"address":amount,...},{"data":"hex"},...] ( locktime replaceable ) createrawtransaction [{"txid":"hex","vout":n,"sequence":n},...] [{"address":amount,...},{"data":"hex"},...] ( locktime replaceable ) decodepsbt "psbt" decoderawtransaction "hexstring" ( iswitness ) decodescript "hexstring" finalizepsbt "psbt" ( extract ) fundrawtransaction "hexstring" ( options iswitness ) getrawtransaction "txid" ( verbose "blockhash" ) joinpsbts ["psbt",...] sendrawtransaction "hexstring" ( maxfeerate ) signrawtransactionwithkey "hexstring" ["privatekey",...] ( [{"txid":"hex","vout":n,"scriptPubKey":"hex","redeemScript":"hex","witnessScript":"hex","amount":amount},...] "sighashtype" ) testmempoolaccept ["rawtx",...] ( maxfeerate ) utxoupdatepsbt "psbt" ( ["",{"desc":"str","range":n or [n,n]},...] ) == Signer == enumeratesigners == Util == createmultisig nrequired ["key",...] ( "address_type" ) deriveaddresses "descriptor" ( range ) estimatesmartfee conf_target ( "estimate_mode" ) getdescriptorinfo "descriptor" getindexinfo ( "index_name" ) signmessagewithprivkey "privkey" "message" validateaddress "address" verifymessage "address" "signature" "message" == Wallet == abandontransaction "txid" abortrescan addmultisigaddress nrequired ["key",...] ( "label" "address_type" ) backupwallet "destination" bumpfee "txid" ( options ) createwallet "wallet_name" ( disable_private_keys blank "passphrase" avoid_reuse descriptors load_on_startup external_signer ) dumpprivkey "address" dumpwallet "filename" encryptwallet "passphrase" getaddressesbylabel "label" getaddressinfo "address" getbalance ( "dummy" minconf include_watchonly avoid_reuse ) getbalances getnewaddress ( "label" "address_type" ) getrawchangeaddress ( "address_type" ) getreceivedbyaddress "address" ( minconf include_immature_coinbase ) getreceivedbylabel "label" ( minconf include_immature_coinbase ) gettransaction "txid" ( include_watchonly verbose ) getunconfirmedbalance getwalletinfo importaddress "address" ( "label" rescan p2sh ) importdescriptors "requests" importmulti "requests" ( "options" ) importprivkey "privkey" ( "label" rescan ) importprunedfunds "rawtransaction" "txoutproof" importpubkey "pubkey" ( "label" rescan ) importwallet "filename" keypoolrefill ( newsize ) listaddressgroupings listdescriptors ( private ) listlabels ( "purpose" ) listlockunspent listreceivedbyaddress ( minconf include_empty include_watchonly "address_filter" include_immature_coinbase ) listreceivedbylabel ( minconf include_empty include_watchonly include_immature_coinbase ) listsinceblock ( "blockhash" target_confirmations include_watchonly include_removed ) listtransactions ( "label" count skip include_watchonly ) listunspent ( minconf maxconf ["address",...] include_unsafe query_options ) listwalletdir listwallets loadwallet "filename" ( load_on_startup ) lockunspent unlock ( [{"txid":"hex","vout":n},...] persistent ) newkeypool psbtbumpfee "txid" ( options ) removeprunedfunds "txid" rescanblockchain ( start_height stop_height ) restorewallet "wallet_name" "backup_file" ( load_on_startup ) send [{"address":amount,...},{"data":"hex"},...] ( conf_target "estimate_mode" fee_rate options ) sendmany "" {"address":amount,...} ( minconf "comment" ["address",...] replaceable conf_target "estimate_mode" fee_rate verbose ) sendtoaddress "address" amount ( "comment" "comment_to" subtractfeefromamount replaceable conf_target "estimate_mode" avoid_reuse fee_rate verbose ) sethdseed ( newkeypool "seed" ) setlabel "address" "label" settxfee amount setwalletflag "flag" ( value ) signmessage "address" "message" signrawtransactionwithwallet "hexstring" ( [{"txid":"hex","vout":n,"scriptPubKey":"hex","redeemScript":"hex","witnessScript":"hex","amount":amount},...] "sighashtype" ) unloadwallet ( "wallet_name" load_on_startup ) upgradewallet ( version ) walletcreatefundedpsbt ( [{"txid":"hex","vout":n,"sequence":n,"weight":n},...] ) [{"address":amount,...},{"data":"hex"},...] ( locktime options bip32derivs ) walletdisplayaddress "address" walletlock walletpassphrase "passphrase" timeout walletpassphrasechange "oldpassphrase" "newpassphrase" walletprocesspsbt "psbt" ( sign "sighashtype" bip32derivs finalize ) ```