Bitcoin Forum
November 05, 2024, 11:16:41 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: making a testnet transaction by hand  (Read 1089 times)
tspacepilot (OP)
Legendary
*
Offline Offline

Activity: 1456
Merit: 1081


I may write code in exchange for bitcoins.


View Profile
August 24, 2015, 11:03:53 PM
 #1

Hi bitcoin pros,

I'm trying to put together my first "by-hand" transaction.  I'm following along with ken sherrif's bitcoins the hard way blog and looking at the docs etc to try to get this going.  I decided that I wanted to do something on testnet first before trying anything on mainnet.  So my step 1 was to generate a testnet address and get some coins sent to it from a testnet fountain.  I did this.

https://www.blocktrail.com/tBTC/tx/3ca5868acb7ea66fc8c2a3ed841337d24774183ec8edb626d0e05d799a271e57

I own the address:

mtmAtMCFotG5NbFgkbVHTPhARKpqToWsky

So, in theory, if I do things right, I should be able to put together a transaction to send those coins along.

Here's what I got so far:

Code:
0100000001571e279a795de0d026b6edc83e187447d2371384eda3c2c86fa67ecb8a86a53c010000001976a9140f532b6d8285d6d1bba1286cd74350270edbc7ee88acffffffff01703a8c00000000001976a9140f532b6d8285d6d1bba1286cd74350270edbc7ee88ac00000000


This isn't signed yet, but I wanted to get someone looking over my shoulder to see if I'm on the right track.

The first part "01000000" is the "version number"
Next "01" is the input count.  I only have a single input for this transaction.
Next,
571e279a795de0d026b6edc83e187447d2371384eda3c2c86fa67ecb8a86a53c
is the bytes reversed of the transaction hash where the input is found (3ca5868acb7ea66fc8c2a3ed841337d24774183ec8edb626d0e05d799a271e57)
Next, the index of the previous output (it was the second output in that transaction, the first was change) 010000
Then, the script from the output (length, script, ffffffff) -> 001976a9140f532b6d8285d6d1bba1286cd74350270edbc7ee88acffffffff
Then the output count 01
Then the value of first output 9190000 satoshis encoded as hex (leaving 10KSat for fee), reversed "703a8c"
Then the script to pay to the address OP_DUP OP_HASH160 DATA OP_EQVERIFY OP_CHECKSIG
Then the block lock time (00000000)

How is this looking to you guys?
tspacepilot (OP)
Legendary
*
Offline Offline

Activity: 1456
Merit: 1081


I may write code in exchange for bitcoins.


View Profile
August 25, 2015, 04:05:14 PM
 #2

It may be the case that it's not important whether this is on testnet or mainnet.

Also, I guess I wonder if there's any transaction validation tool I could use to try to drop my hex in and see if it parses okay (ie, get some feedback on the construction of this thing).
Delek
Full Member
***
Offline Offline

Activity: 157
Merit: 103


Salí para ver


View Profile WWW
August 25, 2015, 07:20:19 PM
 #3

This can help:
https://blockchain.info/decode-tx

\/\/\/\/\/\/\/
-> delek.net <-
/\/\/\/\/\/\/\
tspacepilot (OP)
Legendary
*
Offline Offline

Activity: 1456
Merit: 1081


I may write code in exchange for bitcoins.


View Profile
August 25, 2015, 07:32:11 PM
 #4


Hey, thanks, that does help!

Here's what I got back:
Code:
{
   "lock_time":0,
   "size":110,
   "inputs":[
      {
         "prev_out":{
            "index":1,
            "hash":"3ca5868acb7ea66fc8c2a3ed841337d24774183ec8edb626d0e05d799a271e57"
         },
         "script":"76a9140f532b6d8285d6d1bba1286cd74350270edbc7ee88ac"
      }
   ],
   "version":1,
   "vin_sz":1,
   "hash":"5ac07664014523a1dd0b6de82700add59fc6017e536b06dba6561e7206ede029",
   "vout_sz":1,
   "out":[
      {
         "script_string":"OP_DUP OP_HASH160 0f532b6d8285d6d1bba1286cd74350270edbc7ee OP_EQUALVERIFY OP_CHECKSIG",
         "address":"12Q2mc7LmWZcj72pXqUhWZemW3Vixm3PWp",
         "value":9190000,
         "script":"76a9140f532b6d8285d6d1bba1286cd74350270edbc7ee88ac"
      }
   ]
}

The only thing that stands out as clearly not what I intended is the out["address"].  It's showing up as 12Q2mc7LmWZcj72pXqUhWZemW3Vixm3PWp, but I actually intended to pay to mguz4fCKaXzsWDWSFQT5LUs6N36RuNu9To.  This seems related to my use of a testnet address.  It's not clear to me, however, if it's the case that this decode tool assumes a bitcoin address, or if I created the payToScriptPubKey incorrectly.
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3542
Merit: 6885


Just writing some code


View Profile WWW
August 25, 2015, 07:47:21 PM
 #5


Hey, thanks, that does help!

Here's what I got back:
Code:
{
   "lock_time":0,
   "size":110,
   "inputs":[
      {
         "prev_out":{
            "index":1,
            "hash":"3ca5868acb7ea66fc8c2a3ed841337d24774183ec8edb626d0e05d799a271e57"
         },
         "script":"76a9140f532b6d8285d6d1bba1286cd74350270edbc7ee88ac"
      }
   ],
   "version":1,
   "vin_sz":1,
   "hash":"5ac07664014523a1dd0b6de82700add59fc6017e536b06dba6561e7206ede029",
   "vout_sz":1,
   "out":[
      {
         "script_string":"OP_DUP OP_HASH160 0f532b6d8285d6d1bba1286cd74350270edbc7ee OP_EQUALVERIFY OP_CHECKSIG",
         "address":"12Q2mc7LmWZcj72pXqUhWZemW3Vixm3PWp",
         "value":9190000,
         "script":"76a9140f532b6d8285d6d1bba1286cd74350270edbc7ee88ac"
      }
   ]
}

The only thing that stands out as clearly not what I intended is the out["address"].  It's showing up as 12Q2mc7LmWZcj72pXqUhWZemW3Vixm3PWp, but I actually intended to pay to mguz4fCKaXzsWDWSFQT5LUs6N36RuNu9To.  This seems related to my use of a testnet address.  It's not clear to me, however, if it's the case that this decode tool assumes a bitcoin address, or if I created the payToScriptPubKey incorrectly.
That looks to be correct. I think blockchain is just assuming mainnet since both addresses have the same hash160.

tspacepilot (OP)
Legendary
*
Offline Offline

Activity: 1456
Merit: 1081


I may write code in exchange for bitcoins.


View Profile
August 25, 2015, 07:52:09 PM
 #6

Thanks for the confirmation, knightdk.  I'm going to forge ahead then, and look into creating a signed transaction that I can broadcast.  I'll probably post again here when I (almost certainly) run into technical details that I need advice on.
Muhammed Zakir
Hero Member
*****
Offline Offline

Activity: 560
Merit: 509


I prefer Zakir over Muhammed when mentioning me!


View Profile WWW
August 25, 2015, 08:32:20 PM
 #7

knightdk is right. When you use online decoding tools which are used for mainnet, they show the mainnet address. Using https://tbtc.blockr.io/tx/push or any other testnet transaction decoding tool will give you correct address.

tspacepilot (OP)
Legendary
*
Offline Offline

Activity: 1456
Merit: 1081


I may write code in exchange for bitcoins.


View Profile
August 25, 2015, 09:11:24 PM
 #8

knightdk is right. When you use online decoding tools which are used for mainnet, they show the mainnet address. Using https://tbtc.blockr.io/tx/push or any other testnet transaction decoding tool will give you correct address.

Even better, thanks MZ!  Bookmarked!

This is why I love this forum!
tspacepilot (OP)
Legendary
*
Offline Offline

Activity: 1456
Merit: 1081


I may write code in exchange for bitcoins.


View Profile
August 27, 2015, 07:57:03 AM
 #9

Thanks to you guys' tips and pointers, I got my hand-built transaction generated and signed and pushed:

Code:
0100000001571e279a795de0d026b6edc83e187447d2371384eda3c2c86fa67ecb8a86a53c010000006b483045022100c1369a31af8a3f85233a8210f06808a712e37e5cd0513ae0386b5a033bc4194f022048f30f8acc6a07ef26aa9f7c72ca9d82f769fa78b0a06c0fdfbb79bdc0a713ff01210314bad032ce3473485d1144c5aeb95858adec29e2864d212a114b969dc3477885ffffffff01703a8c00000000001976a9140f532b6d8285d6d1bba1286cd74350270edbc7ee88ac00000000

There were a few extra tricks to figure out because I used a compressed pubkey instead on uncompressed so I had to modify ken sheriff's python code a bit to get a valid signature.  But it looks like everything worked:

https://testnet.blockexplorer.com/tx/4ffe67e59d699b8ea7f61cfe4d63bdd1cce52e7b3b80622358c05f70d6acb07f

^^^ That's a hand-built transaction on the testnet.

After that confirms, I'll make one more to give my testnet coins back to the faucet.

Topic closed.  Thanks to everyone.  I feel like I just earned some sort of merit badge.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!