Bitcoin Forum
May 07, 2024, 12:00:40 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: How to assemble this type of pay to pubkey hash transaction ?  (Read 308 times)
ytrezq (OP)
Member
**
Offline Offline

Activity: 285
Merit: 27


View Profile
April 03, 2019, 07:45:59 PM
Last edit: April 03, 2019, 08:30:20 PM by ytrezq
Merited by ABCbits (1)
 #1

I’d like to perform a transaction like this…
Code:
<expiry time> CHECKLOCKTIMEVERIFY DROP DUP HASH160 <pubKeyHash> EQUALVERIFY CHECKSIG
Which brings many questions :
— How to encode
Code:
<expiry time>
for setting the timing as a block height ?
— How to convert an address to a pubkeyHash ?
— How to assemble this into bytecode the network can understand ?
— How to automatically select utxo ?
— How to publish the resulting transaction to Bitcoin testnet ?
The Bitcoin network protocol was designed to be extremely flexible. It can be used to create timed transactions, escrow transactions, multi-signature transactions, etc. The current features of the client only hint at what will be possible in the future.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715083240
Hero Member
*
Offline Offline

Posts: 1715083240

View Profile Personal Message (Offline)

Ignore
1715083240
Reply with quote  #2

1715083240
Report to moderator
1715083240
Hero Member
*
Offline Offline

Posts: 1715083240

View Profile Personal Message (Offline)

Ignore
1715083240
Reply with quote  #2

1715083240
Report to moderator
1715083240
Hero Member
*
Offline Offline

Posts: 1715083240

View Profile Personal Message (Offline)

Ignore
1715083240
Reply with quote  #2

1715083240
Report to moderator
jackg
Copper Member
Legendary
*
Offline Offline

Activity: 2856
Merit: 3071


https://bit.ly/387FXHi lightning theory


View Profile
April 03, 2019, 07:50:29 PM
 #2

Do you have any ideas as to the platform you are using with this? At least an os or something. Are you trying to do all of this without a wallet and just bare cli instructions also?

ytrezq (OP)
Member
**
Offline Offline

Activity: 285
Merit: 27


View Profile
April 03, 2019, 08:17:51 PM
Last edit: April 03, 2019, 08:29:41 PM by ytrezq
 #3

Do you have any ideas as to the platform you are using with this? At least an os or something. Are you trying to do all of this without a wallet and just bare cli instructions also?


I’d like to install nothing. Which means I’d prefer a web service. Otherwise Windows or Linux is Ok.
Also, yes I’d like to do this from a Wallet or a private key as Text. And as result, I don’t want to perform signing an utxo selection manually. I mean automatically like with a normal transaction as only the output needs to be manual.
jackg
Copper Member
Legendary
*
Offline Offline

Activity: 2856
Merit: 3071


https://bit.ly/387FXHi lightning theory


View Profile
April 04, 2019, 02:53:25 AM
 #4

Ah, these two pages might be of interest to you: https://coinb.in/#newTransaction

https://coinb.in/#newTransaction

I think you might need to get the riepmd160 hash from your computer and convert it into base58 unless you want to pay to public key instaed (I thought p2pk is still supported though I could be completely wrong).
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10555



View Profile
April 04, 2019, 04:03:44 AM
Merited by ABCbits (1)
 #5

I think you might need to get the riepmd160 hash from your computer and convert it into base58 unless you want to pay to public key instaed (I thought p2pk is still supported though I could be completely wrong).

if you have the address (base58) just opening it in blockchain.com explorer will show you both the address and its hash160 and the conversion itself is a very easy one using the base58 decode function that exists in all libraries.
as for P2PK, it is an standard transaction still.

get type: https://github.com/bitcoin/bitcoin/blob/2068f089c8b7b90eb4557d3f67ea0f0ed2059a23/src/script/standard.cpp#L131-L135
doesn't consider non-standard: https://github.com/bitcoin/bitcoin/blob/2068f089c8b7b90eb4557d3f67ea0f0ed2059a23/src/policy/policy.cpp#L57-L78

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
ytrezq (OP)
Member
**
Offline Offline

Activity: 285
Merit: 27


View Profile
April 04, 2019, 10:25:46 AM
 #6

Ah, these two pages might be of interest to you: https://coinb.in/#newTransaction

https://coinb.in/#newTransaction

I think you might need to get the riepmd160 hash from your computer and convert it into base58 unless you want to pay to public key instaed (I thought p2pk is still supported though I could be completely wrong).
Nope. I’ve only the address, not the public key…
ytrezq (OP)
Member
**
Offline Offline

Activity: 285
Merit: 27


View Profile
April 04, 2019, 11:00:26 AM
 #7

What’s the requirement for a transaction to match a ᴘ2ᴘᴋʜ ?
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10555



View Profile
April 04, 2019, 02:51:54 PM
Merited by ABCbits (1)
 #8


i'm not exactly sure what you mean by "requirement", but a P2PKH script is a script that you make by having the resulting 20 byte hash of the public key or the address which is the same thing but encoded differently.
to do that, in any wallet you simply enter the address and if it is a base58 legacy address (starting with 1) it creates it for you.
if you want to know what the script itself is, it is this sequence:
Code:
<OP_DUP><OP_HASH160><..here you include the hash result..><OP_EQUALVERIFY><OP_CHECKSIG>
example: 76 A9 14 89ABCDEFABBAABBAABBAABBAABBAABBAABBAABBA 88 AC

to get the "hash result" you either have your public key in which case depending on whether you want compressed or uncompressed you serialize it and then perform SHA256 first and then RIPEMD160 on it. the result is a 20 byte hash.
if you only have the address and not the public key then use base58 encoder to decode the address, remove its checksum (4 last bytes) remove its first byte and the renaming bytes are the hash you need.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
jackg
Copper Member
Legendary
*
Offline Offline

Activity: 2856
Merit: 3071


https://bit.ly/387FXHi lightning theory


View Profile
April 04, 2019, 02:56:04 PM
 #9

@pooya he said he had the address. While posting that information is interesting, it might just inadvertantly confuse.

as I stated earlier, you can use this to make and sign your transaction: https://coinb.in/#newTransaction

You can get the required information from a block explorer or it might do it automatically (i forget).
ytrezq (OP)
Member
**
Offline Offline

Activity: 285
Merit: 27


View Profile
April 04, 2019, 04:58:44 PM
 #10

@pooya he said he had the address. While posting that information is interesting, it might just inadvertantly confuse.

as I stated earlier, you can use this to make and sign your transaction: https://coinb.in/#newTransaction

You can get the required information from a block explorer or it might do it automatically (i forget).
So the following remains unanswered :
— How to assemble this into bytecode the network can understand ?
— How to automatically select utxo for sending payment ?
— How to publish the resulting transaction to Bitcoin testnet (not on the real network because I don’t have access to Bitcoins currently) ?
ytrezq (OP)
Member
**
Offline Offline

Activity: 285
Merit: 27


View Profile
April 04, 2019, 05:10:02 PM
 #11


i'm not exactly sure what you mean by "requirement", but a P2PKH script is a script that you make by having the resulting 20 byte hash of the public key or the address which is the same thing but encoded differently.
to do that, in any wallet you simply enter the address and if it is a base58 legacy address (starting with 1) it creates it for you.
if you want to know what the script itself is, it is this sequence:
Code:
<OP_DUP><OP_HASH160><..here you include the hash result..><OP_EQUALVERIFY><OP_CHECKSIG>
example: 76 A9 14 89ABCDEFABBAABBAABBAABBAABBAABBAABBAABBA 88 AC

to get the "hash result" you either have your public key in which case depending on whether you want compressed or uncompressed you serialize it and then perform SHA256 first and then RIPEMD160 on it. the result is a 20 byte hash.
if you only have the address and not the public key then use base58 encoder to decode the address, remove its checksum (4 last bytes) remove its first byte and the renaming bytes are the hash you need.

I’m saying this because I know not all transaction can be in the form of ᴘ2ᴘᴋʜ. I definitely need the payment to be made to <pubKeyHash> instead of <ScriptHash> in a block explorer.
jackg
Copper Member
Legendary
*
Offline Offline

Activity: 2856
Merit: 3071


https://bit.ly/387FXHi lightning theory


View Profile
April 04, 2019, 10:41:00 PM
 #12

1. It'll be in an understandable format once the signing is complete.

2. I'm not sure if you can or not

3. That page will probably take testnet keys.

Be proactive and test stuff yourself...
ytrezq (OP)
Member
**
Offline Offline

Activity: 285
Merit: 27


View Profile
April 05, 2019, 12:04:37 AM
 #13

1. It'll be in an understandable format once the signing is complete.

2. I'm not sure if you can or not

3. That page will probably take testnet keys.

Be proactive and test stuff yourself...

No definitely no…

Something like :
Code:
1519394400 CHECKLOCKTIMEVERIFY DROP DUP HASH160 9169b1c4fc26d870d29205144bd51deb43decd80 EQUALVERIFY CHECKSIG
Won’t work as is. Opcodes need to be converted and encoded first. How ? I have no idea about where. What you gave is only for public keys and is not general purpose whereas I can only use the address.

For selecting utxo, this is definitely linked to finding the right program or web service. When performing normal transactions users don’t have to even think what utxo is. There’s no reason it should be done manually here since it’s not the purpose of the question.

And last… which page ? It seems to me you forgot a ᴜʀʟ…
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10555



View Profile
April 05, 2019, 03:44:28 AM
 #14

well you are basically asking us to teach you how script works in one comment and that is impossible. you need to read about it yourself, it is quite long and complicated:
https://blockgeeks.com/guides/best-bitcoin-script-guide/
https://en.bitcoin.it/wiki/Script

here is some quick pointers that cover your questions also:
- each OP code is 1 byte. eg: OP_DUP = 0x76, OP_DROP = 0x75
- when pushing data you use shortest form and it is followed by its size. eg: 0x14 (=size which is 20) then followed by the 20 bytes
- when including numbers you push them in little-endian order. eg: 1519394400  = 0x04 0x601e905a

- to get a list of UTXOs you either have to use JSON-RPC of bitcoin core which i am not familiar with or use a block explorer API like https://www.blockchain.com/api/blockchain_api (i think it only offers HTML now and no JSON) check other explorers for UTXO list
- each tx hex has to be reversed before you put it in your transaction as an outpoint
- to broadcast it you can again either use bitcoin-core or block explorers that have a testnet explorer such as blockcypher

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
ytrezq (OP)
Member
**
Offline Offline

Activity: 285
Merit: 27


View Profile
April 05, 2019, 07:54:04 AM
Last edit: April 05, 2019, 08:20:00 AM by ytrezq
 #15

well you are basically asking us to teach you how script works in one comment and that is impossible. you need to read about it yourself, it is quite long and complicated:
https://blockgeeks.com/guides/best-bitcoin-script-guide/
https://en.bitcoin.it/wiki/Script

here is some quick pointers that cover your questions also:
- each OP code is 1 byte. eg: OP_DUP = 0x76, OP_DROP = 0x75
- when pushing data you use shortest form and it is followed by its size. eg: 0x14 (=size which is 20) then followed by the 20 bytes
- when including numbers you push them in little-endian order. eg: 1519394400  = 0x04 0x601e905a

- to get a list of UTXOs you either have to use JSON-RPC of bitcoin core which i am not familiar with or use a block explorer API like https://www.blockchain.com/api/blockchain_api (i think it only offers HTML now and no JSON) check other explorers for UTXO list
- each tx hex has to be reversed before you put it in your transaction as an outpoint
- to broadcast it you can again either use bitcoin-core or block explorers that have a testnet explorer such as blockcypher

No… You know very well that when peoples create transactions in Bitcoin they don’t use Telnet and Hex editors. Or more generally that assembly is assembled through automated programs called assemblers not manually. In an unrelated example, When you want to call a contract in ethereum you don’t select previous transactions nor sign the current one : you just use metamask with the parameter you build and you don’t have to care about the remaining. Here only TxOut should be manual.
I’ve an idea of how to do it but the question is definitely more about which tools ?
jackg
Copper Member
Legendary
*
Offline Offline

Activity: 2856
Merit: 3071


https://bit.ly/387FXHi lightning theory


View Profile
April 05, 2019, 12:14:48 PM
 #16

It sounds like you might need a bitcoin wallet to do this instead if you can't work out this (that or you're just trolling)..

Most imports and exports work in hex. I have a text editor that allows me to edit hex and ascii like most people have and a lot of wallets export and import in pute hex anyway, its what you're going to need to broadcast the transaction.
Last I checked ethereum and bitcoin were two different coins and with bitcoin transactions at least you have to list the inputs which contain the vout and the txid.



From what you quoted yp0u also have to sign the transaction you make in the sign function I'm putting the private key. I stated the website above in a previous post...
ytrezq (OP)
Member
**
Offline Offline

Activity: 285
Merit: 27


View Profile
April 05, 2019, 12:24:46 PM
 #17

It sounds like you might need a bitcoin wallet to do this instead if you can't work out this (that or you're just trolling)..

Most imports and exports work in hex. I have a text editor that allows me to edit hex and ascii like most people have and a lot of wallets export and import in pute hex anyway, its what you're going to need to broadcast the transaction.
Last I checked ethereum and bitcoin were two different coins and with bitcoin transactions at least you have to list the inputs which contain the vout and the txid.



From what you quoted yp0u also have to sign the transaction you make in the sign function I'm putting the private key. I stated the website above in a previous post...
Correct. I need a bitcoin wallet which can do custom scripting in TxOut. Since that time I download bitcoin core in full. So it might help.

The website you stated in your previous post if for using a public key. But I’ve only the address.
jackg
Copper Member
Legendary
*
Offline Offline

Activity: 2856
Merit: 3071


https://bit.ly/387FXHi lightning theory


View Profile
April 05, 2019, 01:39:49 PM
 #18

This one? https://coinb.in/#newTransaction

OK if you're wanting a wallet, I'd suggest electrum.

Go to electrum.org/#download

I'd suggest you download the portable version for Windows or run it without installing for Linux (the instructions are on the download page).if you're wanting to keep using bitcoin though feel free to install electrum fully.

Once running you're going to want to click to use public or private keys and then you're wanting to paste the private keys into the following screen..

If you're after emptying your wallet, you'll then go to the send tab, type or paste in the address you want to send your coins to and hit the max button (set the fee slider to within 25 blocks before doing this and you'll get more btc out).
ytrezq (OP)
Member
**
Offline Offline

Activity: 285
Merit: 27


View Profile
April 05, 2019, 01:55:44 PM
 #19

This one? https://coinb.in/#newTransaction

OK if you're wanting a wallet, I'd suggest electrum.

Go to electrum.org/#download

I'd suggest you download the portable version for Windows or run it without installing for Linux (the instructions are on the download page).if you're wanting to keep using bitcoin though feel free to install electrum fully.

Once running you're going to want to click to use public or private keys and then you're wanting to paste the private keys into the following screen..

If you're after emptying your wallet, you'll then go to the send tab, type or paste in the address you want to send your coins to and hit the max button (set the fee slider to within 25 blocks before doing this and you'll get more btc out).
and then the question is how to assemble the script and create a transaction with it ?
jackg
Copper Member
Legendary
*
Offline Offline

Activity: 2856
Merit: 3071


https://bit.ly/387FXHi lightning theory


View Profile
April 05, 2019, 01:59:27 PM
 #20

The wallet does it for you. You don't have to worry about assembling a script or anything.

You're just after sending bitcoins right?
Pages: [1] 2 »  All
  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!