submitted by /u/plumbforbtc [link] [comments] |
This blog brings you the best Cryptocurrency & Blockchain, ICO & P2P and Exchange & Laws news. Also contains technology and research based post from all around the world every single day. Get informed! Think Future!
Monday, 5 October 2020
Power of the Command Line (bitcoin-cli, hwi, electrum, trezorctl)
I think some of the console tools available with HW wallets today are greatly under utilized. Here's a quick write-up on how to create and sign a TXN very similar to 43d27...1fc06 found on the SLIP-14 wallet. I'll be using TrezorCTL, Electrum, and HWI for the signing. I won't go much into the setup or install, but feel free to ask if you have questions about it. Note, you don't have to use all three of these. Any one will produce a valid signed TXN for broadcast. I just showed how to do it three ways. Whats more some of the Electrum and HWI steps are interchangeable.
ColdCard also has a utility called ckcc
that will do the sign operation instead of HWI, but in many ways they are interchangeable. KeepKey and Ledger both have libraries for scripted signing but no one-shot, one-line console apps that I know of. But HWI and Electrum of course work on all four.
TrezorCTL
This is the what most would think of to use to craft and sign TXNs, and is definitely very simple. The signing uses a script called build_tx.py to create a JSON file that is then used by the btc sign-tx
command. The whole process is basically:
tools/build_tx.py | trezorctl btc sign-tx -
This just means, take the output of build_tx
and sign it. To copy 43d27...1fc06
, I wrote a small script to feed build_tx
, so my process looks like:
~/input.sh | tools/build_tx.py | trezorctl btc sign-tx -
But it's all very simple. Note... I used FW 2.3.0 (1.9.0) on this since there are some minor incompatibilities in later FW 1.
input.sh
```
!/bin/bash
secho() { sleep 1; echo $*}
secho "Testnet" # coin name secho "tbtc1.trezor.io" # blockbook server and outpoint (below) secho "e294c4c172c3d87991b0369e45d6af8584be92914d01e3060fad1ed31d12ff00:0" secho "m/84'/1'/0'/0/0" # prev_out derivation to signing key secho "4294967293" # Sequence for RBF; hex(-3) secho "segwit" # Signature type on prev_out to use secho "" # NACK to progress to outs secho "2MsiAgG5LVDmnmJUPnYaCeQnARWGbGSVnr3" # out[0].addr secho "10000000" # out[1].amt secho "tb1q9l0rk0gkgn73d0gc57qn3t3cwvucaj3h8wtrlu" # out[1].addr secho "20000000" # out[1].amt secho "tb1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt96jk9x" # out[2].addr secho "99999694" # out[2].amt secho "" # NACK to progress to change secho "" # NACK to skip change secho "2" # txn.version secho "0" # txn.locktime ```
Electrum
Electrum is one of the better GUI wallets available, but it also has a pretty good console interface. Like before you need your Trezor with the SLIP-14 wallet loaded and paired to Electrum. I'll assume Electrum is up and running with the Trezor wallet loaded to make things simple.
Like with TrezorCTL, Electrum feeds on a JSON file, but unlike TrezorCTL it needs that JSON squished into the command line. This is a simple sed
command, but I won't bore you with the details, but just assume that's done. So the process in Electrum (v4.0.3) looks like:
electrum serialize <smushed_json>
(create psbt to sign)electrum --wallet <file> signtransaction <prev_pbst>
(sign said psbt)
Still pretty simple right! Below is the JSON I smushed for #1
txn.json
{ "inputs": [{ "prevout_hash":"e294c4c172c3d87991b0369e45d6af8584be92914d01e3060fad1ed31d12ff00", "prevout_n": 0, "value_sats": 129999867 }], "outputs": [{ "address": "2MsiAgG5LVDmnmJUPnYaCeQnARWGbGSVnr3", "value_sats": 10000000 },{ "address": "tb1q9l0rk0gkgn73d0gc57qn3t3cwvucaj3h8wtrlu", "value_sats": 20000000 },{ "address": "tb1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt96jk9x", "value_sats": 99999694 }]}
HWI
HWI is an unsung hero in my book. It's a very small clean and simple interface between HW wallets and Bitcoin Core. It currently supports a good range of HW wallets. It keeps itself narrowly focused on TXN signing and offloads most everything else to Bitcoin Core. Again, I'll assume you've imported your Trezor keypool into Core and done the requisite IBD and rescan. And if you don't have the RPC enabled, you can always clone these commands into the QT-console.
To sign our TXN in HWI (v1.1.2), we will first need to craft (and finalize) it in Bitcoin Core (0.21.1). Like in Electrum, we will have to use simple sed
to smush some JSON into command arguments, but I'll assume you have that covered. It will take an inputs.json
and an outputs.json
named separately.
bitcoin-cli createpsbt <smushed_inputs> <smushed_outputs>
(create psbt)bitcoin-cli -rpcwallet=<wallet> walletprocesspsbt <prev_pbst>
(process psbt)hwi -f <keypool_fingerprint> signtx <prev_pbst>
(sign psbt)bitcoin-cli -rpcwallet=<wallet> finalizepsbt <prev_pbst>
(get a signed TXN from psbt)
A little more involved, but still nothing too bad. Plus this gives you the full power of Bitcoin Core including integrations with LND (lightning).
inputs.json
[{ "txid": "e294c4c172c3d87991b0369e45d6af8584be92914d01e3060fad1ed31d12ff00", "vout": 0 }]
outputs.json
[{ "2MsiAgG5LVDmnmJUPnYaCeQnARWGbGSVnr3": 0.10000000 },{ "tb1q9l0rk0gkgn73d0gc57qn3t3cwvucaj3h8wtrlu": 0.20000000 },{ "tb1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt96jk9x": 0.99999694 }]
Conclusion
This may all seem like very low level coding, but is surprisingly simple once you get a knack for it. Whats more, all these platforms support testnet which allows you to practice with valueless coins until you get the hang of it. And, like many things in bitcoin, this is all (mostly) python, which is one of the easier languages to learn.
Enjoy
Footnotes
[link] [comments]
Governments only stay in business because they have the power to control how much cash flows through the economy. They can create new money or reduce the amount in circulation. They control the cost of everything, from fixing a pothole in the street to the cost of war in the Middle East.
US Cracks Down on Bitcoin Exchange | This Week in Crypto – Oct 5, 2020 The post US Cracks Down on Bitcoin Exchange | This Week in Crypto – Oct 5, 2020 appeared first on 99 Bitcoins. U.S. regulatory authorities brought a series of civil and criminal charges against BitMEX. The … US Cracks Down on Bitcoin Exchange | This Week in Crypto – Oct 5, 2020 Read More »
The post US Cracks Down on Bitcoin Exchange | This Week in Crypto – Oct 5, 2020 appeared first on 99 Bitcoins.
U.S. regulatory authorities brought a series of civil and criminal charges against BitMEX. The …
US Cracks Down on Bitcoin Exchange | This Week in Crypto – Oct 5, 2020 Read More »
from 99 Bitcoins https://ift.tt/3d1fG0V
via IFTTT
-
Crypto is pretty much the only reason I used Reddit anymore, and I'd like to stop using this website. submitted by /u/TheTruthHas...
-
submitted by /u/FearlessEggplant3036 [link] [comments] source https://www.reddit.com/r/btc/comments/12gt49l/supposedly_insiders_in_t...
-
submitted by /u/KillerHurdz [link] [comments] source https://www.reddit.com/r/btc/comments/a6bm9y/discussing_bitcoin_power_dyn...