Skip to main content
added 7 characters in body
Source Link
Bumblebee
  • 149
  • 1
  • 7
  1. Send the signed raw transaction
  1. Send the raw transaction
  1. Send the signed raw transaction
Source Link
Bumblebee
  • 149
  • 1
  • 7

Just in case somebody else runs into the same issue. Here is how I created the new key pair and derived the Wif private key from it. I used bx which is a part of https://github.com/libbitcoin/libbitcoin-explorer.

Here are the steps:

  1. Create a new private key
# bx seed | bx ec-new
> d86a6cd08829b0e23dfb8e0eeb3abb8378147a950c638bedd368e9f51d1c45bc

  1. Convert the private key to Wif
# bx ec-to-wif -v 239 d86a6cd08829b0e23dfb8e0eeb3abb8378147a950c638bedd368e9f51d1c45bc
> cUqPKAMJJ81psjeY2ZXM5S2HG6azieuqMypRb9viHoY1QvubReUp

Note: the -v 239 option is used for a testnet address. If you want to create an address/Wif private key for the mainnet, you can skip -v 239

  1. Create the public
# bx ec-to-public d86a6cd08829b0e23dfb8e0eeb3abb8378147a950c638bedd368e9f51d1c45bc
> 02a4379f994ccce7041d30026092b13a7987c12cd6e33222dabdf890a00fc50b2e

  1. Create the address
# bx ec-to-address -v 111 02a4379f994ccce7041d30026092b13a7987c12cd6e33222dabdf890a00fc50b2e
> mhyXyTy4fnu2jcmAGeChkgd9RmNgTg7xV5

  1. Send some btc to this address
# bitcoin-cli sendtoaddress mhyXyTy4fnu2jcmAGeChkgd9RmNgTg7xV5 40.0
> 2c9e2222c109ea8ca6171aa1feb07f382b413205003e4271e45ee2e46f88c8c1

  1. Get the raw transaction
#bitcoin-cli getrawtransaction 2c9e2222c109ea8ca6171aa1feb07f382b413205003e4271e45ee2e46f88c8c1
> 020000000001011ec966bff03a8b5af9ac98cf3ba606c558baf5112fff11b99c024743630bb3bd0000000000feffffff02e8e9d039000000001600148c579973d42679c854837ffebf5b6612d5673d1000286bee000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388ac0247304402206525f5763b0c427059ffcea4605492515bd9599250600a3771d4c7af8258ca0502201c54db8b24a146b74ca4a8e64fe1666016f6f9636c9cb39ad1bdb926149f7eef012103962b2c8bcff7291e647ae077b205a9b06660826e1e9754177f4366d074df7a9700000000

  1. Decode the raw transaction
# bitcoin-cli decoderawtransaction 020000000001011ec966bff03a8b5af9ac98cf3ba606c558baf5112fff11b99c024743630bb3bd0000000000feffffff02e8e9d039000000001600148c579973d42679c854837ffebf5b6612d5673d1000286bee000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388ac0247304402206525f5763b0c427059ffcea4605492515bd9599250600a3771d4c7af8258ca0502201c54db8b24a146b74ca4a8e64fe1666016f6f9636c9cb39ad1bdb926149f7eef012103962b2c8bcff7291e647ae077b205a9b06660826e1e9754177f4366d074df7a9700000000
{
  "txid": "2c9e2222c109ea8ca6171aa1feb07f382b413205003e4271e45ee2e46f88c8c1",
  "hash": "945df62297918f141d235c42623bb6f39bb6c5418a9630462658d548e931455e",
  "version": 2,
  "size": 225,
  "vsize": 144,
  "weight": 573,
  "locktime": 0,
  "vin": [
    {
      "txid": "bdb30b634347029cb911ff2f11f5ba58c506a63bcf98acf95a8b3af0bf66c91e",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "304402206525f5763b0c427059ffcea4605492515bd9599250600a3771d4c7af8258ca0502201c54db8b24a146b74ca4a8e64fe1666016f6f9636c9cb39ad1bdb926149f7eef01",
        "03962b2c8bcff7291e647ae077b205a9b06660826e1e9754177f4366d074df7a97"
      ],
      "sequence": 4294967294
    }
  ],
  "vout": [
    {
      "value": 9.69992680,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 8c579973d42679c854837ffebf5b6612d5673d10",
        "hex": "00148c579973d42679c854837ffebf5b6612d5673d10",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "bcrt1q33teju75yeuus4yr0llt7kmxzt2kw0gskkdjh7"
        ]
      }
    },
    {
      "value": 40.00000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 1af72e49ec135151f1421c185b6cb1ce836576c3 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a9141af72e49ec135151f1421c185b6cb1ce836576c388ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "mhyXyTy4fnu2jcmAGeChkgd9RmNgTg7xV5"
        ]
      }
    }
  ]
}

  1. Create raw transaction. To create the raw transaction I created this quick and dirty shell script:
#!/bin/bash

# Adjust the options of bitcoin-cli according to your setup
CLI='bitcoin-cli -regtest -rpcuser=user -rpcpassword=password -rpcport=8332'

# Private Key from Step 1 (This is not used, just for verification)
PRIVATE_KEY='d86a6cd08829b0e23dfb8e0eeb3abb8378147a950c638bedd368e9f51d1c45bc'
# Wif Private Key from step 2
PRIVATE_KEY_BASE58='cUqPKAMJJ81psjeY2ZXM5S2HG6azieuqMypRb9viHoY1QvubReUp'

# Transaction id from Step 5
TX_IN_ID='2c9e2222c109ea8ca6171aa1feb07f382b413205003e4271e45ee2e46f88c8c1'

# Transaction hash from Ste 6
TX_IN_HASH='020000000001011ec966bff03a8b5af9ac98cf3ba606c558baf5112fff11b99c024743630bb3bd0000000000feffffff02e8e9d039000000001600148c579973d42679c854837ffebf5b6612d5673d1000286bee000000001976a9141af72e49ec135151f1421c185b6cb1ce836576c388ac0247304402206525f5763b0c427059ffcea4605492515bd9599250600a3771d4c7af8258ca0502201c54db8b24a146b74ca4a8e64fe1666016f6f9636c9cb39ad1bdb926149f7eef012103962b2c8bcff7291e647ae077b205a9b06660826e1e9754177f4366d074df7a9700000000'

# Receiver address
TO_ADDRESS='moinqaiuWShfsemB9nGcAGFZNMa3ZwPMq6'

# Amount to be sent
TO_AMOUNT=39.9998

echo ""
echo ""
echo "Raw In Transaction"
echo "=================="
$CLI decoderawtransaction $TX_IN_HASH

RAWTX=`$CLI \
    createrawtransaction \
    '[{"txid":"'$TX_IN_ID'","vout":'$TX_IN_VOUT'}]' \
    '{"'$TO_ADDRESS'":'$TO_AMOUNT'}'`

echo ""
echo ""
echo "Raw Transaction"
echo "==============="
echo $RAWTX

echo ""
echo ""
echo "Raw Transaction Decoded"
echo "======================="
$CLI decoderawtransaction $RAWTX

# scriptPubKey from Step 7 (Make sure to take the on from the vout from which you want to spend)
SCRIPT_PUB_KEY='76a9141af72e49ec135151f1421c185b6cb1ce836576c388ac'

echo ""
echo ""
echo "Sign Raw Transaction 1"
echo "======================"
# Make sure to set the vout from which you want to sped
RAWTX_SIGNED=`$CLI \
    signrawtransactionwithkey \
    $RAWTX \
    '["'$PRIVATE_KEY_BASE58'"]' \
    '[{"txid":"'$TX_IN_ID'","vout":1,"scriptPubKey":"'$SCRIPT_PUB_KEY'","redeemScript":""}]' `

echo ""
echo ""
echo "Raw Transaction Signed"
echo "======================"
echo $RAWTX_SIGNED

  1. Send the raw transaction
# bitcoin-cli sendrawtransaction 0200000001c1c8886fe4e25ee471423e000532412b387fb0fea11a17a68cea09c122229e2c010000006a473044022029296a6ac3fdaf0a0c4616c783bee1b3b5f7ea24a63f3df3544e74aa4c1a65b102207baa71419ef0ceff6218e78b6fb93bfe6ac7445584e23d20be1fbf6454bab50f012102a4379f994ccce7041d30026092b13a7987c12cd6e33222dabdf890a00fc50b2effffffff01e0d96aee000000001976a91459fe1a9f9f0a5af33396c59990f064be1ca5127488ac00000000
> 95d4f6bbdda2ec79350c0559d5d9e9c279f73e5d37f8267834034a40c6d520c2