Skip to content

Instantly share code, notes, and snippets.

@pinheadmz
Last active April 17, 2024 04:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pinheadmz/cbf419396ac983ffead9670dde258a43 to your computer and use it in GitHub Desktop.
Save pinheadmz/cbf419396ac983ffead9670dde258a43 to your computer and use it in GitHub Desktop.
Use Bitcoin Core in regtest mode to generate a Taproot address

To start you need a master private key. For me, the easiest way to do this is with bcoin and its default wallet in regtest mode:

$ bwallet-cli mkwallet --mnemonic='zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong' --id=zoo
$ bwallet-cli --id=zoo master
{
  "encrypted": false,
  "key": {
    "xprivkey": "tprv8ZgxMBicQKsPdCttbKDzsuDzypKyWMDfGbzR5YsQe3dnPg6B69PPEaxawUuaanULMtgA8Etd9DaqDVSEBSbScA9xTsdR8PRfPsJZwKS3dJQ"
  },
  "mnemonic": {
    "bits": 128,
    "language": "english",
    "entropy": "ffffffffffffffffffffffffffffffff",
    "phrase": "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong"
  }
}

Now over to Bitcoin Core running in regtest (bitcoind -regtest).

We need a descriptor checksum. Take the tprv from the first step and add /* to the end to make it a "ranged" descriptor.

$ bitcoin-cli -regtest getdescriptorinfo "tr(tprv8ZgxMBicQKsPdCttbKDzsuDzypKyWMDfGbzR5YsQe3dnPg6B69PPEaxawUuaanULMtgA8Etd9DaqDVSEBSbScA9xTsdR8PRfPsJZwKS3dJQ/*)"
{
  "descriptor": "tr(tpubD6NzVbkrYhZ4WfvgUxtbHJt7YqqufgQZqubCN4ui4KSBEALwiYCyR5aT7bioEvpVxAuAqaHP5KB8rA4dTCDDJZDWmVk96QGFi47eAhUjpyz/*)#gqrapqyd",
  "checksum": "e05hhj4z",
  "isrange": true,
  "issolvable": true,
  "hasprivatekeys": true
}

Now create a descriptor wallet.

$ bitcoin-cli -regtest -named createwallet wallet_name=taproot-test-1 descriptors=true

Import the descriptor. We take the tprv from the first step and the checksum from the second step. You'll need to set "active" and add a timestamp as well.

$ bitcoin-cli -regtest -rpcwallet=taproot-test-1 importdescriptors \
  '[{"desc": "tr(tprv8ZgxMBicQKsPdCttbKDzsuDzypKyWMDfGbzR5YsQe3dnPg6B69PPEaxawUuaanULMtgA8Etd9DaqDVSEBSbScA9xTsdR8PRfPsJZwKS3dJQ/*)#e05hhj4z", "timestamp": 1633973910, "active": true }]'

You can test the import worked if "active" is true. There will be many descriptors in this wallet, just look for our "tr()" descriptor.

$ bitcoin-cli -regtest -rpcwallet=taproot-test-1 listdescriptors

...
    {
      "desc": "tr(tpubD6NzVbkrYhZ4WfvgUxtbHJt7YqqufgQZqubCN4ui4KSBEALwiYCyR5aT7bioEvpVxAuAqaHP5KB8rA4dTCDDJZDWmVk96QGFi47eAhUjpyz/*)#gqrapqyd",
      "timestamp": 1633973910,
      "active": true,
      "range": [
        0,
        999
      ],
      "next": 0
    }
...

We finally made it to the last step!

$ bitcoin-cli -regtest -rpcwallet=taproot-test-1 getnewaddress -addresstype bech32m
bcrt1pnmrmugapastum8ztvgwcn8hvq2avmcwh2j4ssru7rtyygkpqq98q4wyd6s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment