ebellocchia / py_crypto_hd_wallet

HD wallet for cryptocurrencies based on my bip_utils library
MIT License
52 stars 34 forks source link

Creating raw transaction using bitcoin-cli #12

Closed tuncatunc closed 3 years ago

tuncatunc commented 3 years ago

Hi 👋 all,

I want to sign a raw hex transaction with a private key generated with py_crypto_hd_wallet the private key is "raw_priv": "5e45c52f98729252619ac4e06036b54106020d10abf96165f278aebd32d5b9aa",

I've already a raw transaction 020000000144ccf76290ab6ff42fd4aa469cb4508125b531f67d670438631c5dcfc1e535fd0100000000ffffffff01409c0000000000001976a914270def551d3adba114b27fb25958689599a92ddc88ac00000000

then to sign the raw transaction, errs. Is my private key wrong?

./bitcoin-cli signrawtransactionwithkey $rawtxhex "[\"$raw_priv\"]"

error code: -5
error message:
Invalid private key

bitcoin testnet wallet data is

{
  "wallet_name": "wegohash_Bip44Coins.BITCOIN_TESTNET_wallet",
  "spec_name": "BIP-0044",
  "coin_name": "Bitcoin TestNet (BTC)",
  "mnemonic": "garbage fossil patrol shadow put morning miss chapter sister undo nation dignity",
  "passphrase": "",
  "seed_bytes": "f7d8372d133b55f1ec9a0e149dae3ba6fea8b0b4e3e97831d58c82b07a68a28a2d2f7516a6073a26c1f3c277625196cd3022fe7b02ae89678cb01e1c4c5977f3",
  "master_key": {
    "ex_pub": "tpubD6NzVbkrYhZ4YcLXgarGhuWCR6n1hxvf8Bzgem77jGAwmkZEtEDThF9KoyrQgUS2qTN8hxDEJSCsjKyfg3Aqz7Lk4FEB91QrnsxpbqTRXFT",
    "raw_compr_pub": "0237dd3bad0f674d3675711f0b3d7709e4a60856dfa351b5e2ea129bfc612ce1a5",
    "raw_uncompr_pub": "0437dd3bad0f674d3675711f0b3d7709e4a60856dfa351b5e2ea129bfc612ce1a5cf7b3b92190ee69ee192ffbb3289b9225123c6a06499741c8091d42a4b629cda",
    "ex_priv": "tprv8ZgxMBicQKsPf9JjnwBgJVr5r5G5YdjkYtPuNF4pJzNYwGJUFqPsWkXTdsJRQDi3F8CfXbvKiskbnVXwjjQT3Ud8KWHApAwbmAp8jaT6Cph",
    "raw_priv": "6be15a636a4c1c48fd2e27498784fda4d8e3521b8bf72145b341ed78ea7e0886",
    "wif_priv": "cRCQYnmNYDq2Hpt3gSb63S7rAGTW1i34p8daBNEcYLPYCUHCwyVM",
    "address": "mm15i1y74uko2vDJtPzqwpsE7dLWkxMarP"
  },
  "purpose_key": {
    "ex_pub": "tpubD8hn1nBq2euBvzPiiEi2b9som8BAe3KUCEihwSuqHHYEfREgka9zi3MR3qAAPRHgDkm4z2uQE3omy4z5XhKpRJLdRXVQbqVm7YoUimAMCjh",
    "raw_compr_pub": "02e65d66c505bd5d780766254c0fcf6201c11b1dd0cb13eeaf7887b9e7a28f3da1",
    "raw_uncompr_pub": "04e65d66c505bd5d780766254c0fcf6201c11b1dd0cb13eeaf7887b9e7a28f3da13503cd4d54bcc64a179776e20c22fc36b10bcde5614ae07f5259f48458b51570",
    "ex_priv": "tprv8c1jsN9atHDX3XMvpb3SBkDhC6fEUi8Zcw7vevsXs1jqpvyv8BLQXYjYshUumAeWJwqFkAXJ89uhnYxYaJYziCjdGQNGmydpUogFT2YMzga",
    "raw_priv": "8630944d0228ec9a1cd3dac03b4bb19f8f7c86eed04be4940b08365cd70c64ef",
    "wif_priv": "cS5Yo6zFxg7WRKLsDKNTgdMqdQGhyFCeBHuaavSMcWrxzrtEnBmt",
    "address": "mtPjxHKThVDCu2JKdv8cK1cBxHvuf4iwZZ"
  },
  "coin_key": {
    "ex_pub": "tpubDBBUQxLxwrruQpYi2GFwRRzyNMKP3ywgLsDnTMDEDh6MMgYQCXjoM5PccYe8FWiQzX8w3z9Lm7DCx445Y2jR1p3oEToDf6zcKiUrbMDuBZY",
    "raw_compr_pub": "029ac93e8c4b65357e9c958305ff807d72f62fffdb2507afa11e3ee7610923c028",
    "raw_uncompr_pub": "049ac93e8c4b65357e9c958305ff807d72f62fffdb2507afa11e3ee7610923c0289ad460c16b761942784eedeed355f51a0ff2f2afccd6f9538e6cd5fdcdfc790e",
    "ex_priv": "tprv8eVSGYJioVBEXMWv8cbM22LroKoStekmmZd1AqAvoRHxXCHda8vDAamkSR5QtbVqWQkk8i6c8mMSNta3Hv3bwYKcsGoUZaDs2hR4eRwWyri",
    "raw_priv": "49756e7fff67320e6812ecdd18244b9e7a5218d3b707bdf4c96becb0a85467c8",
    "wif_priv": "cQ3Vi5oMgUuAVXcCZ4AVz8J92KZmozjRhBp6dZU7eYc7SBFjabLC",
    "address": "mkKb2PozhZjyCvGUaVo6xr6FDKLrisKDtr"
  },
  "account_idx": 111,
  "account_key": {
    "ex_pub": "tpubDCQs3RPvFG7qGqPJmZ8JdQiK9KMN6kAtumdU4iTfsY2jLHBfqfbLpNuaEa9aKTE9w4RRrhwkhivWVzeC7b5twWbZ7Chr1CkiKCu9fPqdXNU",
    "raw_compr_pub": "03b2afca801787158f911f5ac215fdbae53de9feefc169045f6181a6cd05a79924",
    "raw_uncompr_pub": "04b2afca801787158f911f5ac215fdbae53de9feefc169045f6181a6cd05a799246e035137f2447bdebcc32324f8d660e4d445858250fbd5b61e2bb2eb81b6139d",
    "ex_priv": "tprv8fipu1Mg6tSAPNMWsuTiE14CaHqRwQyzLU2gnCRNTGELVnvuDGmkdtHi4PysLtDbNnKRnNEvMoHqroTJ9YJWRsdzTcwnq9e2hmdYXTDDq3w",
    "raw_priv": "0a82a9c0944d29a430d7088527ef33bc6c1e829555905dabd33fcccb5833f1c7",
    "wif_priv": "cMw8dx1vTDtenfyVHhAFCx56JqdLgMQWHAsRc9dWzhwAGnV1YgSd",
    "address": "mnLVJNEubdDbnTTWiRFPXnp438kLhf9oVY"
  },
  "change_idx": 0,
  "change_key": {
    "ex_pub": "tpubDETRZpvGECGV9vNEbmB3yiT3mtNJ6VLEUx3TKn9wx3CVuwQdXecECRrWKNxv7j41PuSUb2dyLprMj6t1eSfyMRdeEgSj7EDkh3HnmVmVukA",
    "raw_compr_pub": "03c1fd5032021fdb8e6c218fcb867f3577df14a1cb0e5e677f1bb661b7fe20ff39",
    "raw_uncompr_pub": "04c1fd5032021fdb8e6c218fcb867f3577df14a1cb0e5e677f1bb661b7fe20ff392771eb55ff2bcba76b1fd8176304c129ada720a1e3949f2d70807cf3b1077877",
    "ex_priv": "tprv8hmPRQt25papGTLSi7WTaJnwCrrMwA9KueSg3G7eXmQ75T9ruFne1wEe9Cgiw32xLsEdJWsepCHfTgyW2x6M5A45CVBxpSFNxVcXk9UBMLa",
    "raw_priv": "0b15cc242e1202ebadbc9a40c9436be1238b0b436de8c718988545f32343d434",
    "wif_priv": "cMxFSJG6wkkherQE8oCByqX86Dtik5oYNHmD1tu58z8Tz4yrzvWR",
    "address": "mswzHZyz675zTvYG9hip5z2k5tKxrwfPMm"
  },
  "address": {
    "address_0": {
      "ex_pub": "tpubDGnoZU6kcYpQmMH1CRrvBerwt173898on1qCWruQD8w3nn7rknjWX9wmepJ5XG1yx1DB8xzRpro1gVXq3S8sF3hVPMtMDPPxZaMKsLTsV8w",
      "raw_compr_pub": "025d1927eaf76519508c587733791d104acecb610fded1ce16e610435247e88f02",
      "raw_uncompr_pub": "045d1927eaf76519508c587733791d104acecb610fded1ce16e610435247e88f02c1756bf5fca8a42bce7c093937802698a0a09f1eecd1c8861754658302fcabaa",
      "ex_priv": "tprv8k6mR44WUB8jstFDJnCKnFCqJyb6xowuCiERELs6ns8exHs68PuvLfKuUhMhZDVrXpMUUwh5pWiCUK8GrQaJnqCCppNRvn5zaXfXpcTnVho",
      "raw_priv": "5e45c52f98729252619ac4e06036b54106020d10abf96165f278aebd32d5b9aa",
      "wif_priv": "cQjxMLoEAmrCcyqGfihZRdX43K5RBnBT2LAL35pvwJjya3NkoWvP",
      "address": "mftWkKrdUmV5F1BgpT6JPBWTyBQrSTbG8q"
    }
  }
}

Thx

ebellocchia commented 3 years ago

Hi, it depends on the format that bitcoin-cli requires for the private key, you can try using the WIF format with Bitcoin

Regards

tuncatunc commented 3 years ago

Thanks a lot for this library and great documentation. Successfully created and signed and sent a raw bitcoin transaction on bitcoin test network. Used address's WIF private key.

It deserves 100 times more stars, for supporting a lot of network addresses out of box.