Post
Topic
Board Development & Technical Discussion
i need Help in learning how p2sh addresses and tx works.
by
btctousd81
on 09/11/2017, 19:20:30 UTC
i have had discussion here , https://bitcointalk.org/index.php?topic=2294855

ill resume it here in this thread.

i was under impression that address starting with 3 needs more than 1 private keys to send funds. but looks like that is not the case

from :  https://bitcointalk.org/index.php?topic=2294855.msg23374174

post id 11 : https://bitcointalk.org/index.php?topic=2294855.msg23374174#msg23374174


from 1 sha256 private key i can create WIF private key and public kay pair which is
5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf  1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm

how would i get p2sh address for something like that ?

or am i missing again something .,

does the p2sh address's private key also falls in

int range
1 - 115792089237316195423570985008687907852837564279074904382605163141518161494336

if so then how can i generate a pair ?

lets say , so far i have these

input                        : 1
network                      : Bitcoin mainnet
netcode                      : BTC
secret exponent              : 1
 hex                         : 1
wif                          : KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn
 uncompressed                : 5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf
public pair x                : 55066263022277343669578718895168534326250603453777594175500187360389116729240
public pair y                : 32670510020758816978083085130507043184471273380659243275938904335757337482424
 x as hex                    : 79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
 y as hex                    : 483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8
y parity                     : even
key pair as sec              : 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
 uncompressed                : 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798\
                                 483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8
hash160                      : 751e76e8199196d454941c45d1b3a323f1433bd6
 uncompressed                : 91b24bf9f5288532960ac687abb035127b1d28a5
Bitcoin address              : 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH
Bitcoin address uncompressed : 1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm
Bitcoin segwit address       : p2y59b9U5YTUAYEDBr5zwSHFoM8pn3ozAhRD






post id 12 : https://bitcointalk.org/index.php?topic=2294855.msg23375280#msg23375280



from 1 sha256 private key i can create WIF private key and public kay pair which is
5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf  1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm

That is NOT a public key.

That is a bitcoin address.  Specifically, that is an uncompressed key P2PKH bitcoin address.

From that SAME WIF private key, you could also generate a compressed key P2PKH bitcoin address:
1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH

Furthermore, you could create 2160 different P2SH bitcoin addresses.  Here are a few of them:
38fEX6RbBBMmpu3nbbuULku1xyrrzqqqnE
3Q2iKGxFppUJEZUTUMmahjwUoLNRqDY9o3
3CZj1DTSHD4vhr3zALL3pgs6acyw1deYDt

how would i get p2sh address for something like that ?

Build a bitcoin output script.  Hash it.  Concatenate a byte value of 0x05 in front of the hash value. Encode the result with base64check encoding.

or am i missing again something .

Probably.

does the p2sh address's private key also falls in

int range
1 - 115792089237316195423570985008687907852837564279074904382605163141518161494336

if so then how can i generate a pair ?

P2SH means "pay to script hash".  It doesn't necessarily need a key, but is it is safer to build a script that requires a signature (in which case a signature would be required).


so how can i spend this output https://blockchain.info/unspent?active=3LmzcN7f4M8dnvTnoHV3BF8n8i1mLE1udr&format=html


Code:
{
    
    "unspent_outputs":[
    
        {
            "tx_hash":"3435869ad5a272e7d14306e73ea563d763ac65f28fc7672d1e16e47497950253",
            "tx_hash_big_endian":"5302959774e4161e2d67c78ff265ac63d763a53ee70643d1e772a2d59a863534",
            "tx_index":284855121,
            "tx_output_n": 17,
            "script":"a914d15b5f90ef9d3120c3704dac91055b35d180c36b87",
            "value": 109619902000,
            "value_hex": "1985daf630",
            "confirmations":7624
        }
      
    ]
}

Code:
tx_hash_big_endian : 5302959774e4161e2d67c78ff265ac63d763a53ee70643d1e772a2d59a863534
tx_output_n : 17
value : 109619902000

out address : 1P6oVB6r1KKZYNQQVS1QqJy6tFDrHMLCt6
createrawtransaction i get this

Code:
{
"result": "02000000013435869ad5a272e7d14306e73ea563d763ac65f28fc7672d1e16e474979502531100000000ffffffff0100e87648170000001976a914f26ba6c2e4fe4bc4a1cac44d0e2c9f525195cb0388ac00000000",
"error": null,
"id": null
}

if i decode tx i get this

Code:
{
   "lock_time":0,
   "size":85,
   "inputs":[
      {
         "prev_out":{
            "index":17,
            "hash":"5302959774e4161e2d67c78ff265ac63d763a53ee70643d1e772a2d59a863534"
         },
         "script":""
      }
   ],
   "version":2,
   "vin_sz":1,
   "hash":"2b05faacb73e30da3166e5c932f429c8b34c78ed6a0981c6366fb6357f2bfc45",
   "vout_sz":1,
   "out":[
      {
         "script_string":"OP_DUP OP_HASH160 f26ba6c2e4fe4bc4a1cac44d0e2c9f525195cb03 OP_EQUALVERIFY OP_CHECKSIG",
         "address":"1P6oVB6r1KKZYNQQVS1QqJy6tFDrHMLCt6",
         "value":100000000000,
         "script":"76a914f26ba6c2e4fe4bc4a1cac44d0e2c9f525195cb0388ac"
      }
   ]
}

what next ?
is this correct so far ?

Thanks for your time.