Author

Topic: Script to spend BCH from Armory Lockbox (2-of-3 Multisig) (Read 310 times)

newbie
Activity: 6
Merit: 0
Here's a bash script I used to free some BCH from my Armory Lockbox. Feel free to use and enhance it!

Donations are appreciated!
BTC: 12YWVqdZqCrjJX4dAfKto47WSak93kB9mK
BCH: 14ZniiUi6Mu1ir6qZpvpMCbNDCnwYHcXsk

You need to fill the various variables in the script, specify the UTXO details (remove the "exit" line when you found those). This script will automatically send the signed transaction.

Make sure to leave some room between $ORIGAMOUNT (everything there is in the UTXO VOUT) and $AMOUNT (the amount you will get): the difference are fees for the miners.

Bitcoin ABC has to be running and referenced correctly in $CLI.

Code:
#!/bin/bash
# https://bitcoin.org/en/developer-examples#p2sh-multisig
CLI=bitcoin-cli # Bitcoin ABC
# Get public keys by double clicking on lockbox in armory
P2SH_ADDRESS="3..."
PUB1="0434be1f..."
PUB2="04a3b81..."
PUB3="04ce75f..."
# Find private keys in Armory:
# double click on wallet
# Find address in Unused Addresses - P2PKH (the first one in my case)
# Double click on address
# View Address Keys
# Use the Private Key (Base58) without spaces
PRIVATE_KEY1="5K..."
PRIVATE_KEY2="5J..."
COMPUTED_P2SH_ADDRESS=`$CLI createmultisig 2 "[\"$PUB1\", \"$PUB2\", \"$PUB3\"]" | jq -r ".address"`
echo "Computed address: $COMPUTED_P2SH_ADDRESS"
echo "Expected address: $P2SH_ADDRESS"
TARGETADDRESS="13..."
# Pick an unspent transaction which puts money into $P2SH_ADDRESS
UTXO_TXID="b3d..."

$CLI getrawtransaction $UTXO_TXID 1
exit # Enter data below and remove this line
UTXO_VOUT=0 # .vout[n].n
UTXO_OUTPUT_SCRIPT="a914131357a7bddee4de25e96fbdfadd45276cb5bae987" #.vout[n].scriptPubKey.hex
ORIGAMOUNT=0.001 # .vout[n].value
AMOUNT=0.00095 # .vout[n].value (difference to $ORIGAMOUNT are fees!)

P2SH_REDEEM_SCRIPT=`$CLI createmultisig 2 "[\"$PUB1\", \"$PUB2\", \"$PUB3\"]" | jq -r ".redeemScript"`
RAW_TX=`$CLI createrawtransaction "[{\"txid\":\"$UTXO_TXID\",\"vout\":$UTXO_VOUT,\"redeemscript\":\"$P2SH_REDEEM_SCRIPT\"}]" "{\"$TARGETADDRESS\":$AMOUNT}"`
SIGNED_RAW_TX=`$CLI signrawtransaction $RAW_TX "[{\"txid\":\"$UTXO_TXID\",\"amount\":$ORIGAMOUNT,\"vout\":$UTXO_VOUT,\"scriptPubKey\":\"$UTXO_OUTPUT_SCRIPT\",\"redeemScript\":\"$P2SH_REDEEM_SCRIPT\"}]" "[\"$PRIVATE_KEY1\", \"$PRIVATE_KEY2\"]" | jq -r ".hex"`
$CLI sendrawtransaction $SIGNED_RAW_TX
Jump to: