Skip to content

Instantly share code, notes, and snippets.

@bitkevin
Last active December 19, 2015 04:09
Show Gist options
  • Save bitkevin/5895291 to your computer and use it in GitHub Desktop.
Save bitkevin/5895291 to your computer and use it in GitHub Desktop.

create raw transaction

  • bitcoindtest = bitcoind -testnet

one input, one output

$ bitcoindtest createrawtransaction '[{"txid":"f5583dcb7ee8881e37110912f6163ddab9ffcc02e739b8683667b64c597bd635", "vout":0}]' '{"mq7se9wy2egettFxPbmn99cK8v5AFq55Lx":1}'

output hex:

010000000135d67b594cb6673668b839e702ccffb9da3d16f6120911371e88e87ecb3d58f50000000000ffffffff0100e1f505000000001976a9146953ce65058e5e68125a9163d74b277d6a7f4a9e88ac00000000

output hex explain:

01000000  // version
01        // vin count

/*** vin[0] ***/

35d67b594cb6673668b839e702ccffb9da3d16f6120911371e88e87ecb3d58f5  // input txid
00000000                                                          // index of output
00                                                                // scriptSig length
ffffffff                                                          // sequence, UINT32_MAX

01        // vout count

/*** vout[0] ***/

00e1f50500000000                                    // amount - uint64_t
19                                                  // scriptPubKey length, 0x19 = 25bytes
76a9146953ce65058e5e68125a9163d74b277d6a7f4a9e88ac  // scriptPubKey hex

00000000  // locktime

two input, two output

#
# two input, two output
#
$ bitcoindtest createrawtransaction '[{"txid":"f5583dcb7ee8881e37110912f6163ddab9ffcc02e739b8683667b64c597bd635", "vout":0},{"txid":"7fee3b2f8c4f68c6be634bd88876ddacad8f02a1ec56b01b9d6751e4d10889b7", "vout":0}]' '{"mq7se9wy2egettFxPbmn99cK8v5AFq55Lx":2, "n2zWWpBsFcCn5LWi7DTqJGxZKYgeEmX2Rz":2}'

output hex:

010000000235d67b594cb6673668b839e702ccffb9da3d16f6120911371e88e87ecb3d58f50000000000ffffffffb78908d1e451679d1bb056eca1028fadacdd7688d84b63bec6684f8c2f3bee7f0000000000ffffffff0200c2eb0b000000001976a9146953ce65058e5e68125a9163d74b277d6a7f4a9e88ac00c2eb0b000000001976a914eb90c4b191fb933dab8e2e6bd92f27a97bda907188ac00000000

output hex explain:

01000000  // version
02        // vin count

// vin[0]
35d67b594cb6673668b839e702ccffb9da3d16f6120911371e88e87ecb3d58f5  // input txid
00000000                                                          // index of output
00                                                                // scriptSig length
ffffffff                                                          // sequence, UINT32_MAX

// vin[1]
b78908d1e451679d1bb056eca1028fadacdd7688d84b63bec6684f8c2f3bee7f
00000000
00
ffffffff

02        // vout count

// vout[0]
00c2eb0b00000000                                    // amount
19                                                  // scriptPubKey length, 0x19 = 25bytes
76a9146953ce65058e5e68125a9163d74b277d6a7f4a9e88ac  // scriptPubKey hex

// vout[1]
00c2eb0b00000000
19
76a914eb90c4b191fb933dab8e2e6bd92f27a97bda907188ac

00000000  // locktime

decode this raw transaction (before sign)

$ bitcoindtest decoderawtransaction 010000000235d67b594cb6673668b839e702ccffb9da3d16f6120911371e88e87ecb3d58f50000000000ffffffffb78908d1e451679d1bb056eca1028fadacdd7688d84b63bec6684f8c2f3bee7f0000000000ffffffff0200c2eb0b000000001976a9146953ce65058e5e68125a9163d74b277d6a7f4a9e88ac00c2eb0b000000001976a914eb90c4b191fb933dab8e2e6bd92f27a97bda907188ac00000000

output:

{
    "txid" : "ceeae616df808494fc28e6588af29fa30c59bfabe87cf76babf9a7616905f343",
    "version" : 1,
    "locktime" : 0,
    "vin" : [
        {
            "txid" : "f5583dcb7ee8881e37110912f6163ddab9ffcc02e739b8683667b64c597bd635",
            "vout" : 0,
            "scriptSig" : {
                "asm" : "",
                "hex" : ""
            },
            "sequence" : 4294967295
        },
        {
            "txid" : "7fee3b2f8c4f68c6be634bd88876ddacad8f02a1ec56b01b9d6751e4d10889b7",
            "vout" : 0,
            "scriptSig" : {
                "asm" : "",
                "hex" : ""
            },
            "sequence" : 4294967295
        }
    ],
    "vout" : [
        {
            "value" : 2.00000000,
            "n" : 0,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 6953ce65058e5e68125a9163d74b277d6a7f4a9e OP_EQUALVERIFY OP_CHECKSIG",
                "hex" : "76a9146953ce65058e5e68125a9163d74b277d6a7f4a9e88ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "mq7se9wy2egettFxPbmn99cK8v5AFq55Lx"
                ]
            }
        },
        {
            "value" : 2.00000000,
            "n" : 1,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 eb90c4b191fb933dab8e2e6bd92f27a97bda9071 OP_EQUALVERIFY OP_CHECKSIG",
                "hex" : "76a914eb90c4b191fb933dab8e2e6bd92f27a97bda907188ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "n2zWWpBsFcCn5LWi7DTqJGxZKYgeEmX2Rz"
                ]
            }
        }
    ]
}

address info

  • address
    • moaToTdmmw75Gw4LCrw8Lqb2UgZsGPvKGa
  • private key
    • cQVH8fcp4o9MXLNkVXKcXBNN5PVemAnrgFtTi8KGDjqTLzsfV7g5
  • ScriptSig Hex
    • 6a914586ae2a6dfee86cd34fbac5320cc9c04e89afba688ac

sign raw transaction

$ bitcoindtest signrawtransaction 010000000235d67b594cb6673668b839e702ccffb9da3d16f6120911371e88e87ecb3d58f50000000000ffffffffb78908d1e451679d1bb056eca1028fadacdd7688d84b63bec6684f8c2f3bee7f0000000000ffffffff0200c2eb0b000000001976a9146953ce65058e5e68125a9163d74b277d6a7f4a9e88ac00c2eb0b000000001976a914eb90c4b191fb933dab8e2e6bd92f27a97bda907188ac00000000 '[{"txid":"f5583dcb7ee8881e37110912f6163ddab9ffcc02e739b8683667b64c597bd635", "vout":0,"scriptPubKey":"76a914586ae2a6dfee86cd34fbac5320cc9c04e89afba688ac"},{"txid":"7fee3b2f8c4f68c6be634bd88876ddacad8f02a1ec56b01b9d6751e4d10889b7", "vout":0,"scriptPubKey":"76a914586ae2a6dfee86cd34fbac5320cc9c04e89afba688ac"}]' '["cQVH8fcp4o9MXLNkVXKcXBNN5PVemAnrgFtTi8KGDjqTLzsfV7g5"]'

output:

{
	"hex" : "010000000235d67b594cb6673668b839e702ccffb9da3d16f6120911371e88e87ecb3d58f5000000006b483045022047717ad9456127ac0cd86dbdcd479d2f8852aa71d6ca71bf44d9eb1c2fdb22e1022100fba70cdcd1b192c68b98f9ef384bc219f1c3611ea6d34f458390bfea0522cf8c01210261222c3c49280b0c088c6738479c05ed05df8894184282caa7a324797d393220ffffffffb78908d1e451679d1bb056eca1028fadacdd7688d84b63bec6684f8c2f3bee7f000000006b483045022100c42a18716afad83fffe05e925918bad9b94ad9509acc321d7921a986fd5f531202206854a5e937328268d6ec0f44a8aca62642616b04cd3fc9f0c8a2cfc2456ec79f01210261222c3c49280b0c088c6738479c05ed05df8894184282caa7a324797d393220ffffffff0200c2eb0b000000001976a9146953ce65058e5e68125a9163d74b277d6a7f4a9e88ac00c2eb0b000000001976a914eb90c4b191fb933dab8e2e6bd92f27a97bda907188ac00000000",
    "complete" : true
}

output hex explain:

01000000
02

35d67b594cb6673668b839e702ccffb9da3d16f6120911371e88e87ecb3d58f5
00000000
// signature length
6b
// signature
483045022047717ad9456127ac0cd86dbdcd479d2f8852aa71d6ca71bf44d9eb1c2fdb22e1022100fba70cdcd1b192c68b98f9ef384bc219f1c3611ea6d34f458390bfea0522cf8c01210261222c3c49280b0c088c6738479c05ed05df8894184282caa7a324797d393220
ffffffff

b78908d1e451679d1bb056eca1028fadacdd7688d84b63bec6684f8c2f3bee7f
00000000
// signature length
6b
// signature
483045022100c42a18716afad83fffe05e925918bad9b94ad9509acc321d7921a986fd5f531202206854a5e937328268d6ec0f44a8aca62642616b04cd3fc9f0c8a2cfc2456ec79f01210261222c3c49280b0c088c6738479c05ed05df8894184282caa7a324797d393220
ffffffff

02

00c2eb0b00000000
19
76a9146953ce65058e5e68125a9163d74b277d6a7f4a9e88ac

00c2eb0b00000000
19
76a914eb90c4b191fb933dab8e2e6bd92f27a97bda907188ac

00000000

decode this raw transaction (after sign)

$ bitcoindtest decoderawtransaction 010000000235d67b594cb6673668b839e702ccffb9da3d16f6120911371e88e87ecb3d58f5000000006b483045022047717ad9456127ac0cd86dbdcd479d2f8852aa71d6ca71bf44d9eb1c2fdb22e1022100fba70cdcd1b192c68b98f9ef384bc219f1c3611ea6d34f458390bfea0522cf8c01210261222c3c49280b0c088c6738479c05ed05df8894184282caa7a324797d393220ffffffffb78908d1e451679d1bb056eca1028fadacdd7688d84b63bec6684f8c2f3bee7f000000006b483045022100c42a18716afad83fffe05e925918bad9b94ad9509acc321d7921a986fd5f531202206854a5e937328268d6ec0f44a8aca62642616b04cd3fc9f0c8a2cfc2456ec79f01210261222c3c49280b0c088c6738479c05ed05df8894184282caa7a324797d393220ffffffff0200c2eb0b000000001976a9146953ce65058e5e68125a9163d74b277d6a7f4a9e88ac00c2eb0b000000001976a914eb90c4b191fb933dab8e2e6bd92f27a97bda907188ac00000000

output:

{
    "txid" : "96a39ac001a349139f971539397b3b1ad351848db6ca91a498c10005f5f0cdc7",
    "version" : 1,
    "locktime" : 0,
    "vin" : [
        {
            "txid" : "f5583dcb7ee8881e37110912f6163ddab9ffcc02e739b8683667b64c597bd635",
            "vout" : 0,
            "scriptSig" : {
                "asm" : "3045022047717ad9456127ac0cd86dbdcd479d2f8852aa71d6ca71bf44d9eb1c2fdb22e1022100fba70cdcd1b192c68b98f9ef384bc219f1c3611ea6d34f458390bfea0522cf8c01 0261222c3c49280b0c088c6738479c05ed05df8894184282caa7a324797d393220",
                "hex" : "483045022047717ad9456127ac0cd86dbdcd479d2f8852aa71d6ca71bf44d9eb1c2fdb22e1022100fba70cdcd1b192c68b98f9ef384bc219f1c3611ea6d34f458390bfea0522cf8c01210261222c3c49280b0c088c6738479c05ed05df8894184282caa7a324797d393220"
            },
            "sequence" : 4294967295
        },
        {
            "txid" : "7fee3b2f8c4f68c6be634bd88876ddacad8f02a1ec56b01b9d6751e4d10889b7",
            "vout" : 0,
            "scriptSig" : {
                "asm" : "3045022100c42a18716afad83fffe05e925918bad9b94ad9509acc321d7921a986fd5f531202206854a5e937328268d6ec0f44a8aca62642616b04cd3fc9f0c8a2cfc2456ec79f01 0261222c3c49280b0c088c6738479c05ed05df8894184282caa7a324797d393220",
                "hex" : "483045022100c42a18716afad83fffe05e925918bad9b94ad9509acc321d7921a986fd5f531202206854a5e937328268d6ec0f44a8aca62642616b04cd3fc9f0c8a2cfc2456ec79f01210261222c3c49280b0c088c6738479c05ed05df8894184282caa7a324797d393220"
            },
            "sequence" : 4294967295
        }
    ],
    "vout" : [
        {
            "value" : 2.00000000,
            "n" : 0,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 6953ce65058e5e68125a9163d74b277d6a7f4a9e OP_EQUALVERIFY OP_CHECKSIG",
                "hex" : "76a9146953ce65058e5e68125a9163d74b277d6a7f4a9e88ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "mq7se9wy2egettFxPbmn99cK8v5AFq55Lx"
                ]
            }
        },
        {
            "value" : 2.00000000,
            "n" : 1,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 eb90c4b191fb933dab8e2e6bd92f27a97bda9071 OP_EQUALVERIFY OP_CHECKSIG",
                "hex" : "76a914eb90c4b191fb933dab8e2e6bd92f27a97bda907188ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "n2zWWpBsFcCn5LWi7DTqJGxZKYgeEmX2Rz"
                ]
            }
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment