0

I'm using bitcoin core (via rpc api). I've generated one 2of2 multisig address on electrum wallet, and after that, I've imported that address into bitcoin core by using importaddress rpc method. When I want to create a transaction by using createrawtransaction, that method returns non-segwit encoded transaction. How can I force creation of segwit transaction (inputs are only from watch only multisig addresses), and is this even possible? I'm using bitcoin core 17.0

For multisig addresses generated inside that wallet, it creates segwit transaction.

I want to use bitcoin core only with watch-only multisig addresses, and when I want to spend some output, I use rpc method signrawtransactionwithkey to sign transaction. And that works. The problem is that I don't know if it's even possible to use segwit in that case. Multisig addresses are generated from p2wpkh addresses (on Electrum wallet).

Here are the steps (testnet):

1. Inside the Electrum wallet's console, I've generated a multisig addresses, by using these commands:
addresses = list()
addresses.append(createnewaddress())
addresses.append(createnewaddress())
pubKeys = getpubkeys(addresses[0])
pubKeys.append(getpubkeys(addresses[1])[0])
privateKeys = getprivatekeys(addresses)
multisigAddress = createmultisig(2, pubKeys)

I've got address 2NGAAYNVCrzmNJHoTfQMuiDYtAwsHTmMQ1m, pk1, pk2, and  redeemScript (prefix before private keys says that those two addresses used for multisig creation process are p2wpkh).

2. Importing address as watch-only in bitcoin-core:
bitcoin-cli importaddress 2NGAAYNVCrzmNJHoTfQMuiDYtAwsHTmMQ1m false

3. I've sent a small amount of BTCs to this multisig address.

4. Create raw transaction:
bitcoin-cli createrawtransaction '[{"txid":"44e42d229d94161debe4dc644bce4f669feb11a6107b2ffa4236df0420d72ccd", "vout":1}]' '{"2MwbQRMJDvaGBTB3dpLhwus5nwmLfUWm2cD":0.11000999}'
result: 0200000001cd2cd72004df3642fa2f7b10a611eb9f664fce4b64dce4eb1d16949d222de4440100000000ffffffff01a7dca7000000000017a9142fb187dd5e402c645aeda05394ff3d8c70d5d1bb8700000000

5. Transaction signing
bitcoin-cli signrawtransactionwithkey 0200000001cd2cd72004df3642fa2f7b10a611eb9f664fce4b64dce4eb1d16949d222de4440100000000ffffffff01a7dca7000000000017a9142fb187dd5e402c645aeda05394ff3d8c70d5d1bb8700000000 '["{pk1}", "{pk2}"]' '[{"txid":"44e42d229d94161debe4dc644bce4f669feb11a6107b2ffa4236df0420d72ccd", "vout":1, "scriptPubKey":"a914fb55ef9d9ffac793832ada2b63e747f94a630b9e87", "redeemScript":"{redeemScript}", "amount":0.111}]'
result: 0200000001cd2cd72004df3642fa2f7b10a611eb9f664fce4b64dce4eb1d16949d222de44401000000d90047304402205e90adeca33e882813bc2a03aa2b631e895853961058f7bad98a86410dc26e5d02204d40d6ee562ae07dd2b75c058e0cc8ae79b1ee6f9a244c50bf713b0ec3b45dba0147304402200193c7d676b70ec3de6f53baf07a6c1498c86253dcca686eda05def58dda0b090220290d23f332a592dce1485256200f98c24b48166671b72da937ea45da7f53782f0147522102591616129c718dd806042cafea42ddcba88657a745f7e6c79df51919dbf0cea721025b014c62165a7465efbca3780e499363ec8ee8f8b0ed577d8d8297a53f3098b152aeffffffff01a7dca7000000000017a9142fb187dd5e402c645aeda05394ff3d8c70d5d1bb8700000000

As you can see, this isn't a segwit transaction.
Decoded:
{
  "txid": "26d32452f0897d6bb6663619667826b952e2dd4a19df6518c015f662a0f8333e",
  "hash": "26d32452f0897d6bb6663619667826b952e2dd4a19df6518c015f662a0f8333e",
  "version": 2,
  "size": 300,
  "vsize": 300,
  "weight": 1200,
  "locktime": 0,
  "vin": [
    {
      "txid": "44e42d229d94161debe4dc644bce4f669feb11a6107b2ffa4236df0420d72ccd",
      "vout": 1,
      "scriptSig": {
        "asm": "0 304402205e90adeca33e882813bc2a03aa2b631e895853961058f7bad98a86410dc26e5d02204d40d6ee562ae07dd2b75c058e0cc8ae79b1ee6f9a244c50bf713b0ec3b45dba[ALL] 304402200193c7d676b70ec3de6f53baf07a6c1498c86253dcca686eda05def58dda0b090220290d23f332a592dce1485256200f98c24b48166671b72da937ea45da7f53782f[ALL] 522102591616129c718dd806042cafea42ddcba88657a745f7e6c79df51919dbf0cea721025b014c62165a7465efbca3780e499363ec8ee8f8b0ed577d8d8297a53f3098b152ae",
        "hex": "0047304402205e90adeca33e882813bc2a03aa2b631e895853961058f7bad98a86410dc26e5d02204d40d6ee562ae07dd2b75c058e0cc8ae79b1ee6f9a244c50bf713b0ec3b45dba0147304402200193c7d676b70ec3de6f53baf07a6c1498c86253dcca686eda05def58dda0b090220290d23f332a592dce1485256200f98c24b48166671b72da937ea45da7f53782f0147522102591616129c718dd806042cafea42ddcba88657a745f7e6c79df51919dbf0cea721025b014c62165a7465efbca3780e499363ec8ee8f8b0ed577d8d8297a53f3098b152ae"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.11000999,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 2fb187dd5e402c645aeda05394ff3d8c70d5d1bb OP_EQUAL",
        "hex": "a9142fb187dd5e402c645aeda05394ff3d8c70d5d1bb87",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2MwbQRMJDvaGBTB3dpLhwus5nwmLfUWm2cD"
        ]
      }
    }
  ]
}
4
  • The fact that createrawtransaction does not give you a segwit-encoded output is completely expected, as it has no witness. That's not a problem; signrawtransaction will happily take it, and add a witness if needed, and return a transaction in segwit format in that case. Commented Jan 16, 2019 at 6:53
  • The problem is that signrawtransactionwithkey also returns a non-segwit transaction (flag for segwit in encoded transaction is not active). Commented Jan 16, 2019 at 8:00
  • Please describe in details all the steps and RPCs you are using. The raw transaction API certainly supports creating segwit spends, but can be annoying to use. Commented Jan 16, 2019 at 15:57
  • I've added all the steps into my first post. Commented Jan 17, 2019 at 7:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.