This is a guide to using your Trezor with Bitcoin Core. It may seem like more trouble than it's worth but many applications use Bitcoin Core as a wallet such as LND, EPS, and JoinMarket. Learning how to integrate your Trezor into a Bitcoin Core install is rather useful in many unexpected ways. I did this all through the QT interfaces, but it's simple to script. There is a much simpler guide available from the HWI github
( A ) Install TrezorCTL, HWI, and build GUI
You only need to set the wallet up once, but may repeat to upgrade
( A.I ) Download extract and install HWI
- Download and isntall Python
- Download https://github.com/bitcoin-core/HWI/archive/1.1.2.zip
- Extract it to a working folder (assumes
C:\User\Reddit\src\HWI
) - Change Directory (
cd
) to working foldercd "C:\User\Reddit\src\HWI"
- Setup venv
python -m venv .venv
- Enter venv
.venv\Scripts\activate.bat
1 - Install dependencies
python -m pip install -U setuptools pip wheel
- Install TrezorCTL
python -m pip install trezor[hidapi]
- Install HWI
python -m pip install hwi pyside2
( A.II ) Build the QT UI files
- Download and install MSYS2
- Launch a
mingw64.exe
- CD to working folder
cd "C:\User\Reddit\src\HWI"
- Enter venv
source .venv/Scripts/activate
1 - Run UI build
bash contrib/generate-ui.sh
( B ) Create a Trezor wallet in Bitcoin Core (testnet)
You only need to set the wallet up once, no private key data is stored, only xpub
data
( B.I ) Retrieve keypool from HWI-QT
- Launch
hwi-qt.exe --testnet
(assuming testnet) - Click
Set passphrase
(if needed) to cache your passphrase then clickRefresh
- Select you trezor from the list then click
Set Pin
(if needed) - Ensure your Trezor in the dropdown has a fingerprint
- Select
Change keypool options
and chooseP2WPKH
- Copy all the text from the
Keypool
textbox
( B.II ) Create the wallet in Bitcoin QT
- Launch Bitcoin Core (testnet) (non-pruned) 2
- Select
Console
from theWindow
menu - Create a wallet
createwallet "hwi" true
- Ensure that
hwi
is selected in the console wallet dropdown - Verify
walletname
using thegetwalletinfo
command - Import keypool
importmulti '<keypool_text_from_B.I.6>'
(note'
caging) - Rescan if TXNs are missing
rescanblockchain <starting_block_num>
3
( C.I ) Grab Tesnet coins
- Select the
Receive
tab in Bitcoin Core (testnet) - Ensure that the
Wallet
dropdown hashwi
selected - Select
Create new receiving address
and copy address - Google "bitcoin testnet faucet" and visit a few sites
- Answer captcha and input your addressed copied from C.I.3
( D ) Spending funds with HWI
This is how you can spend funds in your Trezor using Bitcoin Core (testnet)
( D.I ) Create an unsigned PSBT
- Select the
Send
tab in Bitcoin Core (testnet) - Ensure that the
Wallet
dropdown hashwi
selected - Verify your balance in
Watch-only balance
- Rescan if balance is wrong (see B.II.7) 3
- Craft your TXN as usual, then click
Create Unsigned
- Copy the PSBT to your clipboard when prompted
( D.II ) Sign your PSBT
- In HWI-QT click
Sign PSBT
- Paste what you copied in D.I.6 in
PSBT to Sign
field - Click
Sign PSBT
- Copy the text for
PSBT Result
( D.III ) Broadcast your TXN
- Select the
Console
window in Bitcoin Core (testnet) - Ensure that the
Wallet
dropdown hashwi
selected - Finalize PSBT:
finalizepsbt <psbt_copied_from_D.II.4>
- Copy the signed TXN hex from the
hex
field returned - Broadcast TXN:
sendrawtransaction <txn_copied_from_D.III.4>
Final Thoughts
I did this all through the GUI interfaces for the benefit of the Windows users. Windows console is fine, but the quote escaping in windows console is nightmarish. Powershell would be good, but that throws this on a whole another level for most Windows folks.
There is also the need to use HWI-QT due to a bug in blank passphrases on the commandline. You can work around it by toggling passphrase off or on, but again, it's more than I wanted to spell out.
Footnotes:
- 1. - Later version of python put the activate script under 'bin' instead of 'Script'
- 2. - You can run pruned, but you need to have a fresh wallet
- 3. - Rescan is automatic on 'importmulti' but I was pruned so it was wierd
No comments:
Post a Comment