0

Im trying to create a coinbase transaction so that I can do some mining.

I have a bech32 bitcoin address, how do I convert that to hex so that I can include it in the coinbase transaction data?

example> bc1quukrk3u6cgpjhyqvehcj0ruyk8990dpev0zn6h

Also, where are the parts of the address? network type, checksum.

And how would I do it with the other address types?

Thanks in advance!

1

BIP173 specifies the conversion from Bech32 segwit addresses to scriptPubKey. You probably want to use some reference software to do the decoding (there are several links in the BIP). If you need the details, it is approximately:

  • Split the address in a "human readable part" and a "data part"; the last '1' character in the address separates the two.
  • Convert the data part from characters to symbols (integers in range 0-31) using the character map in the BIP.
  • Verify the checksum (last 6 characters of the data part). I'll refer to the BIP for the details.
  • Interpret the symbols of the data part as follows:
    • One symbol: Witness version (number 0-16)
    • Variable number of symbol: witness program
    • The last 6 symbols: the checksum
  • Perform various sanity checks on the data sizes and ranges, also illustrated in the BIP.

The retrieved information (witness version and program) can the be converted to a scriptPubKey, as specified in BIP141. Namely, OP_n (where n is the witness version), followed by a push of the witness program. Note that OP_0 is 0x00, while OP_1-OP_16 are 0x51..0x60.

There is a proposed amendment called BIP350 which improves the checksum for witness versions higher than 0 (which are currently not in use, but may become in use following the activation of Taproot (BIP340-342).

This is how conversion from addresses to scriptPubKeys works for all transaction outputs, FWIW. It is entirely unrelated to coinbases.

Disclaimer: I'm a co-author of all the BIPs mentioned in this answer.

0

I assume you want to post it in the coinbase transaction in the form of hex-represented ASCII data (like encoding text in OP_RETURN) for some sort of signaling/"bragging rights".

You haven't mentioned any specific programming language you want to use so I'd suggest using online ASCII to HEX converter? Like this one? Most programming languages have very simple to use ASCII to HEX converters as well.

2
  • I think the question is how to create a coinbase txout that pays out to the address he specifies. – Pieter Wuille Feb 22 at 23:30
  • Oh, looks like XY problem ;) – Tony Sanak Feb 23 at 0:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.