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:
- 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 $@'
- Start bitcoind container
rtstart
- Create testnet xprv key
XPRV=$(bdk-cli key generate | jq -r '.xprv')
- 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
- 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
- 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]}]"
- Get wallet info
rtcli -rpcwallet=test getwalletinfo
- Get new receive address
rtcli -rpcwallet=test getnewaddress "" "bech32m"
- Generate blocks to test wallet
rtcli generatetoaddress 101 <bech32m address>
- Get wallet info again and see new balance of 50 BTC
rtcli -rpcwallet=test getwalletinfo
- 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
ACK, can generate P2TR addresses and send/receive coins using the Taproot wallet successfully.
Working perfectly!