5

Can you give a simple step-by-step example for a taproot transaction with bitcoin-cli on Testnet?

0

2 Answers 2

5

Steps that I followed to do a transaction which creates a P2TR output:

  1. Copy XPUB from test vectors mentioned in BIP 86
xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ
  1. Convert XPUB (mainnet) to TPUB (testnet) using Bitcoin Extended Public Key Converter
tpubDC3pD7UZXnsgh3EBjbtBQiB1FnLask7UHBSunZ1DPK4dCFFZoFRkgxHB8gt42FvLzx1DpxfHWxAsYaY6b643RVcGjDxXxns7wKKYnnfEcbB
  1. Create a blank descriptor wallet with private keys disabled:
bitcoin-cli -named createwallet wallet_name=taproot_wallet blank=true disable_private_keys=true descriptors=true
  1. Save the descriptor info in a text file for TPUB we got from step 2 (descriptor.txt):
[
  {
    "desc": "tr([8868ab13/86'/1'/0']tpubDC3pD7UZXnsgh3EBjbtBQiB1FnLask7UHBSunZ1DPK4dCFFZoFRkgxHB8gt42FvLzx1DpxfHWxAsYaY6b643RVcGjDxXxns7wKKYnnfEcbB/0/*)#06sjusfa",
    "timestamp": "now",
    "active": true,
    "internal": false,
    "range": [
      0,
      999
    ],
    "next": 0
  }
]

I have copied this format from listdescriptors output for a new descriptor wallet that had private keys enabled.

  1. Import this descriptor in wallet we created in step 3:
bitcoin-cli -rpcwallet=taproot_wallet importdescriptors "$(cat descriptor.txt)"
  1. This is a watch only wallet with a taproot descriptor TPUB that can be used to create new bech32m address:
bitcoin-cli -rpcwallet=taproot_wallet getnewaddress "" "bech32m"
tb1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqp3mvzv
  1. Send some bitcoin from another wallet:

https://blockstream.info/testnet/tx/2035ead4a9d0c8e2da1184924abc9034d26f2a7093371183ef12891623b235d1

I had compiled bitcoind with branch used by Sjors Provoost in PR #2260

2
  • But how do you spend from that taproot output? I guess you have to do the same steps while using a privKey instead of a xPub, right?
    – RobinLinus
    Aug 11, 2021 at 14:19
  • Yes use XPRV for mainnet and TPRV for testnet. Test vectors in BIP 86 had no TPRV so I had to follow the steps mentioned in this answer.
    – user103136
    Aug 11, 2021 at 14:23
0

There is the step-by-step example of spending from the tb1p8wpt9v4frpf3tkn0srd97pksgsxc5hs52lafxwru9kgeephvs7rqlqt9zj Taproot address to the other Taproot one: tb1p90h6z3p36n9hrzy7580h5l429uwchyg8uc9sz4jwzhdtuhqdl5eqmpwq6n.

$ ./bitcoin-cli.exe -testnet createrawtransaction '[{"txid":"8cdf19ed3ade4af038314ef58b116a523f99aa1c585ca3c157ce5386f9df6421","vout":0}]' '[{"tb1p90h6z3p36n9hrzy7580h5l429uwchyg8uc9sz4jwzhdtuhqdl5eqmpwq6n":0.00001000}]'
$ ./bitcoin-cli.exe -testnet importdescriptors '[ { "desc" : "tr(cV628xvqToz45dwdPmTcJ9RgEVnWMwP8dpZBGzb9LfTk3sBHFNwc)#8skcj28y", "timestamp" : "now" } ]'
$ ./bitcoin-cli.exe -testnet signrawtransactionwithwallet "02000000012164dff98653ce57c1a35c581caa993f526a118bf54e3138f04ade3aed19df8c0000000000fdffffff01e8030000000000002251202befa14431d4cb71889ea1df7a7eaa2f1d8b9107e60b01564e15dabe5c0dfd3200000000" '[{"txid": "8cdf19ed3ade4af038314ef58b116a523f99aa1c585ca3c157ce5386f9df6421", "vout": 0, "scriptPubKey": "5120c38859777bc9c3294d3587035fc3823a146dabaab1fa250bc04e92f16887a065", "amount": 0.00000000}]' "DEFAULT"
$ ./bitcoin-cli.exe -testnet sendrawtransaction 020000000001012164dff98653ce57c1a35c581caa993f526a118bf54e3138f04ade3aed19df8c0000000000fdffffff01e8030000000000002251202befa14431d4cb71889ea1df7a7eaa2f1d8b9107e60b01564e15dabe5c0dfd320140f10fc6bb1d414d4c888838fb6b1699c3e538331d32b64b5baf85c1cc34e2c43eb7bdd7a14fd4a4a07341d1b0390ad977be711bc49df786982243c6564a33f6b400000000

Note that the commands with arguments may not work from PowerShell. There is the Bash used in the example above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.