Skip to content

Instantly share code, notes, and snippets.

@notmandatory
Last active April 25, 2023 03:08
Show Gist options
  • Save notmandatory/483c7edd098550c235da75d5babcf255 to your computer and use it in GitHub Desktop.
Save notmandatory/483c7edd098550c235da75d5babcf255 to your computer and use it in GitHub Desktop.
Creating a regtest taproot descriptor wallet with bitcoind

This gist demonstrates how to create a bitcoind wallet that is based on pay to taproot (P2TR) descriptors.

Tools used:

  • docker with image bitcoindevkit/bitcoind:v22.0rc2
  • bitcoin dev kit cli, bdk-cli

About bech32 vs bech32m addresses

Steps:

  1. Create aliases to work with bitcoind docker image
alias rtstart='docker run --detach --rm -p 127.0.0.1:18443-18444:18443-18444/tcp -p 127.0.0.1:60401:60401/tcp --name bitcoind bitcoindevkit/bitcoind:v22.0rc2'
alias rtstop='docker kill bitcoind'
alias rtlogs='docker container logs bitcoind'
alias rtcli='docker exec -it bitcoind /root/bitcoin-cli -regtest -datadir=/root/.bitcoin $@'
  1. Start bitcoind container
rtstart
  1. Create testnet xprv key
XPRV=$(bdk-cli key generate | jq -r '.xprv')
  1. Create an external descriptor with testnet xprv key and get it's checksum
EX_DESC="tr($XPRV/86h/1h/0h/0/*)"
EX_DESC_CS=$(rtcli getdescriptorinfo $EX_DESC | jq -r '.checksum')
EX_DESC=$EX_DESC#$EX_DESC_CS
  1. Create an internal (change) descriptor with testnet xprv key and get it's checksum
IN_DESC="tr($XPRV/86h/1h/0h/1/*)"
IN_DESC_CS=$(rtcli getdescriptorinfo $IN_DESC | jq -r '.checksum')
IN_DESC=$IN_DESC#$IN_DESC_CS
  1. Import descriptors to new "test" wallet
rtcli createwallet "test" false true "" false true false false
rtcli -rpcwallet=test importdescriptors "[{ \"desc\": \"$EX_DESC\", \"timestamp\":\"now\", \"active\": true, \"range\": [0,100]}, { \"desc\": \"$IN_DESC\", \"timestamp\":\"now\", \"internal\": true, \"active\": true, \"range\": [0,100]}]"
  1. Get wallet info
rtcli -rpcwallet=test getwalletinfo
  1. Get new receive address
rtcli -rpcwallet=test getnewaddress "" "bech32m"
  1. Generate blocks to test wallet
rtcli generatetoaddress 101 <bech32m address>
  1. Get wallet info again and see new balance of 50 BTC
rtcli -rpcwallet=test getwalletinfo
  1. Create legacy wallet and send BTC to it
rtcli createwallet "legacy"
rtcli -rpcwallet=legacy getnewaddress
rtcli -rpcwallet=test sendtoaddress <legacy address> 1
rtcli -rpcwallet=test getnewaddress "" "bech32m"
rtcli generatetoaddress 1 <bech32m address>
rtcli -rpcwallet=legacy listtransactions
@sandipndev
Copy link

ACK, can generate P2TR addresses and send/receive coins using the Taproot wallet successfully.
Working perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment